quantumlib / Cirq

A Python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.
Apache License 2.0
4.26k stars 1.01k forks source link

Wavefunction simulator should accept NoiseModel too #2432

Closed kevinsung closed 3 years ago

kevinsung commented 4 years ago

It can simulate mixtures and coherent noise models.

Strilanc commented 4 years ago

I think we need to have noise models declare themselves as "monte carlo unitary safe" or something like that in order for this to work properly.

kevinsung commented 4 years ago

I was thinking the simulator could just raise a runtime error if it encounters a gate it can't simulate, but your solution is probably better.

kevinsung commented 4 years ago

I think we should add is_mixture_of_unitaries and is_coherent methods/properties to NoiseModel.

kevinsung commented 4 years ago

We decided at #2440 to make the simulator do all the work instead of letting noise models declare whether they can be simulated.

Strilanc commented 4 years ago

In the specific case of the wave functio nsimulator being given a noise model, it should be understood that if you give a noise model it can't handle then you will get an error.

daxfohl commented 3 years ago

Is this just a matter of copying the noise preprocessing code from density matrix simulator to the sparse simulator? https://github.com/quantumlib/Cirq/blob/e46f62eb1cfec26b876411042f756f6187a52285/cirq/sim/density_matrix_simulator.py#L265

95-martin-orion commented 3 years ago

Is this just a matter of copying the noise preprocessing code from density matrix simulator to the sparse simulator?

Prior discussion on this issue suggests that there's a degree of validation required here. There are effectively three types of noise that a NoiseModel can generate, and the sparse simulator only supports two of them:

  1. Adding "noise" gates into the circuit (supported)
  2. Converting gates into mixtures (supported)
  3. Converting gates into channels (not supported)

Without some nontrivial changes in the sparse simulator, (3) must be rejected. I think you can handle this with two checks:

cirq.has_mixture(gate)  # true for mixtures and gates, but not channels
cirq.is_measurement(gate)  # true for measurements, which aren't "noise" but don't have a mixture

Now that CircuitOperation exists, this check will need to be recursive.

95-martin-orion commented 3 years ago

Incidentally, this check should be very similar (but not identical) to the is_noisy check defined in #3799.