Skip to content

Commit

Permalink
Removing noise model check in Simulator initialization (#4216)
Browse files Browse the repository at this point in the history
Addresses issue #4170 by removing NOISE_MODEL_LIKE check in sparse_simulator.py and updates tests accordingly.
  • Loading branch information
asmuzsoy committed Jun 21, 2021
1 parent 099fc74 commit ba2cd7f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 1 addition & 4 deletions cirq-core/cirq/sim/sparse_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import numpy as np

from cirq import ops, protocols, qis, devices
from cirq import ops, protocols, qis
from cirq.sim import (
simulator,
state_vector,
Expand Down Expand Up @@ -154,9 +154,6 @@ def __init__(
"""
if np.dtype(dtype).kind != 'c':
raise ValueError(f'dtype must be a complex type but was {dtype}')
noise_model = devices.NoiseModel.from_noise_model_like(noise)
if not protocols.has_mixture(noise_model):
raise ValueError(f'noise must be unitary or mixture but was {noise_model}')
super().__init__(
dtype=dtype,
noise=noise,
Expand Down
12 changes: 9 additions & 3 deletions cirq-core/cirq/sim/sparse_simulator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,12 @@ def test_nondeterministic_mixture_noise():
assert result1 != result2


def test_unsupported_noise_fails():
with pytest.raises(ValueError, match='noise'):
cirq.Simulator(noise=cirq.amplitude_damp(0.5))
def test_noise_model():
q = cirq.LineQubit(0)
circuit = cirq.Circuit(cirq.H(q), cirq.measure(q))

noise_model = cirq.NoiseModel.from_noise_model_like(cirq.depolarize(p=0.01))
simulator = cirq.Simulator(noise=noise_model)
result = simulator.run(circuit, repetitions=100)

assert 40 <= sum(result.measurements['0'])[0] < 60

0 comments on commit ba2cd7f

Please sign in to comment.