Skip to content

Commit

Permalink
Remove commute_coeff
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-mills-cqc committed Dec 10, 2024
1 parent 00fc8ba commit b3c29a1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 70 deletions.
18 changes: 13 additions & 5 deletions qermit/noise_model/noise_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,14 @@ def to_ptm(self) -> Tuple[NDArray, Dict[Tuple[Pauli, ...], int]]:
pauli_iterable=error,
qubit_list=[Qubit(i) for i in range(self.n_qubits)],
)

ptm[index][index] += error_rate * QermitPauli.commute_coeff(
pauli_one=pauli, pauli_two=error_pauli
commute_coeff = (
1
if pauli.qubit_pauli_tensor.commutes_with(
error_pauli.qubit_pauli_tensor
)
else -1
)
ptm[index][index] += error_rate * commute_coeff

# Some checks that the form of the PTM is correct.
identity = tuple(Pauli.I for _ in range(self.n_qubits))
Expand Down Expand Up @@ -190,8 +194,12 @@ def from_ptm(
pauli_iterable=pauli_two_tuple,
qubit_list=[Qubit(i) for i in range(len(pauli_two_tuple))],
)
commutation_matrix[index_one][index_two] = QermitPauli.commute_coeff(
pauli_one=pauli_one, pauli_two=pauli_two
commutation_matrix[index_one][index_two] = (
1
if pauli_one.qubit_pauli_tensor.commutes_with(
pauli_two.qubit_pauli_tensor
)
else -1
)

error_rate_list = np.matmul(ptm.diagonal(), np.linalg.inv(commutation_matrix))
Expand Down
30 changes: 1 addition & 29 deletions qermit/noise_model/qermit_pauli.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,6 @@ def __init__(
self.phase = phase
self.qubit_list = qubit_list

@staticmethod
def commute_coeff(pauli_one: QermitPauli, pauli_two: QermitPauli) -> int:
"""Calculate the coefficient which result from commuting pauli_one
past pauli_two. That is to say P_2 P_1 = c P_1 P_2 where c is the
coefficient returned by this function.
:param pauli_one: First Pauli
:param pauli_two: Second Pauli
:raises Exception: Raised if the Paulis do not act
on matching qubits.
:return: Coefficient resulting from commuting the two Paulis.
"""
if not pauli_one.qubit_list == pauli_two.qubit_list:
raise Exception(
"The given Paulis must act on the same qubits. "
+ f"In this case the qubits acted on by pauli_one {pauli_one.qubit_list} "
+ f"differ from those of pauli_two {pauli_two.qubit_list}."
)
power = sum(
pauli_one.X_list[qubit] * pauli_two.Z_list[qubit]
for qubit in pauli_one.qubit_list
)
power += sum(
pauli_one.Z_list[qubit] * pauli_two.X_list[qubit]
for qubit in pauli_one.qubit_list
)
return (-1) ** power

def is_measureable(self, qubit_list: List[Qubit]) -> bool:
"""Checks if this Pauli would be measurable on the given qubits in the
computational bases. That is to say if at least one Pauli on the given
Expand Down Expand Up @@ -208,7 +180,7 @@ def __hash__(self):
return hash(key)

def __str__(self) -> str:
return str(self.qubit_pauli_tensor)
return str(self.qubit_pauli_tensor.string) + str(self.qubit_pauli_tensor.coeff)

def __eq__(self, other: object) -> bool:
"""Checks for equality by checking all qubits match, and that all
Expand Down
36 changes: 0 additions & 36 deletions tests/noise_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,42 +112,6 @@ def test_qermit_pauli_from_iterable() -> None:
pauli.qubit_pauli_tensor.coeff == 1 + 0j


def test_qermit_pauli_commute_coeff() -> None:
# This tests a few commutation coefficients
# which have been verified by hand.
verified_list = [
# Single qubit Paulis
((([0], [1]), ([1], [0])), -1),
((([1], [1]), ([1], [1])), 1),
((([1], [0]), ([0], [1])), -1),
((([0], [0]), ([0], [1])), 1),
((([1], [0]), ([0], [0])), 1),
((([1], [1]), ([0], [1])), -1),
# Two qubit Paulis
((([0, 1], [1, 0]), ([1, 0], [0, 1])), 1),
((([0, 1], [1, 0]), ([0, 0], [1, 1])), -1),
((([0, 0], [0, 0]), ([0, 0], [1, 1])), 1),
]

for verified in verified_list:
n_qubits = len(verified[0][0][0])

pauli_one = QermitPauli(
Z_list=verified[0][0][0],
X_list=verified[0][0][1],
qubit_list=[Qubit(i) for i in range(n_qubits)],
)
pauli_two = QermitPauli(
Z_list=verified[0][1][0],
X_list=verified[0][1][1],
qubit_list=[Qubit(i) for i in range(n_qubits)],
)
assert (
QermitPauli.commute_coeff(pauli_one=pauli_one, pauli_two=pauli_two)
== verified[1]
)


def test_noise_model_logical_error_propagation() -> None:
pytket_ciruit = Circuit(2).H(0).CX(0, 1).measure_all()

Expand Down

0 comments on commit b3c29a1

Please sign in to comment.