Skip to content
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
13 changes: 13 additions & 0 deletions qiskit_device_benchmarking/bench_code/mrb/mirror_qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
"""
Mirror QA Experiment class.
"""
from typing import Union, Iterable, Optional, List, Sequence

Check failure on line 15 in qiskit_device_benchmarking/bench_code/mrb/mirror_qa.py

View workflow job for this annotation

GitHub Actions / build

Ruff (F401)

qiskit_device_benchmarking/bench_code/mrb/mirror_qa.py:15:47: F401 `typing.List` imported but unused
import numpy as np
from numpy import pi
from numpy.random import Generator, BitGenerator, SeedSequence
from scipy.stats import entropy
from uncertainties import unumpy as unp
from scipy.spatial.distance import hamming

Check failure on line 21 in qiskit_device_benchmarking/bench_code/mrb/mirror_qa.py

View workflow job for this annotation

GitHub Actions / build

Ruff (F401)

qiskit_device_benchmarking/bench_code/mrb/mirror_qa.py:21:36: F401 `scipy.spatial.distance.hamming` imported but unused

from qiskit.circuit import Instruction
from qiskit.providers.backend import Backend
Expand Down Expand Up @@ -221,6 +221,19 @@
)
self._coupling_map = coupling_map
self._pairs = pairs
self._singles = singles

def _rewrite_string(self, string, index):
'''
Returns a string of equal length, pairs have parity on the lowest numbered qubit
and 0 on the highest.
'''
pair_string = ["0"]*len(string)
for q in self._singles[index]:
pair_string[-1-q] = string[-1-q]
for q0, q1 in self._pairs[index]:
pair_string[-1-min(q0,q1)] = str(int(string[-1-q0]!=string[-1-q1]))
return ''.join(pair_string)

def _process(self, data: np.ndarray):
if self._analyzed_quantity == "Mutual Information":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,19 +262,24 @@ def __init__(
self._analyzed_quantity = analyzed_quantity
self._target_bs = target_bs

def _rewrite_string(string, index):
'''Returns string unchanged. Will be overwritten for Mirror QA'''
return string

def _process(self, data: np.ndarray):
# Arrays to store the y-axis data and uncertainties
y_data = []
y_data_unc = []

for i, circ_result in enumerate(data):
target_bs = self._target_bs[i]
target_bs = self._rewrite_string(self._target_bs[i], i)

# h[k] = proportion of shots that are Hamming distance k away from target bitstring
hamming_dists = np.zeros(self._num_qubits + 1)
success_prob = 0.0
success_prob_unc = 0.0
for bitstring, count in circ_result.items():
bitstring = self._rewrite_string(bitstring, i)
# Compute success probability
if self._analyzed_quantity == "Success Probability":
if bitstring == target_bs:
Expand Down
Loading