Integrate tracer functionality to support MQT FlowViz#714
Conversation
…tor into thesis-integration
…s-and-wrappers' into thesis-integration
|
@coderabbitai review |
✅ Action performedReview finished.
|
📝 WalkthroughWalkthroughAdds ChangesCompilationTracer Feature
Sequence Diagram(s)sequenceDiagram
participant User
participant qcompile
participant rl_compile
participant Predictor
participant PredictorEnv
participant CompilationTracer
User->>qcompile: qcompile(qc, tracer_output_path=path)
qcompile->>rl_compile: rl_compile(qc, device, fom, tracer_output_path=path)
rl_compile->>Predictor: Predictor(tracer_output_path=path)
Predictor->>PredictorEnv: PredictorEnv(tracer_output_path=path)
rl_compile->>Predictor: compile_as_predicted(qc)
Predictor->>PredictorEnv: reset(qc) — init CompilationTracer, record baseline step
loop Each RL step
Predictor->>PredictorEnv: step(action) — time, trace, collect FOM
PredictorEnv->>CompilationTracer: record_step(index, action_name, action_type, duration, reward, qc, fom)
end
PredictorEnv->>CompilationTracer: save_to_json(tracer_output_path/circuit_name.json)
rl_compile-->>User: compiled circuit
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
CHANGELOG.md (1)
22-30: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick winMove this feature entry to
Unreleased.Line 22 is the already released
2.3.0section dated July 29, 2025. Adding a new feature there rewrites historical release notes instead of documenting the next release.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@CHANGELOG.md` around lines 22 - 30, Move the new feature entry out of the released 2.3.0 section and into the Unreleased changelog section instead. Update the CHANGELOG.md entry near the existing Added list so it is documented for the next release, keeping the released 2.3.0 history unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/mqt/predictor/qcompile.py`:
- Around line 31-39: The public API docstring in the qcompile function uses a
nonstandard parameter section label, so update the docstring to Google-style
formatting. In the docstring for the function that compiles the quantum circuit,
replace the “Arguments:” section with an “Args:” section and keep the parameter
descriptions aligned with the existing parameters like qc, figure_of_merit, and
tracer_output_path.
In `@src/mqt/predictor/rl/predictor.py`:
- Around line 193-200: The rl_compile path is mutating shared singleton state
via predictor_singleton.env.tracer_output_path around
Predictor.compile_as_predicted, which can race across overlapping calls. Update
the rl/predictor.py flow so the tracer path is passed as call-local state into
compile_as_predicted (or another non-shared context) instead of rewriting
predictor.env.tracer_output_path, or otherwise serialize access to
predictor_singleton to prevent interleaving restores.
In `@src/mqt/predictor/rl/predictorenv.py`:
- Around line 232-235: The filename construction in PredictorEnv’s tracer output
path uses current_circuit_name directly, which can contain invalid or
path-separating characters. Sanitize or normalize current_circuit_name before
interpolating it into trace_{...}.json in the out_path logic, and ensure the
fallback name from the current_circuit_name assignment path cannot produce
invalid Windows filenames or unintended subpaths. Keep the fix localized to the
tracing/export flow in PredictorEnv so all uses of tracer_output_path remain
safe.
- Around line 195-207: The estimated metric fields in predictorenv are being
serialized with the wrong kind, since both estimated_success_probability and
estimated_hellinger_distance are approximation-based rather than exact. Update
the metric creation in the predictor environment logic (the esp_metric and
hd_metric handling in the state/hellinger path) so these FOMMetric instances use
kind="approx" instead of kind="exact", while keeping the unavailable fallback
unchanged.
In `@tests/compilation/test_tracer.py`:
- Around line 109-116: The semantic validation in the tracer test is only
checking top-level dataclass construction and still allows nested dict/list
payloads through. Update the validation around DeviceMetadata and
CompilationStep to explicitly construct or validate the nested dataclasses and
objects for figures_of_merit, topology, and calibration_data so malformed nested
payloads are actually caught. Use the existing DeviceMetadata, CompilationStep,
and related nested type names from the test to locate and strengthen the
validation block.
---
Outside diff comments:
In `@CHANGELOG.md`:
- Around line 22-30: Move the new feature entry out of the released 2.3.0
section and into the Unreleased changelog section instead. Update the
CHANGELOG.md entry near the existing Added list so it is documented for the next
release, keeping the released 2.3.0 history unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 0952b2c0-4b77-4fde-ba05-e2f7d3977567
📒 Files selected for processing (6)
CHANGELOG.mdsrc/mqt/predictor/qcompile.pysrc/mqt/predictor/rl/predictor.pysrc/mqt/predictor/rl/predictorenv.pysrc/mqt/predictor/rl/tracer.pytests/compilation/test_tracer.py
Description
This PR implements the Predictor Tracer backend which collects information about the RL compilation process of the MQT Predictor. If active, the tracer outputs the collected information to a json file, which is used by the MQT FlowViz frontend to visualize the compilation.
AI Usage
The idea, logical structure and functionality of the code are entirely my own work; Google Gemini Pro 3.1 was solely used to assist with writing syntactically valid Python code. All code that was produced by Gemini was carefully reviewed and tested by myself.
Checklist
If PR contains AI-assisted content: