-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Ensure simulator runs circuit compatible with a provided noise model's properties #8139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Acciaccatura
wants to merge
12
commits into
quantumlib:main
Choose a base branch
from
Acciaccatura:issue6608
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+90
−2
Open
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
91cdc5f
bug: added gate/qubit compatability checking for simulations
Acciaccatura 9349d73
feat: reformat with ruff
Acciaccatura 664ea5b
lint: undo lint changes from ruff
Acciaccatura 62875a2
bug: mistype
Acciaccatura 9979e55
bug: update docstring to fit this commit
Acciaccatura 8977a62
bug: update docstring to compile correctly
Acciaccatura e093fd2
feat: rebase and update to new functions/variables
Acciaccatura af6383b
feat: reformat with ruff
Acciaccatura 3801697
lint: undo lint changes from ruff
Acciaccatura 75b1b05
bug: mistype
Acciaccatura 7e8f89d
bug: remove test file for other issue
Acciaccatura 7d3a59d
lint: add some more details in the comments
Acciaccatura File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,8 @@ | |
| import sympy | ||
|
|
||
| import cirq | ||
| from cirq import devices, ops | ||
| from cirq.devices import noise_utils | ||
|
|
||
|
|
||
| class CountingState(cirq.qis.QuantumStateRepresentation): | ||
|
|
@@ -464,3 +466,50 @@ def test_simulate_unresolved_parameter_raises() -> None: | |
| match=r'Circuit contains ops whose symbols were not specified in the parameter sweep\.', | ||
| ): | ||
| sim.simulate(circuit) | ||
|
|
||
|
|
||
| def test_simulates_noise_only_on_valid_gates_and_qubits() -> None: | ||
| expected_single_qubit_gates = [cirq.XPowGate, cirq.ZPowGate] | ||
| expected_qubits = [cirq.GridQubit(1, 2)] | ||
|
|
||
| unexpected_qubits = [cirq.GridQubit(2, 2)] | ||
|
|
||
| class TestNoiseProperties(devices.SuperconductingQubitsNoiseProperties): | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the |
||
| @classmethod | ||
| def single_qubit_gates(cls) -> set[type[ops.Gate]]: | ||
| return set(expected_single_qubit_gates) | ||
|
|
||
| @classmethod | ||
| def symmetric_two_qubit_gates(cls) -> set[type[ops.Gate]]: | ||
| return set() | ||
|
|
||
| @classmethod | ||
| def asymmetric_two_qubit_gates(cls) -> set[type[ops.Gate]]: | ||
| return set() | ||
|
|
||
| noise_props = TestNoiseProperties( | ||
| gate_times_ns=dict.fromkeys(expected_single_qubit_gates, 1e9), | ||
| t1_ns=dict.fromkeys(expected_qubits, 1e9), | ||
| tphi_ns=dict.fromkeys(expected_qubits, 1e9), | ||
| readout_errors=dict.fromkeys(expected_qubits, [0.5, 0.5]), | ||
| gate_pauli_errors={ | ||
| noise_utils.OpIdentifier(gate, expected_qubits[0]): 0 | ||
| for gate in expected_single_qubit_gates | ||
| }, | ||
| ) | ||
| noise_model = devices.NoiseModelFromNoiseProperties(noise_props) | ||
|
|
||
| simulator = cirq.Simulator(noise=noise_model) | ||
|
|
||
| valid_circuit_invalid_qubits = cirq.Circuit(cirq.X(unexpected_qubits[0])) | ||
| valid_circuit_valid_qubits = cirq.Circuit(cirq.X(expected_qubits[0])) | ||
| invalid_circuit_invalid_qubits = cirq.Circuit(cirq.Y(unexpected_qubits[0])) | ||
| invalid_circuit_valid_qubits = cirq.Circuit(cirq.Y(expected_qubits[0])) | ||
|
|
||
| with pytest.raises(TypeError): | ||
| simulator.simulate(invalid_circuit_invalid_qubits) | ||
| with pytest.raises(TypeError): | ||
| simulator.simulate(invalid_circuit_valid_qubits) | ||
| with pytest.raises(TypeError): | ||
| simulator.simulate(valid_circuit_invalid_qubits) | ||
| simulator.simulate(valid_circuit_valid_qubits) | ||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
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:
Cirq/cirq-google/cirq_google/devices/google_noise_properties.py
Lines 189 to 191 in 4adcfb9
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)andX), but I believe this check will not allowX. is this ok, and if not is there a better alternative for testing gate equality?