Skip to content

Ensure simulator runs circuit compatible with a provided noise model's properties#8139

Open
Acciaccatura wants to merge 12 commits into
quantumlib:mainfrom
Acciaccatura:issue6608
Open

Ensure simulator runs circuit compatible with a provided noise model's properties#8139
Acciaccatura wants to merge 12 commits into
quantumlib:mainfrom
Acciaccatura:issue6608

Conversation

@Acciaccatura

@Acciaccatura Acciaccatura commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

When provided a NoiseModelFromNoiseProperties noise model to simulate, ensure the circuit uses qubits and gates that are compatible with the noise properties. At a slightly lower level:

  • NoiseModelFromNoiseProperties exposes its underlying NoiseProperties as a public property.
  • SimulatorBase will check to make sure all the gates and qubits used by the circuit are permitted under any NoiseProperties from the associated NoiseModelFromNoiseProperties.
    • In the current state, only SuperconductingQubitsNoiseProperties contains expected_qubits or expected_gates, so the code is currently hardcoded to this class. I'm uncertain if Cirq has any plans on genericizing this behavior to NoiseProperties.

fixes #6608

@Acciaccatura Acciaccatura requested a review from a team as a code owner June 14, 2026 23:12
@Acciaccatura Acciaccatura requested a review from maffoo June 14, 2026 23:12
@github-actions github-actions Bot added the size: M 50< lines changed <250 label Jun 14, 2026
@Acciaccatura

Copy link
Copy Markdown
Contributor Author

question - this change seems to be blocked on a Docstring test failure, specifically this one:

>>> cal = cirq_google.engine.load_median_device_calibration("rainbow")
>>> noise_props = cirq_google.engine.noise_properties_from_calibration(
... cal, gate_times_ns="legacy")
>>> noise_model = cirq_google.NoiseModelFromGoogleNoiseProperties(noise_props)
>>> simulator = cirq.Simulator(noise=noise_model)
>>> circuit = cirq.Circuit(cirq.X(cirq.GridQubit(5, 2)))
>>> result = simulator.simulate(circuit)

however when checking the expected gateset of the noise properties from this processor myself, it seems its failure is working as intended according to my implementation:

>>> import cirq_google
>>> cal = cirq_google.engine.load_median_device_calibration("rainbow")
>>> noise_props = cirq_google.engine.noise_properties_from_calibration(cal, gate_times_ns="legacy\
")
>>> print(noise_props.expected_gates())
{<class 'cirq.ops.measurement_gate.MeasurementGate'>, <class 'cirq.ops.swap_gates.ISwapPowGate'>, <class 'cirq.ops.fsim_gate.FSimGate'>, <class 'cirq.ops.common_gates.ZPowGate'>, <class 'cirq.ops.fsim_gate.PhasedFSimGate'>, <class 'cirq.ops.common_gates.CZPowGate'>, <class 'cirq.ops.phased_x_z_gate.PhasedXZGate'>, <class 'cirq_google.ops.sycamore_gate.SycamoreGate'>, <class 'cirq.ops.common_channels.ResetChannel'>}

(i.e. my implementation assumes cirq.X or any of its superclass gates must appear in the noise property's expected gateset, which it doesn't). is this expected, and if not, how should I change my implementation?

Comment thread cirq-core/cirq/sim/simulator_base.py Outdated
import cirq

TStepResultBase = TypeVar('TStepResultBase', bound='StepResultBase')
TStepResultBase = TypeVar("TStepResultBase", bound="StepResultBase")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lots of modifications to this file due to running ruff format.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert. Use check/format-incremental for formatting instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, will do - fixed!

@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.60%. Comparing base (835ca4b) to head (10173fc).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8139      +/-   ##
==========================================
- Coverage   99.60%   99.60%   -0.01%     
==========================================
  Files        1118     1118              
  Lines      101061   101102      +41     
==========================================
+ Hits       100661   100701      +40     
- Misses        400      401       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.


unexpected_qubits = [cirq.GridQubit(2, 2)]

class TestNoiseProperties(devices.SuperconductingQubitsNoiseProperties):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the TestNoiseProperties created for this test might not make sense from a QC point of view just because of my limited domain knowledge - feel free to re-implement to something more sensible if this is a concern!

Comment thread cirq-core/cirq/sim/simulator_base.py Outdated
import cirq

TStepResultBase = TypeVar('TStepResultBase', bound='StepResultBase')
TStepResultBase = TypeVar("TStepResultBase", bound="StepResultBase")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, will do - fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: M 50< lines changed <250

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NoiseModelFromGoogleNoiseProperties should raise an error when simulations use qubits not on the device or an uncompiled circuit

2 participants