Skip to content

Commit

Permalink
wfn compact visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
davibinco committed Dec 11, 2024
1 parent a12e33f commit 4a6148d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/tequila/wavefunction/qubit_wavefunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,15 +365,18 @@ def normalize(self, inplace: bool = False) -> QubitWaveFunction:
# because the __mul__ implementation of the number tries to perform some sort of array
# operation.
def length(self):
return sum(1 for (k, v) in self.raw_items() if abs(v) > 1e-6)
return sum(1 for _ in self.raw_items())

def __repr__(self):
result = str()
for index, coeff in self.items():
index = index.integer
if self.numbering == BitNumbering.LSB:
index = reverse_int_bits(index, self._n_qubits)
result += f"{coeff} |{index:0{self._n_qubits}b}> "
if np.isclose(coeff.imag,0.0):
result += f"{coeff.real:+2.4f} |{index:0{self._n_qubits}b}> "
else:
result += f"({coeff.real:+2.4f} + {coeff.imag:+2.4f}i) |{index:0{self._n_qubits}b}>"
# If the wavefunction contains no states
if not result:
result = "empty wavefunction"
Expand Down

0 comments on commit 4a6148d

Please sign in to comment.