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

Address nits in Single Qubit Randomized Benchmarking benchmarks: #5885

Merged
merged 2 commits into from
Sep 21, 2022
Merged
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
13 changes: 8 additions & 5 deletions benchmarks/randomized_benchmarking.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import List
from typing import List, Sequence
import functools
import numpy as np
import cirq
from cirq.experiments.qubit_characterizations import _single_qubit_cliffords, _find_inv_matrix


def dot(*args: np.ndarray) -> np.ndarray:
def dot(args: Sequence[np.ndarray]) -> np.ndarray:
return functools.reduce(np.dot, args)


Expand All @@ -39,7 +39,10 @@ class SingleQubitRandomizedBenchmarking:

def setup(self, *_):
self.sq_xz_matrices = np.array(
[dot(*[cirq.unitary(c) for c in group]) for group in _single_qubit_cliffords().c1_in_xz]
[
dot([cirq.unitary(c) for c in reversed(group)])
for group in _single_qubit_cliffords().c1_in_xz
]
)
self.sq_xz_cliffords: List[cirq.Gate] = [
cirq.PhasedXZGate.from_matrix(mat) for mat in self.sq_xz_matrices
Expand All @@ -48,8 +51,8 @@ def setup(self, *_):
def _get_op_grid(self, qubits: List[cirq.Qid], depth: int) -> List[List[cirq.Operation]]:
op_grid: List[List[cirq.Operation]] = []
for q in qubits:
gate_ids = list(np.random.choice(len(self.sq_xz_cliffords), depth))
idx = _find_inv_matrix(dot(*self.sq_xz_matrices[gate_ids]), self.sq_xz_matrices)
gate_ids = np.random.choice(len(self.sq_xz_cliffords), depth)
idx = _find_inv_matrix(dot(self.sq_xz_matrices[gate_ids][::-1]), self.sq_xz_matrices)
op_sequence = [self.sq_xz_cliffords[id].on(q) for id in gate_ids]
op_sequence.append(self.sq_xz_cliffords[idx].on(q))
op_grid.append(op_sequence)
Expand Down