Skip to content

Commit

Permalink
4th commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rht committed Jan 6, 2020
1 parent 05bec6d commit da54557
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions pyquil/experiment/_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def _max_weight_operator(ops: Iterable[PauliTerm]) -> Union[None, PauliTerm]:
mapping = dict() # type: Dict[int, str]
for op in ops:
for idx, op_str in op:
assert isinstance(idx, int)
if idx in mapping:
if mapping[idx] != op_str:
return None
Expand Down
10 changes: 7 additions & 3 deletions pyquil/experiment/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def get_meas_qubits(self) -> List[int]:
"""
meas_qubits: Set[int] = set()
for settings in self:
meas_qubits.update(settings[0].out_operator.get_qubits())
meas_qubits.update(cast(List[int], settings[0].out_operator.get_qubits()))
return sorted(meas_qubits)

def get_meas_registers(self, qubits: Optional[Sequence[int]] = None) -> List[int]:
Expand Down Expand Up @@ -377,8 +377,12 @@ def build_setting_memory_map(self, setting: ExperimentSetting) -> Dict[str, List
"""
meas_qubits = self.get_meas_qubits()

in_pt = PauliTerm.from_list([(op, meas_qubits.index(q)) for q, op in setting.in_operator])
out_pt = PauliTerm.from_list([(op, meas_qubits.index(q)) for q, op in setting.out_operator])
in_pt = PauliTerm.from_list(
[(op, meas_qubits.index(cast(int, q))) for q, op in setting.in_operator]
)
out_pt = PauliTerm.from_list(
[(op, meas_qubits.index(cast(int, q))) for q, op in setting.out_operator]
)

preparation_map = pauli_term_to_preparation_memory_map(in_pt)
measurement_map = pauli_term_to_measurement_memory_map(out_pt)
Expand Down
5 changes: 3 additions & 2 deletions pyquil/experiment/_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
##############################################################################

import itertools
from typing import Dict, List, Tuple
from typing import Dict, List, Tuple, cast

import numpy as np

Expand Down Expand Up @@ -102,7 +102,7 @@ def pauli_term_to_euler_memory_map(
gamma_label = f"{prefix}_{suffix_gamma}"

# assume the pauli indices are equivalent to the memory region
memory_size = max(term.get_qubits()) + 1
memory_size = max(cast(List[int], term.get_qubits())) + 1

memory_map = {
alpha_label: [0.0] * memory_size,
Expand All @@ -113,6 +113,7 @@ def pauli_term_to_euler_memory_map(
tuples = {"X": tuple_x, "Y": tuple_y, "Z": tuple_z, "I": tuple_z}

for qubit, operator in term:
assert isinstance(qubit, int)
if operator not in tuples:
raise ValueError(f"Unknown operator {operator}")
memory_map[alpha_label][qubit] = tuples[operator][0]
Expand Down
2 changes: 1 addition & 1 deletion pyquil/experiment/_setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def _pauli_to_product_state(in_state: PauliTerm) -> TensorProductState:
else:
return TensorProductState(
[
_OneQState(label=pauli_label, index=0, qubit=qubit)
_OneQState(label=pauli_label, index=0, qubit=cast(int, qubit))
for qubit, pauli_label in in_state._ops.items()
]
)
Expand Down
1 change: 1 addition & 0 deletions pyquil/simulation/_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def _term_expectation(wf: np.ndarray, term: PauliTerm) -> Any:
# Computes <psi|XYZ..XXZ|psi>
wf2 = wf
for qubit_i, op_str in term._ops.items():
assert isinstance(qubit_i, int)
# Re-use QUANTUM_GATES since it has X, Y, Z
op_mat = QUANTUM_GATES[op_str]
wf2 = targeted_tensordot(gate=op_mat, wf=wf2, wf_target_inds=[qubit_i])
Expand Down
1 change: 1 addition & 0 deletions pyquil/simulation/_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def _term_expectation(wf: np.ndarray, term: PauliTerm, n_qubits: int) -> Any:
# Computes <psi|XYZ..XXZ|psi>
wf2 = wf
for qubit_i, op_str in term._ops.items():
assert isinstance(qubit_i, int)
# Re-use QUANTUM_GATES since it has X, Y, Z
op_mat = QUANTUM_GATES[op_str]
op_mat = lifted_gate_matrix(matrix=op_mat, qubit_inds=[qubit_i], n_qubits=n_qubits)
Expand Down

0 comments on commit da54557

Please sign in to comment.