Skip to content

Commit

Permalink
Merge 7786882 into 2f450c1
Browse files Browse the repository at this point in the history
  • Loading branch information
gribeill committed Apr 16, 2020
2 parents 2f450c1 + 7786882 commit f200634
Show file tree
Hide file tree
Showing 9 changed files with 868 additions and 504 deletions.
45 changes: 34 additions & 11 deletions QGL/BasicSequences/RB.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from ..PulsePrimitives import *
from ..Cliffords import *
from ..Compiler import compile_to_hardware
from ..PulseSequencePlotter import plot_pulse_files
from ..Cliffords import clifford_seq, clifford_mat, inverse_clifford
from ..tools.clifford_tools import clifford_mat, inverse_clifford
from .helpers import create_cal_seqs, cal_descriptor
from ..config import logger

import os
from csv import reader
Expand Down Expand Up @@ -87,7 +89,7 @@ def create_RB_seqs(numQubits,

return seqs

def SingleQubitRB(qubit, seqs, purity=False, showPlot=False, add_cals=True):
def SingleQubitRB(qubit, seqs, cliff_type='std', purity=False, showPlot=False, add_cals=True):
"""
Single qubit randomized benchmarking using 90 and 180 generators.
Expand Down Expand Up @@ -119,12 +121,16 @@ def SingleQubitRB(qubit, seqs, purity=False, showPlot=False, add_cals=True):
'/path/to/exp/exp-meta.json'
"""

if cliff_type.upper() not in clifford_map.keys():
raise ValueError(f"Unknown clifford type: must be one of {clifford.map.keys()}.")

clifford = clifford_map[cliff_type.upper()]

seqsBis = []
op = [Id(qubit, length=0), Y90m(qubit), X90(qubit)]
for ct in range(3 if purity else 1):
for seq in seqs:
seqsBis.append(reduce(operator.add, [clifford_seq(c, qubit)
for c in seq]))
seqsBis.append([clifford(qubit,c) for c in seq])
#append tomography pulse to measure purity
seqsBis[-1].append(op[ct])
#append measurement
Expand All @@ -148,7 +154,7 @@ def SingleQubitRB(qubit, seqs, purity=False, showPlot=False, add_cals=True):
plot_pulse_files(metafile)
return metafile

def SingleQubitLeakageRB(qubit, seqs, pi2args, showPlot=False):
def SingleQubitLeakageRB(qubit, seqs, pi2args, cliff_type='std', showPlot=False):
"""
Single qubit randomized benchmarking using 90 and 180 generators to
measure leakage outside the qubit subspace.
Expand Down Expand Up @@ -182,9 +188,14 @@ def SingleQubitLeakageRB(qubit, seqs, pi2args, showPlot=False):
'/path/to/exp/exp-meta.json'
"""

if cliff_type.upper() not in clifford_map.keys():
raise ValueError(f"Unknown clifford type: must be one of {clifford.map.keys()}.")

clifford = clifford_map[cliff_type.upper()]

seqsBis = []
for seq in seqs:
combined_seq = reduce(operator.add, [clifford_seq(c, qubit) for c in seq])
combined_seq = [clifford(qubit, c) for c in seq]

# Append sequence with tomography ids and measurement
seqsBis.append(combined_seq + [Id(qubit), Id(qubit), MEAS(qubit)])
Expand Down Expand Up @@ -219,7 +230,7 @@ def SingleQubitLeakageRB(qubit, seqs, pi2args, showPlot=False):



def TwoQubitRB(q1, q2, seqs, showPlot=False, suffix="", add_cals=True):
def TwoQubitRB(q1, q2, seqs, meas_qubits='all', cliff_type='std', showPlot=False, suffix="", add_cals=True):
"""
Two qubit randomized benchmarking using 90 and 180 single qubit generators
and ZX90.
Expand Down Expand Up @@ -253,14 +264,18 @@ def TwoQubitRB(q1, q2, seqs, showPlot=False, suffix="", add_cals=True):
>>> mf
'/path/to/exp/exp-meta.json'
"""

seqsBis = []
for seq in seqs:
seqsBis.append(reduce(operator.add, [clifford_seq(c, q2, q1)
seqsBis.append(reduce(operator.add, [TwoQubitClifford(q2, q1, c, kind=cliff_type)
for c in seq]))

#Add the measurement to all sequences
for seq in seqsBis:
seq.append(MEAS(q1) * MEAS(q2))
if meas_qubits.upper() == "ALL":
seq.append(MEAS(q1) * MEAS(q2))
else:
seq.append(reduce(operator.mul, [MEAS(q) for q in meas_qubits]))

axis_descriptor = [{
'name': 'length',
Expand All @@ -280,7 +295,7 @@ def TwoQubitRB(q1, q2, seqs, showPlot=False, suffix="", add_cals=True):
plot_pulse_files(metafile)
return metafile

def TwoQubitLeakageRB(q1, q2, meas_qubit, seqs, pi2args, showPlot=False):
def TwoQubitLeakageRB(q1, q2, meas_qubit, seqs, pi2args, cliff_type='std', showPlot=False):
"""
Two qubit randomized benchmarking using 90 and 180 single qubit generators
and ZX90 to measure leakage outside the qubit subspace. See https://
Expand Down Expand Up @@ -319,7 +334,7 @@ def TwoQubitLeakageRB(q1, q2, meas_qubit, seqs, pi2args, showPlot=False):
"""
seqsBis = []
for seq in seqs:
combined_seq = reduce(operator.add, [clifford_seq(c, q2, q1) for c in seq])
combined_seq = reduce(operator.add, [TwoQubitClifford(q2, q1, c, kind=cliff_type) for c in seq])

# Append sequence with tomography ids and measurement
seqsBis.append(combined_seq + [Id(meas_qubit), Id(meas_qubit), MEAS(meas_qubit)])
Expand Down Expand Up @@ -385,6 +400,10 @@ def SingleQubitRB_AC(qubit, seqs, purity=False, showPlot=False, add_cals=True):
>>> mf
'/path/to/exp/exp-meta.json'
"""

logger.warning("This function is deprecated and may be removed in a future release of QGL! " +
"Use `SingleQubitRB` with the `cliff_type` keyword argument instead.")

seqsBis = []
op = [Id(qubit, length=0), Y90m(qubit), X90(qubit)]
for ct in range(3 if purity else 1):
Expand Down Expand Up @@ -453,6 +472,10 @@ def SingleQubitRB_DiAC(qubit,
>>> mf
'/path/to/exp/exp-meta.json'
"""

logger.warning("This function is deprecated and may be removed in a future release of QGL! " +
"Use `SingleQubitRB` with the `cliff_type` keyword argument instead.")

seqsBis = []
op = [Id(qubit, length=0), Y90m(qubit), X90(qubit)]
for ct in range(3 if purity else 1):
Expand Down

0 comments on commit f200634

Please sign in to comment.