Skip to content

Commit

Permalink
chore: remove need for flag by delaying instruction pruning
Browse files Browse the repository at this point in the history
  • Loading branch information
jselig-rigetti committed Oct 25, 2023
1 parent 6927708 commit 1b2b431
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 25 deletions.
4 changes: 2 additions & 2 deletions docs/examples/qubit_spectroscopy_t1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"stop_time = 60 * MICROSECOND\n",
"num_points = 15\n",
"times = np.linspace(0, stop_time, num_points)\n",
"expt = generate_t1_experiments(qubits, times, is_qvm='qvm' in qc.name)\n",
"expt = generate_t1_experiments(qubits, times)\n",
"print(expt)"
]
},
Expand Down Expand Up @@ -219,7 +219,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.11"
"version": "3.8.15"
}
},
"nbformat": 4,
Expand Down
6 changes: 3 additions & 3 deletions docs/examples/qubit_spectroscopy_t2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"num_points = 65\n",
"times = np.linspace(0, stop_time, num_points)\n",
"detune = 1 * MHZ\n",
"t2_star_expt = generate_t2_star_experiments(qubits, times, detune, is_qvm='qvm' in qc.name)"
"t2_star_expt = generate_t2_star_experiments(qubits, times, detune)"
]
},
{
Expand Down Expand Up @@ -218,7 +218,7 @@
"metadata": {},
"outputs": [],
"source": [
"t2_echo_expt = generate_t2_echo_experiments(qubits, times, detune, is_qvm='qvm' in qc.name)"
"t2_echo_expt = generate_t2_echo_experiments(qubits, times, detune)"
]
},
{
Expand Down Expand Up @@ -313,7 +313,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.11"
"version": "3.8.15"
}
},
"nbformat": 4,
Expand Down
9 changes: 9 additions & 0 deletions forest/benchmarking/observable_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from pyquil import Program
from pyquil.api import QuantumComputer
from pyquil.gates import RX, RZ, MEASURE, RESET
from pyquil.quilbase import Delay
from pyquil.paulis import PauliTerm, sI, is_identity

from forest.benchmarking.compilation import basic_compile, _RY
Expand Down Expand Up @@ -900,6 +901,14 @@ def estimate_observables(qc: QuantumComputer, obs_expt: ObservablesExperiment,
programs, meas_qubits = generate_experiment_programs(obs_expt, active_reset)
for prog, meas_qs, settings in zip(tqdm(programs, disable=not show_progress_bar), meas_qubits,
obs_expt):
# Remove `Delay` instructions for qvm-bound executions,
# where Quil-T instructions are not supported.
if 'qvm' in qc.name:
prog.instructions = [
instruction for instruction in prog.instructions
if not isinstance(instruction, Delay)
]

results = qc.run_symmetrized_readout(prog, num_shots, symm_type, meas_qs or [0])

for setting in settings:
Expand Down
29 changes: 9 additions & 20 deletions forest/benchmarking/qubit_spectroscopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def get_stats_by_qubit(expt_results: List[List[ExperimentResult]]) \
# ==================================================================================================


def generate_t1_experiments(qubits: Sequence[int], times: Sequence[float], is_qvm: bool = False) \
def generate_t1_experiments(qubits: Sequence[int], times: Sequence[float]) \
-> List[ObservablesExperiment]:
"""
Return a ObservablesExperiment containing programs which constitute a t1 experiment to
Expand All @@ -95,8 +95,6 @@ def generate_t1_experiments(qubits: Sequence[int], times: Sequence[float], is_qv
:param qubits: list of qubits to measure.
:param times: The times at which to measure, given in seconds. Each time is rounded to the
nearest .1 microseconds.
:param is_qvm: If this experiment is destined to run on a QVM. If so,
PRAGMA DELAY are not added.
:return: ObservablesExperiments which will measure the decay of each qubit after
initialization to the 1 state and delay of t seconds for each t in times.
"""
Expand All @@ -106,8 +104,7 @@ def generate_t1_experiments(qubits: Sequence[int], times: Sequence[float], is_qv
program = Program()
settings = []
for q in qubits:
if not is_qvm:
program += Delay(frames=[], qubits=[q], duration=t)
program += Delay(frames=[], qubits=[q], duration=t)
settings.append(ExperimentSetting(minusZ(q), PauliTerm('Z', q)))

expts.append(ObservablesExperiment([settings], program))
Expand Down Expand Up @@ -186,7 +183,7 @@ def do_t1_or_t2(qc: QuantumComputer, qubits: Sequence[int], times: Sequence[floa
else:
raise ValueError('Kind must be one of \'t1\', \'t2_star\', or \'t2_echo\'.')

expts = gen_method(qubits, times, is_qvm='qvm' in qc.name)
expts = gen_method(qubits, times)
results = acquire_qubit_spectroscopy_data(qc, expts, num_shots, show_progress_bar)
stats = get_stats_by_qubit(results)
decay_time_by_qubit = {}
Expand All @@ -203,7 +200,7 @@ def do_t1_or_t2(qc: QuantumComputer, qubits: Sequence[int], times: Sequence[floa
# T2 star and T2 echo functions
# ==================================================================================================
def generate_t2_star_experiments(qubits: Sequence[int], times: Sequence[float],
detuning: float = 1e6, is_qvm: bool = False) -> List[ObservablesExperiment]:
detuning: float = 1e6) -> List[ObservablesExperiment]:
"""
Return ObservablesExperiments containing programs which constitute a T2 star experiment to
measure the T2 star coherence decay time for each qubit in qubits.
Expand All @@ -218,8 +215,6 @@ def generate_t2_star_experiments(qubits: Sequence[int], times: Sequence[float],
:param times: the times at which to measure, given in seconds. Each time is rounded to the
nearest .1 microseconds.
:param detuning: The additional detuning frequency about the z axis in Hz.
:param is_qvm: If this experiment is destined to run on a QVM. If so,
PRAGMA DELAY are not added.
:return: ObservablesExperiments which can be run to acquire an estimate of T2* for each qubit
"""
expts = []
Expand All @@ -228,8 +223,7 @@ def generate_t2_star_experiments(qubits: Sequence[int], times: Sequence[float],
program = Program()
settings = []
for q in qubits:
if not is_qvm:
program += Delay(frames=[], qubits=[q], duration=t)
program += Delay(frames=[], qubits=[q], duration=t)
program += RZ(2 * pi * t * detuning, q)
settings.append(ExperimentSetting(minusY(q), PauliTerm('Y', q)))

Expand All @@ -239,7 +233,7 @@ def generate_t2_star_experiments(qubits: Sequence[int], times: Sequence[float],


def generate_t2_echo_experiments(qubits: Sequence[int], times: Sequence[float],
detuning: float = 1e6, is_qvm: bool = False) -> List[ObservablesExperiment]:
detuning: float = 1e6) -> List[ObservablesExperiment]:
"""
Return ObservablesExperiments containing programs which constitute a T2 echo experiment to
measure the T2 echo coherence decay time.
Expand All @@ -261,8 +255,6 @@ def generate_t2_echo_experiments(qubits: Sequence[int], times: Sequence[float],
:param times: the times at which to measure, given in seconds. Each time is rounded to the
nearest .1 microseconds.
:param detuning: The additional detuning frequency about the z axis.
:param is_qvm: If this experiment is destined to run on a QVM. If so,
PRAGMA DELAY are not added.
:return: ObservablesExperiments which can be run to acquire an estimate of T2 for each qubit.
"""
expts = []
Expand All @@ -272,12 +264,9 @@ def generate_t2_echo_experiments(qubits: Sequence[int], times: Sequence[float],
program = Program()
settings = []
for q in qubits:
if not is_qvm:
half_delay += Delay(frames=[], qubits=[q], duration=half_time)
# echo
program += [half_delay, RY(pi, q), half_delay]
else:
program += RY(pi, q)
half_delay += Delay(frames=[], qubits=[q], duration=half_time)
# echo
program += [half_delay, RY(pi, q), half_delay]
# apply detuning
program += RZ(2 * pi * t * detuning, q)
settings.append(ExperimentSetting(minusY(q), PauliTerm('Y', q)))
Expand Down

0 comments on commit 1b2b431

Please sign in to comment.