Skip to content

Commit

Permalink
Adding a method for users to recover the bit values of their simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloAndresCQ committed Sep 9, 2024
1 parent 02162f4 commit 689b0ee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pytket/extensions/cutensornet/structured_state/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
4 changes: 4 additions & 0 deletions tests/test_structured_state_conditionals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 689b0ee

Please sign in to comment.