Rename NoiseModel to NoiseParameters with a fluent interface - #435
Closed
ciaranra wants to merge 1 commit into
Closed
Rename NoiseModel to NoiseParameters with a fluent interface#435ciaranra wants to merge 1 commit into
ciaranra wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Renames the DEM-construction noise dataclass to
NoiseParameters, lifts it to thepecostop level, and gives it a fluentwith_*interface in the shape of thesim()noise builders. Closes #433.Stacked on #420 — it depends on the shared idle-noise vocabulary introduced there.
Merge #420 first.
Why the rename
NoiseModelcollided conceptually with the simulator-side noise models(
GeneralNoiseModel,DepolarizingNoiseModel), which are executable objects that applynoise during simulation. This one is a parameter bag consumed at DEM construction, and
since #422 it is the shared idle-noise vocabulary for both the Guppy and native-surface
routes — so it was neither a "model" nor surface-code-specific.
NoiseParametersis the real name;NoiseModelremains as a deprecated aliasresolving to the identical class, so no existing code breaks.
pecostop level, besidegeneral_noise()/depolarizing_noise().Deliberately not placed in
pecos.noise, which holds the legacy simulator errormodels (
DepolarModel,XZModel,GatewiseModel); a modern DEM parameter classthere would read as part of that old machinery.
pecos.qec.surface.not everyday use.
Fluent interface
Chained, immutable (every setter returns a new object via
dataclasses.replace), andwith no terminal method — matching the sim noise builders, which are passed directly
into
.noise(...). The dataclass constructor keeps working; the fluent form is additive.One mechanical rule:
with_<field_name>, no suffix translation. The simulator's_probability/_ratesuffixes were deliberately not mirrored: only four fields(
p1,p2,p_meas,p_prep) have simulator counterparts, so suffix-mirroring wouldbuy alignment on four methods while adding a translation layer to all thirty. It also
removes a hazard rather than documenting it — the simulator's
with_p_idle_linear_raterefers to what is our deprecated Z-only alias, not to the family scalar
p_idle_linear, so under the mechanical rule no false equivalence is expressible.One deliberate exception, found by testing rather than by design: the idle families
take their rate and model together, as
with_p_idle_linear(rate, model). Separatesetters are impossible in principle here —
__post_init__translates a family into thecanonical per-axis fields and then clears it, so a second call setting only the model
collides with the per-axis values the first call produced. A model without a rate is
inert and rejected anyway, so the two are inherently a pair. The first implementation
had split setters and raised
ValueErroron the natural usage.with_p_idle_linear(0.01).with_p_idle_linear_model({"Z": 1.0}).Verification
tests/qec: 1393 passed, 1 skipped, 1 xfailed — this suite exercises most of therenamed call sites and is the oracle that behavior did not change.
tests/qec/surface/test_noise_parameters.py: 12 tests covering the equivalenceoracle, immutability, the family round-trip through
for_runtime_idle_time_units(),the deprecated alias, import paths, and the paired-setter rule.
.ruff_cachecleared.