Skip to content

Commit

Permalink
feat: Add type hints and consistency check for statevector sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshioka1128 committed Sep 25, 2024
1 parent 5428423 commit c19528b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/openqaoa-core/openqaoa/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -1985,11 +1985,16 @@ def to_bin(number, n_qubits):

return wavefunction

def is_close_statevector(statevector1, statevector2) -> bool:
def is_close_statevector(statevector1: np.ndarray, statevector2: np.ndarray) -> bool:
"""
Checks if statevector1 can be expressed as e^(i*theta) * statevector2.
Both statevector1 and statevector2 must be numpy arrays of the same size.
"""

# Check for size consistency
if statevector1.shape != statevector2.shape:
raise ValueError("The statevectors must have the same shape.")

# Threshold for considering a value to be zero
tolerance = 1e-10

Expand Down

0 comments on commit c19528b

Please sign in to comment.