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

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
@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.59%. Comparing base (4adcfb9) to head (7d3a59d).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8139   +/-   ##
=======================================
  Coverage   99.59%   99.59%           
=======================================
  Files        1131     1131           
  Lines      103601   103642   +41     
=======================================
+ Hits       103180   103221   +41     
  Misses        421      421           

☔ 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
@mhucka

mhucka commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

@Acciaccatura Thank you for this effort. If you are still working on this, would you mind changing it to a draft PR?

@mhucka mhucka added the priority/after-1.8 Deferred until after the Cirq 1.8 release label Sep 4, 2026
@Acciaccatura
Acciaccatura marked this pull request as draft September 25, 2026 06:06
@review-notebook-app

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@github-actions github-actions Bot added size: XL lines changed >1000 and removed size: M 50< lines changed <250 labels Sep 25, 2026
@github-actions github-actions Bot removed the size: XL lines changed >1000 label Sep 25, 2026
@github-actions github-actions Bot added the size: M 50< lines changed <250 label Sep 25, 2026
@Acciaccatura

Copy link
Copy Markdown
Contributor Author

hey @mhucka ! sorry I missed your message. this PR is ready for review - I just rebased :). i've left some comments on some areas I think might require some clarification.

@Acciaccatura
Acciaccatura marked this pull request as ready for review September 25, 2026 10:16
circuit_gates = {op.gate for op in circuit.all_operations()}
if not all(
any(
isinstance(gate, expected_gate)

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.

noise models define their expected gateset explicitly - for example:

@classmethod
def single_qubit_gates(cls) -> set[type]:
return {cirq.ZPowGate, cirq.PhasedXZGate, cirq.MeasurementGate, cirq.ResetChannel}

there are some gates that are mathematically equivalent to other gates (e.g. I think PhasedXZGate(axis_phase_exponent=0, x_exponent=1, z_exponent=0) and X), but I believe this check will not allow X. is this ok, and if not is there a better alternative for testing gate equality?

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

Labels

priority/after-1.8 Deferred until after the Cirq 1.8 release 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

3 participants