Add noise model API for Stim circuit compilation#160
Add noise model API for Stim circuit compilation#160
Conversation
Enhance noise_model.py with detailed NumPy-style docstrings including: - Module-level documentation with usage examples - NoiseKind enum descriptions for each event type - NoiseOp and NoiseEvent parameter documentation with examples - NoiseModel abstract class with comprehensive examples and notes Add Sphinx documentation: - Create docs/source/noise_model.rst for API reference - Add noise_model to module reference in references.rst Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…odel] - Replace string-based noise API with typed NoiseOp dataclasses (PauliChannel1, PauliChannel2, HeraldedPauliChannel1, HeraldedErase, RawStimOp) - Add typed event classes (PrepareEvent, EntangleEvent, MeasureEvent, IdleEvent) with NodeInfo and Coordinate for position-dependent noise models - Change NoiseModel method return type from Iterable[NoiseOp] to Sequence[NoiseOp] for covariance (allows subclasses to return Sequence[PauliChannel1] etc.) - Update stim_compile to accept Sequence[NoiseModel] instead of single NoiseModel for composing multiple independent noise sources - Add NoisePlacement enum (AUTO, BEFORE, AFTER) for controlling noise insertion - Add comprehensive tests for noise_model module Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Update module docstrings to use the standard "This module provides:" format with a list of public exports. Replace all double backticks with single backticks for inline code references to match the project's documentation style conventions. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Use double backticks for non-Python references (Stim instruction names, parameter names, example values) and proper Sphinx roles (:data:) for module constants. Single backticks remain only for Python object cross- references. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add utility function that creates a probability dict with all 15 Pauli pairs having equal probability p/15. Update the module docstring example to use this utility for proper 2-qubit depolarizing noise instead of the simplified ZZ-only version. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add utility function that creates px, py, pz probabilities each set to p/3 for single-qubit depolarizing channel. Update the module docstring example to use both depolarize1_probs and depolarize2_probs. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace old parameter-based noise API with the new NoiseModel classes: - Use DepolarizingNoiseModel instead of p_depol_after_clifford - Use MeasurementFlipNoiseModel instead of p_before_meas_flip Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #160 +/- ##
==========================================
+ Coverage 83.65% 85.20% +1.54%
==========================================
Files 21 22 +1
Lines 2313 2650 +337
Branches 416 456 +40
==========================================
+ Hits 1935 2258 +323
- Misses 287 293 +6
- Partials 91 99 +8 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a571d0fef9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
graphqomb/stim_compiler.py
Outdated
| if self._noise_models: | ||
| return self._noise_models[0].default_placement(event) |
There was a problem hiding this comment.
Apply AUTO placement using each model's default
The compiler flattens ops from all noise_models, but AUTO placement is resolved with only self._noise_models[0].default_placement(event). This means any later model that overrides default_placement has its AUTO ops inserted on the wrong side of the event (for example, AFTER-intended measurement noise can be emitted BEFORE), producing incorrect circuits whenever multiple models are combined.
Useful? React with 👍 / 👎.
graphqomb/stim_compiler.py
Outdated
| if isinstance(op, MeasurementFlip) and op.target == node: | ||
| meas_flip_p = max(meas_flip_p, op.p) |
There was a problem hiding this comment.
Combine MeasurementFlip contributions instead of taking max
When more than one model emits MeasurementFlip for the same measurement, this logic keeps only the maximum probability and drops the rest. Because stim_compile explicitly supports multiple noise models, this underestimates measurement noise in combined-model runs (e.g., two independent flip sources do not both contribute), so simulation error rates are systematically too low.
Useful? React with 👍 / 👎.
Summary
NoiseModelAPI for injecting custom noise into Stim circuits during pattern compilationNoiseOpdataclasses (PauliChannel1,PauliChannel2,HeraldedPauliChannel1,HeraldedErase,RawStimOp,MeasurementFlip)DepolarizingNoiseModelandMeasurementFlipNoiseModelimplementationsdepolarize1_probs()anddepolarize2_probs()utility functionsstim_compile()to acceptnoise_modelsparameter withSequence[NoiseModel]supportTest plan
🤖 Generated with Claude Code