✨ Add RL truncation#697
Conversation
## Description This PR addresses critical bugs in the RL training process with the following key changes: **Structure Improvements:** - **Redesigned action validation logic** (`predictorenv.py`): Rewrote `determine_valid_actions_for_state()` with a more structured (but equivalent) state machine that explicitly tracks three circuit states (synthesized, laid_out, routed) and handles 6 different state combinations. - Added helper methods `is_circuit_laid_out()` and `is_circuit_routed()` to replace the buggy `CheckMap` pass with more reliable state checking. The new logic supports both the original restricted MDP and a flexible general MDP mode. - **Fixed type annotation** (`actions.py`): Corrected `do_while` parameter type from `dict[str, Circuit]` to `PropertySet` and added missing import for Qiskit's `PropertySet`. - **Added reproducibility** (`predictor.py`): Set random seed for non-test training runs to ensure reproducible results. - **Improved VF2Layout error handling** (`predictorenv.py`): Replaced assertion failures with warning logs when VF2Layout doesn't find a solution, preventing crashes during training. **Test Updates:** - Suppressed deprecation warnings in tket routing test --------- Signed-off-by: Patrick Hopf <81010725+flowerthrower@users.noreply.github.com> Co-authored-by: flowerthrower <flowerthrower@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
…ove-action-pass-imports-and-wrappers
…ove-action-pass-imports-and-wrappers
Co-authored-by: Lukas Burgholzer <burgholzer@me.com> Signed-off-by: Patrick Hopf <81010725+flowerthrower@users.noreply.github.com>
…ove-action-pass-imports-and-wrappers
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@coderabbitai review |
✅ Action performedReview finished.
|
📝 WalkthroughWalkthroughThis PR introduces a configurable ChangesAdd RL truncation
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant Predictor
participant PredictorEnv
participant Tracer
Predictor->>PredictorEnv: __init__(max_steps)
Predictor->>PredictorEnv: step(action)
PredictorEnv->>PredictorEnv: increment num_steps
alt num_steps >= max_steps
PredictorEnv->>Tracer: trace terminal step
PredictorEnv-->>Predictor: truncated=True, info.truncation_reason
else
PredictorEnv->>Tracer: trace normal step
PredictorEnv-->>Predictor: normal terminated/truncated result
end
Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 |
Description
This PR adds a maximum steps (per episode) argument for Predictor/PredictorEnv initialization. As opposed to tracer_path this is not supposed to be changed after training. It defaults to None, keeping previous implementation behavior consistent.
I decided against implementing the pass timeout (for now), since I did not find an issue with overly long passes during training (might change with additional passes in the future), and this often raises issues when running multiple worker instances.
Fixes #678
Assisted-by: GPT-5.5 via Codex
Checklist
If PR contains AI-assisted content:
Assisted-by: [Model Name] via [Tool Name]footer.