quantumlib / OpenFermion

The electronic structure package for quantum computers.
Apache License 2.0
1.51k stars 372 forks source link

QuadraticFermionicSimulationGate tests fail with cirq == 1.3.0 #865

Closed fdmalone closed 7 months ago

fdmalone commented 7 months ago
import openfermion
from openfermion.circuits.gates.fermionic_simulation_test import assert_permute_consistent

gate = openfermion.QuarticFermionicSimulationGate(
    (
        (7.0342200118223275 + 18.937442050412095j),
        (1.7822288828087238 - 13.314793949155135j),
        (13.085448799969598 - 7.627580846758029j),
    ),
    absorb_exponent=False,
    exponent=10.086043324530468,
)

assert_permute_consistent(gate)

this passes with cirq == 1.2.0, but fails for cirq == 1.3.0

mpharrigan commented 7 months ago

Do you have any leads on what changed?

fdmalone commented 7 months ago

Just looking at the release notes it's looks like there were some PRs related to EigenGate which this QFSG inherits from (e.g. https://github.com/quantumlib/Cirq/pull/6231), not sure if related yet.

mpharrigan commented 7 months ago

I see https://github.com/quantumlib/Cirq/pull/6275 and I see that the test is trying to make a shallow copy of the gate with __copy__. I would bet money that this is the source of the issue

mpharrigan commented 7 months ago

diff --git a/src/openfermion/circuits/gates/fermionic_simulation.py b/src/openfermion/circuits/gates/fermionic_simulation.py
index 3c03e11..0face4b 100644
--- a/src/openfermion/circuits/gates/fermionic_simulation.py
+++ b/src/openfermion/circuits/gates/fermionic_simulation.py
@@ -182,7 +182,7 @@ def sum_of_interaction_operator_gate_generators(
     return operator

-@cirq.value_equality(approximate=True)
+@cirq.value_equality(approximate=True, unhashable=True)
 class ParityPreservingFermionicGate(cirq.Gate, metaclass=abc.ABCMeta):
     r"""The Jordan-Wigner transform of $\exp(-i H)$ for a fermionic
     Hamiltonian $H$.

fixes

fdmalone commented 7 months ago

Fixed in #867