Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster PauliwordOp.to_opemnfermion #175

Merged
merged 3 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion symmer/operators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,7 @@ def to_openfermion(self) -> QubitOperator:
"""
open_f = QubitOperator()
for P_sym, coeff in zip(self.symp_matrix, self.coeff_vec):
open_f+=QubitOperator(' '.join([Pi+str(i) for i,Pi in enumerate(symplectic_to_string(P_sym)) if Pi!='I']), coeff)
open_f+=symplectic_to_openfermion(P_sym, coeff)
return open_f

@cached_property
Expand Down
31 changes: 31 additions & 0 deletions symmer/operators/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,37 @@ def symplectic_to_string(symp_vec) -> str:

return Pword_string

def symplectic_to_openfermion(symp_vec, coeff) -> str:
"""Returns string form of symplectic vector defined as (X | Z).

Args:
symp_vec (array): symplectic Pauliword array

Returns:
Pword_string (str): String version of symplectic array
"""
n_qubits = len(symp_vec) // 2

X_block = symp_vec[:n_qubits]
Z_block = symp_vec[n_qubits:]

Y_loc = np.logical_and(X_block, Z_block)
X_loc = np.logical_xor(Y_loc, X_block)
Z_loc = np.logical_xor(Y_loc, Z_block)

char_aray = np.array(list("I" * n_qubits), dtype=str)

char_aray[Y_loc] = "Y"
char_aray[X_loc] = "X"
char_aray[Z_loc] = "Z"

indices = np.array(range(n_qubits), dtype=str)
char_aray = np.char.add(char_aray, indices)[np.where(char_aray != "I")[0]]

Pword_string = " ".join(char_aray)

return QubitOperator(Pword_string, coeff)

def string_to_symplectic(pauli_str, n_qubits):
"""
Args:
Expand Down
Loading