From 36eaa33fe79729fa2fc04abfdf631a97e0247cd6 Mon Sep 17 00:00:00 2001 From: Matthew Harrigan Date: Thu, 25 Sep 2025 21:59:49 +0000 Subject: [PATCH 1/3] Support Cirq 1.5 --- dev_tools/requirements/deps/runtime.txt | 4 ++-- qualtran/bloqs/bookkeeping/split_test.py | 13 +++++++++---- qualtran/bloqs/mcmt/and_bloq.py | 2 +- qualtran/bloqs/swap_network/cswap_approx.py | 2 +- qualtran/cirq_interop/_cirq_to_bloq.py | 2 +- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/dev_tools/requirements/deps/runtime.txt b/dev_tools/requirements/deps/runtime.txt index 53d1a689e6..88e5892f34 100644 --- a/dev_tools/requirements/deps/runtime.txt +++ b/dev_tools/requirements/deps/runtime.txt @@ -2,9 +2,9 @@ attrs>=23.2.0 cachetools>=5.3 networkx -numpy +numpy~=1.26 sympy -cirq-core==1.4 +cirq-core>=1.4.0,<1.6 fxpmath galois diff --git a/qualtran/bloqs/bookkeeping/split_test.py b/qualtran/bloqs/bookkeeping/split_test.py index 685d7664ae..4ad2d50126 100644 --- a/qualtran/bloqs/bookkeeping/split_test.py +++ b/qualtran/bloqs/bookkeeping/split_test.py @@ -70,10 +70,15 @@ def test_classical_sim_dtypes(): assert isinstance(xx, np.ndarray) assert xx.tolist() == [1, 1, 1, 1, 1, 1, 1, 1] - # Warning: numpy will wrap too-large values - (xx,) = s.call_classically(reg=np.uint8(256)) - assert isinstance(xx, np.ndarray) - assert xx.tolist() == [0, 0, 0, 0, 0, 0, 0, 0] + numpy_major_version = int(np.__version__.split('.')[0]) + if numpy_major_version < 2: + # Warning: numpy 1 will wrap too-large values + (xx,) = s.call_classically(reg=np.uint8(256)) + assert isinstance(xx, np.ndarray) + assert xx.tolist() == [0, 0, 0, 0, 0, 0, 0, 0] + else: + with pytest.raises(OverflowError): + (xx,) = s.call_classically(reg=np.uint8(256)) with pytest.raises(ValueError): _ = s.call_classically(reg=np.uint16(256)) diff --git a/qualtran/bloqs/mcmt/and_bloq.py b/qualtran/bloqs/mcmt/and_bloq.py index 50f4bc5a5a..ca5c62adce 100644 --- a/qualtran/bloqs/mcmt/and_bloq.py +++ b/qualtran/bloqs/mcmt/and_bloq.py @@ -312,7 +312,7 @@ def _decompose_via_tree( control_values: Tuple[SymbolicInt, ...], ancillas: NDArray[cirq.Qid], target: cirq.Qid, - ) -> cirq.ops.op_tree.OpTree: + ): """Decomposes multi-controlled `And` in-terms of an `And` ladder of size #controls- 2.""" if len(controls) == 2: diff --git a/qualtran/bloqs/swap_network/cswap_approx.py b/qualtran/bloqs/swap_network/cswap_approx.py index 0629511b30..70de58fac0 100644 --- a/qualtran/bloqs/swap_network/cswap_approx.py +++ b/qualtran/bloqs/swap_network/cswap_approx.py @@ -72,7 +72,7 @@ def decompose_from_registers( ) -> Iterator[cirq.OP_TREE]: ctrl, target_x, target_y = quregs['ctrl'], quregs['x'], quregs['y'] - def g(q: cirq.Qid, adjoint=False) -> cirq.ops.op_tree.OpTree: + def g(q: cirq.Qid, adjoint=False): yield [cirq.S(q), cirq.H(q)] yield cirq.T(q) ** (1 - 2 * adjoint) yield [cirq.H(q), cirq.S(q) ** -1] diff --git a/qualtran/cirq_interop/_cirq_to_bloq.py b/qualtran/cirq_interop/_cirq_to_bloq.py index d2977e4339..b540af7d9e 100644 --- a/qualtran/cirq_interop/_cirq_to_bloq.py +++ b/qualtran/cirq_interop/_cirq_to_bloq.py @@ -436,7 +436,7 @@ def cirq_gate_to_bloq(gate: cirq.Gate) -> Bloq: if isinstance(gate, cirq.GlobalPhaseGate): if isinstance(gate.coefficient, numbers.Complex): return GlobalPhase.from_coefficient(coefficient=complex(gate.coefficient)) - return GlobalPhase.from_coefficient(coefficient=gate.coefficient) + return GlobalPhase.from_coefficient(coefficient=gate.coefficient) # type: ignore[arg-type] # No known basic gate, wrap the cirq gate in a CirqGateAsBloq wrapper. return CirqGateAsBloq(gate) From 8404cb11835a6686f3e2f573006a33e2bad6bc87 Mon Sep 17 00:00:00 2001 From: Matthew Harrigan Date: Thu, 25 Sep 2025 22:08:56 +0000 Subject: [PATCH 2/3] re-pip-compile --- dev_tools/requirements/envs/dev.env.txt | 2 +- dev_tools/requirements/envs/docs.env.txt | 2 +- dev_tools/requirements/envs/format.env.txt | 2 +- dev_tools/requirements/envs/mypy.env.txt | 2 +- dev_tools/requirements/envs/pylint.env.txt | 2 +- dev_tools/requirements/envs/pytest.env.txt | 2 +- dev_tools/requirements/envs/runtime.env.txt | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dev_tools/requirements/envs/dev.env.txt b/dev_tools/requirements/envs/dev.env.txt index 832df23039..9f759d4fd4 100644 --- a/dev_tools/requirements/envs/dev.env.txt +++ b/dev_tools/requirements/envs/dev.env.txt @@ -94,7 +94,7 @@ cffi==1.17.1 # cryptography charset-normalizer==3.4.3 # via requests -cirq-core==1.4.0 +cirq-core==1.5.0 # via # -r deps/runtime.txt # openfermion diff --git a/dev_tools/requirements/envs/docs.env.txt b/dev_tools/requirements/envs/docs.env.txt index 9c54fae7d3..fc883eaed2 100644 --- a/dev_tools/requirements/envs/docs.env.txt +++ b/dev_tools/requirements/envs/docs.env.txt @@ -123,7 +123,7 @@ charset-normalizer==3.4.3 # via # -c envs/dev.env.txt # requests -cirq-core==1.4.0 +cirq-core==1.5.0 # via # -c envs/dev.env.txt # -r deps/runtime.txt diff --git a/dev_tools/requirements/envs/format.env.txt b/dev_tools/requirements/envs/format.env.txt index 7a1f265ca2..36b1898b53 100644 --- a/dev_tools/requirements/envs/format.env.txt +++ b/dev_tools/requirements/envs/format.env.txt @@ -109,7 +109,7 @@ charset-normalizer==3.4.3 # via # -c envs/dev.env.txt # requests -cirq-core==1.4.0 +cirq-core==1.5.0 # via # -c envs/dev.env.txt # -r deps/runtime.txt diff --git a/dev_tools/requirements/envs/mypy.env.txt b/dev_tools/requirements/envs/mypy.env.txt index a73204217b..fc563b1f32 100644 --- a/dev_tools/requirements/envs/mypy.env.txt +++ b/dev_tools/requirements/envs/mypy.env.txt @@ -101,7 +101,7 @@ charset-normalizer==3.4.3 # via # -c envs/dev.env.txt # requests -cirq-core==1.4.0 +cirq-core==1.5.0 # via # -c envs/dev.env.txt # -r deps/runtime.txt diff --git a/dev_tools/requirements/envs/pylint.env.txt b/dev_tools/requirements/envs/pylint.env.txt index 47c171c0b1..f60f73ec08 100644 --- a/dev_tools/requirements/envs/pylint.env.txt +++ b/dev_tools/requirements/envs/pylint.env.txt @@ -122,7 +122,7 @@ charset-normalizer==3.4.3 # via # -c envs/dev.env.txt # requests -cirq-core==1.4.0 +cirq-core==1.5.0 # via # -c envs/dev.env.txt # -r deps/runtime.txt diff --git a/dev_tools/requirements/envs/pytest.env.txt b/dev_tools/requirements/envs/pytest.env.txt index 0f27f63cc4..9b379ccbf2 100644 --- a/dev_tools/requirements/envs/pytest.env.txt +++ b/dev_tools/requirements/envs/pytest.env.txt @@ -109,7 +109,7 @@ charset-normalizer==3.4.3 # via # -c envs/dev.env.txt # requests -cirq-core==1.4.0 +cirq-core==1.5.0 # via # -c envs/dev.env.txt # -r deps/runtime.txt diff --git a/dev_tools/requirements/envs/runtime.env.txt b/dev_tools/requirements/envs/runtime.env.txt index e9154812e6..45b4197af7 100644 --- a/dev_tools/requirements/envs/runtime.env.txt +++ b/dev_tools/requirements/envs/runtime.env.txt @@ -101,7 +101,7 @@ charset-normalizer==3.4.3 # via # -c envs/dev.env.txt # requests -cirq-core==1.4.0 +cirq-core==1.5.0 # via # -c envs/dev.env.txt # -r deps/runtime.txt From 96be47866186ea543f730be9fd12eaf518d1b87d Mon Sep 17 00:00:00 2001 From: Matthew Harrigan Date: Mon, 13 Oct 2025 10:48:19 -0700 Subject: [PATCH 3/3] format --- qualtran/bloqs/swap_network/cswap_approx.py | 1 - 1 file changed, 1 deletion(-) diff --git a/qualtran/bloqs/swap_network/cswap_approx.py b/qualtran/bloqs/swap_network/cswap_approx.py index eb2eea04b8..362798e240 100644 --- a/qualtran/bloqs/swap_network/cswap_approx.py +++ b/qualtran/bloqs/swap_network/cswap_approx.py @@ -72,7 +72,6 @@ def decompose_from_registers( ) -> Iterator[cirq.OP_TREE]: ctrl, target_x, target_y = quregs['ctrl'], quregs['x'], quregs['y'] - def g(q: cirq.Qid, adjoint=False) -> Iterator[cirq.OP_TREE]: yield [cirq.S(q), cirq.H(q)] yield cirq.T(q) ** (1 - 2 * adjoint)