From 0559dfdc369b5a73c5cab58f8e43bae7a27d113d Mon Sep 17 00:00:00 2001 From: Matthew Harrigan Date: Wed, 21 Aug 2024 00:47:58 +0000 Subject: [PATCH] [style] Only use "cbloq" for composite bloqs (#1325) --- qualtran/_infra/controlled_test.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/qualtran/_infra/controlled_test.py b/qualtran/_infra/controlled_test.py index 9c3f50532..ebdc92d71 100644 --- a/qualtran/_infra/controlled_test.py +++ b/qualtran/_infra/controlled_test.py @@ -341,9 +341,9 @@ def test_notebook(): def _verify_ctrl_tensor_for_unitary(ctrl_spec: CtrlSpec, bloq: Bloq, gate: cirq.Gate): - cbloq = Controlled(bloq, ctrl_spec) + ctrl_bloq = Controlled(bloq, ctrl_spec) cgate = cirq.ControlledGate(gate, control_values=ctrl_spec.to_cirq_cv()) - np.testing.assert_allclose(cbloq.tensor_contract(), cirq.unitary(cgate), atol=1e-8) + np.testing.assert_allclose(ctrl_bloq.tensor_contract(), cirq.unitary(cgate), atol=1e-8) interesting_ctrl_specs = [ @@ -368,15 +368,15 @@ def test_controlled_tensor_for_unitary(ctrl_spec: CtrlSpec): def test_controlled_tensor_without_decompose(): ctrl_spec = CtrlSpec() bloq = TwoBitCSwap() - cbloq = Controlled(bloq, ctrl_spec) + ctrl_bloq = Controlled(bloq, ctrl_spec) cgate = cirq.ControlledGate(cirq.CSWAP, control_values=ctrl_spec.to_cirq_cv()) - tn = cbloq_to_quimb(cbloq.as_composite_bloq()) + tn = cbloq_to_quimb(ctrl_bloq.as_composite_bloq()) # pylint: disable=unbalanced-tuple-unpacking - right, left = get_right_and_left_inds(tn, cbloq.signature) + right, left = get_right_and_left_inds(tn, ctrl_bloq.signature) # pylint: enable=unbalanced-tuple-unpacking np.testing.assert_allclose(tn.to_dense(right, left), cirq.unitary(cgate), atol=1e-8) - np.testing.assert_allclose(cbloq.tensor_contract(), cirq.unitary(cgate), atol=1e-8) + np.testing.assert_allclose(ctrl_bloq.tensor_contract(), cirq.unitary(cgate), atol=1e-8) def test_controlled_global_phase_tensor(): @@ -402,10 +402,10 @@ def signature(self) -> 'Signature': def build_composite_bloq(self, bb: 'BloqBuilder') -> Dict[str, 'SoquetT']: one_or_zero = [ZeroState(), OneState()] - cbloq = Controlled(And(*self.and_ctrl), ctrl_spec=self.ctrl_spec) + ctrl_bloq = Controlled(And(*self.and_ctrl), ctrl_spec=self.ctrl_spec) ctrl_soqs = {} - for reg, cvs in zip(cbloq.ctrl_regs, self.ctrl_spec.cvs): + for reg, cvs in zip(ctrl_bloq.ctrl_regs, self.ctrl_spec.cvs): soqs = np.empty(shape=reg.shape, dtype=object) for idx in reg.all_idxs(): soqs[idx] = bb.add(IntState(val=cvs[idx], bitsize=reg.dtype.num_qubits)) @@ -413,10 +413,10 @@ def build_composite_bloq(self, bb: 'BloqBuilder') -> Dict[str, 'SoquetT']: and_ctrl = [bb.add(one_or_zero[cv]) for cv in self.and_ctrl] - ctrl_soqs = bb.add_d(cbloq, **ctrl_soqs, ctrl=and_ctrl) + ctrl_soqs = bb.add_d(ctrl_bloq, **ctrl_soqs, ctrl=and_ctrl) out_soqs = np.asarray([*ctrl_soqs.pop('ctrl'), ctrl_soqs.pop('target')]) # type: ignore[misc] - for reg, cvs in zip(cbloq.ctrl_regs, self.ctrl_spec.cvs): + for reg, cvs in zip(ctrl_bloq.ctrl_regs, self.ctrl_spec.cvs): for idx in reg.all_idxs(): ctrl_soq = np.asarray(ctrl_soqs[reg.name])[idx] bb.add(IntEffect(val=cvs[idx], bitsize=reg.dtype.num_qubits), val=ctrl_soq) @@ -424,8 +424,8 @@ def build_composite_bloq(self, bb: 'BloqBuilder') -> Dict[str, 'SoquetT']: def _verify_ctrl_tensor_for_and(ctrl_spec: CtrlSpec, and_ctrl: Tuple[int, int]): - cbloq = TestCtrlStatePrepAnd(ctrl_spec, and_ctrl) - bloq_tensor = cbloq.tensor_contract() + bloq = TestCtrlStatePrepAnd(ctrl_spec, and_ctrl) + bloq_tensor = bloq.tensor_contract() cirq_state_vector = GateHelper(And(*and_ctrl)).circuit.final_state_vector( initial_state=and_ctrl + (0,) )