diff --git a/pytket/extensions/cutensornet/structured_state/general.py b/pytket/extensions/cutensornet/structured_state/general.py index ff14727d..d5512201 100644 --- a/pytket/extensions/cutensornet/structured_state/general.py +++ b/pytket/extensions/cutensornet/structured_state/general.py @@ -447,6 +447,10 @@ def get_amplitude(self, state: int) -> complex: """ raise NotImplementedError(f"Method not implemented in {type(self).__name__}.") + def get_bits(self) -> dict[Bit, bool]: + """Returns the dictionary of bits and their values.""" + return self._bits_dict.copy() + @abstractmethod def get_qubits(self) -> set[Qubit]: """Returns the set of qubits that ``self`` is defined on.""" diff --git a/tests/test_structured_state_conditionals.py b/tests/test_structured_state_conditionals.py index 95061d4e..6fa237cb 100644 --- a/tests/test_structured_state_conditionals.py +++ b/tests/test_structured_state_conditionals.py @@ -398,6 +398,8 @@ def test_repeat_until_sucess_i() -> None: assert np.isclose(state.vdot(state), 1.0, atol=cfg._atol) assert state.get_fidelity() == 1.0 + # The flag bit should have turned False + assert not state.get_bits()[flag[0]] # The auxiliary qubits should be in state |0> prob = state.postselect({qaux[0]: 0}) assert np.isclose(prob, 1.0) @@ -471,6 +473,8 @@ def test_repeat_until_sucess_ii() -> None: assert np.isclose(state.vdot(state), 1.0, atol=cfg._atol) assert state.get_fidelity() == 1.0 + # All of the flag bits should have turned False + assert all(not state.get_bits()[bit] for bit in flag) # The auxiliary qubits should be in state |0> prob = state.postselect({qaux[0]: 0, qaux[1]: 0}) assert np.isclose(prob, 1.0)