Add custom noise model support to compile_canvas_to_stim#114
Conversation
Extract compile_canvas_to_pattern as a reusable function and extend compile_canvas_to_stim to accept graphqomb NoiseModel instances via the noise_models parameter. Legacy parameters (p_depol_after_clifford, p_before_meas_flip) remain supported but are now optional. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Pull Request Review: Add custom noise model support to compile_canvas_to_stimSummaryThis PR introduces custom noise model support to the
Code Quality ✅Strengths:
Structure:
Potential Issues & Recommendations🔴 Critical: Missing Validation LogicThe PR documents that legacy parameters "Cannot be combined with Current code (lspattern/compiler.py:154-155): pattern, _graph, node_map = compile_canvas_to_pattern(canvas)
# No validation here!Required fix: # Validate that legacy and noise_models params are not mixed
if noise_models is not None and (p_depol_after_clifford is not None or p_before_meas_flip is not None):
msg = "Legacy noise parameters cannot be used together with noise_models"
raise ValueError(msg)This validation might be implemented in Performance ✅No performance concerns. The refactoring does not add overhead—just reorganizes existing logic. Security ✅No security concerns identified. Test Coverage
|
There was a problem hiding this comment.
Pull request overview
This PR extends the Stim compilation pipeline to support injecting custom graphqomb.NoiseModel instances, while also extracting the core “canvas → pattern” compilation into a reusable helper.
Changes:
- Extract
compile_canvas_to_pattern(canvas) -> (Pattern, BaseGraphState, node_map)from the existing Stim compilation flow. - Extend
compile_canvas_to_stimwith anoise_modelsparameter for custom noise injection. - Make legacy noise parameters optional and add tests covering custom noise injection and argument-mixing rejection.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
lspattern/compiler.py |
Refactors compilation into a reusable pattern compiler and adds noise_models support to Stim compilation. |
tests/test_custom_noise_models.py |
Adds tests validating custom noise model injection and enforcing mutual exclusivity with legacy noise params. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
compile_canvas_to_patternas a reusable function returning(Pattern, BaseGraphState, node_map)noise_modelsparameter tocompile_canvas_to_stimfor injecting customgraphqomb.NoiseModelinstancesp_depol_after_clifford,p_before_meas_flip) optionalTest plan
🤖 Generated with Claude Code