quantumlib / Cirq

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

failing comparisons for noise channels #6631

Open richrines1 opened 5 months ago

richrines1 commented 5 months ago

Description of the issue

two related bugs related to equality checks for noise channels:

How to reproduce the issue

cirq.approx_eq(cirq.depolarize(0.1), cirq.X)  # AttributeError: '_PauliX' object has no attribute 'p'
cirq.approx_eq(cirq.phase_damp(0.1), cirq.X)  # AttributeError: '_PauliX' object has no attribute '_gamma'
cirq.approx_eq(cirq.phase_flip(0.1), cirq.X)  # AttributeError: '_PauliX' object has no attribute '_p'
cirq.approx_eq(cirq.bit_flip(0.1), cirq.X)  # AttributeError: '_PauliX' object has no attribute '_p'
cirq.approx_eq(cirq.asymmetric_depolarize(0.1), cirq.X)  # AttributeError: '_PauliX' object has no attribute 'error_probabilities'

assert cirq.depolarize(0.1, 1) == cirq.depolarize(0.1, 2)  # passes, but shouldn't

i believe the first issue would be fixed by just adding approximate=True to the @value_equality decorator for each class and removing their explicit implementations of _approx_eq_. The second issue just requires the inclusion of n_qubits in DepolarizingChannel._value_equality_values_

Cirq version

1.4.0.dev20240529202703