Skip to content

Commit

Permalink
update format
Browse files Browse the repository at this point in the history
  • Loading branch information
madcpf committed Jul 22, 2024
1 parent acbeff6 commit 7c0cea9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions unitary/alpha/quantum_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ def density_matrix(
histogram = self.get_correlated_histogram(ordered_objects, count)

# Get an estimate of the state vector.
state_vector = np.array([0.] * (2**num_all_qubits))
state_vector = np.array([0.0] * (2**num_all_qubits))
for key, val in histogram.items():
state_vector += self.__to_state_vector__(key) * np.sqrt(val * 1.0 / count)
density_matrix = np.outer(state_vector, state_vector)
Expand Down Expand Up @@ -710,11 +710,11 @@ def __getitem__(self, name: str) -> QuantumObject:
return quantum_object

def __to_state_vector__(self, input: tuple) -> np.ndarray:
""" Converts the given tuple (of length N) to the corresponding state vector (of length 2**N).
"""Converts the given tuple (of length N) to the corresponding state vector (of length 2**N).
e.g. (0, 1) -> [0, 1, 0, 0]
"""
num = len(input)
index = int(''.join([str(i) for i in input]),2)
state_vector = np.array([0.] * (2**num))
index = int("".join([str(i) for i in input]), 2)
state_vector = np.array([0.0] * (2**num))
state_vector[index] = 1.0
return state_vector

0 comments on commit 7c0cea9

Please sign in to comment.