Skip to content

Commit ba2cd7f

Browse files
authored
Removing noise model check in Simulator initialization (#4216)
Addresses issue #4170 by removing NOISE_MODEL_LIKE check in sparse_simulator.py and updates tests accordingly.
1 parent 099fc74 commit ba2cd7f

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

cirq-core/cirq/sim/sparse_simulator.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
import numpy as np
2929

30-
from cirq import ops, protocols, qis, devices
30+
from cirq import ops, protocols, qis
3131
from cirq.sim import (
3232
simulator,
3333
state_vector,
@@ -154,9 +154,6 @@ def __init__(
154154
"""
155155
if np.dtype(dtype).kind != 'c':
156156
raise ValueError(f'dtype must be a complex type but was {dtype}')
157-
noise_model = devices.NoiseModel.from_noise_model_like(noise)
158-
if not protocols.has_mixture(noise_model):
159-
raise ValueError(f'noise must be unitary or mixture but was {noise_model}')
160157
super().__init__(
161158
dtype=dtype,
162159
noise=noise,

cirq-core/cirq/sim/sparse_simulator_test.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,12 @@ def test_nondeterministic_mixture_noise():
12701270
assert result1 != result2
12711271

12721272

1273-
def test_unsupported_noise_fails():
1274-
with pytest.raises(ValueError, match='noise'):
1275-
cirq.Simulator(noise=cirq.amplitude_damp(0.5))
1273+
def test_noise_model():
1274+
q = cirq.LineQubit(0)
1275+
circuit = cirq.Circuit(cirq.H(q), cirq.measure(q))
1276+
1277+
noise_model = cirq.NoiseModel.from_noise_model_like(cirq.depolarize(p=0.01))
1278+
simulator = cirq.Simulator(noise=noise_model)
1279+
result = simulator.run(circuit, repetitions=100)
1280+
1281+
assert 40 <= sum(result.measurements['0'])[0] < 60

0 commit comments

Comments
 (0)