Skip to content

Commit

Permalink
feat: Rename execute_cr to execute_cr_sequence and add calibrate_cr_s…
Browse files Browse the repository at this point in the history
…equence method for improved control sequence calibration
  • Loading branch information
Akinori Machino committed Dec 27, 2024
1 parent 6dfeae1 commit eda71b1
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 36 deletions.
60 changes: 30 additions & 30 deletions docs/examples/simulator/8_cr_calibration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"\n",
"cr_duration = 1000\n",
"cr_amplitude = 0.2\n",
"cr_ramp = 50\n",
"cr_ramptime = 50\n",
"cr_phase = 0.25 * np.pi\n",
"\n",
"crosstalk_ratio = 0.01\n",
Expand Down Expand Up @@ -154,7 +154,7 @@
" target_drive_frequency: float,\n",
" cr_amplitude: float,\n",
" cr_duration: float,\n",
" cr_ramp: float,\n",
" cr_ramptime: float,\n",
" cr_phase: float,\n",
" crosstalk_amplitude: float = 0.0,\n",
" crosstalk_phase: float = 0.0,\n",
Expand All @@ -165,19 +165,19 @@
" cr_waveform = qp.FlatTop(\n",
" duration=cr_duration,\n",
" amplitude=2 * np.pi * cr_amplitude,\n",
" tau=cr_ramp,\n",
" tau=cr_ramptime,\n",
" phase_shift=cr_phase,\n",
" )\n",
" cancel_waveform = qp.FlatTop(\n",
" duration=cr_duration,\n",
" amplitude=2 * np.pi * cancel_amplitude,\n",
" tau=cr_ramp,\n",
" tau=cr_ramptime,\n",
" phase_shift=cancel_phase,\n",
" )\n",
" crosstalk_waveform = qp.FlatTop(\n",
" duration=cr_duration,\n",
" amplitude=2 * np.pi * crosstalk_amplitude,\n",
" tau=cr_ramp,\n",
" tau=cr_ramptime,\n",
" phase_shift=crosstalk_phase,\n",
" )\n",
" with qp.PulseSchedule(\n",
Expand Down Expand Up @@ -244,7 +244,7 @@
" target_drive_frequency: float,\n",
" cr_amplitude: float,\n",
" cr_duration: float,\n",
" cr_ramp: float,\n",
" cr_ramptime: float,\n",
" cr_phase: float,\n",
" crosstalk_amplitude: float = 0.0,\n",
" crosstalk_phase: float = 0.0,\n",
Expand All @@ -260,7 +260,7 @@
" target_drive_frequency=target_drive_frequency,\n",
" cr_amplitude=cr_amplitude,\n",
" cr_duration=cr_duration,\n",
" cr_ramp=cr_ramp,\n",
" cr_ramptime=cr_ramptime,\n",
" cr_phase=cr_phase,\n",
" crosstalk_amplitude=crosstalk_amplitude,\n",
" crosstalk_phase=crosstalk_phase,\n",
Expand Down Expand Up @@ -298,7 +298,7 @@
" target_drive_frequency=target_drive_frequency,\n",
" cr_amplitude=cr_amplitude,\n",
" cr_duration=cr_duration,\n",
" cr_ramp=cr_ramp,\n",
" cr_ramptime=cr_ramptime,\n",
" cr_phase=cr_phase,\n",
" crosstalk_amplitude=crosstalk_amplitude,\n",
" crosstalk_phase=crosstalk_phase,\n",
Expand All @@ -318,7 +318,7 @@
" target_drive_frequency=target_drive_frequency,\n",
" cr_amplitude=cr_amplitude,\n",
" cr_duration=cr_duration,\n",
" cr_ramp=cr_ramp,\n",
" cr_ramptime=cr_ramptime,\n",
" cr_phase=cr_phase,\n",
" crosstalk_amplitude=crosstalk_amplitude,\n",
" crosstalk_phase=crosstalk_phase,\n",
Expand All @@ -338,7 +338,7 @@
" target_drive_frequency: float,\n",
" cr_amplitude: float,\n",
" cr_duration: float,\n",
" cr_ramp: float,\n",
" cr_ramptime: float,\n",
" cr_phase: float,\n",
" cross_talk_amplitude: float = 0.0,\n",
" cross_talk_phase: float = 0.0,\n",
Expand All @@ -352,7 +352,7 @@
" target_drive_frequency=target_drive_frequency,\n",
" cr_amplitude=cr_amplitude,\n",
" cr_duration=cr_duration,\n",
" cr_ramp=cr_ramp,\n",
" cr_ramptime=cr_ramptime,\n",
" cr_phase=cr_phase,\n",
" crosstalk_amplitude=cross_talk_amplitude,\n",
" crosstalk_phase=cross_talk_phase,\n",
Expand All @@ -367,7 +367,7 @@
" target_drive_frequency=target_drive_frequency,\n",
" cr_amplitude=cr_amplitude,\n",
" cr_duration=cr_duration,\n",
" cr_ramp=cr_ramp,\n",
" cr_ramptime=cr_ramptime,\n",
" cr_phase=cr_phase,\n",
" crosstalk_amplitude=cross_talk_amplitude,\n",
" crosstalk_phase=cross_talk_phase,\n",
Expand All @@ -382,8 +382,8 @@
" vectors_0 = result_0.get_bloch_vectors(target_qubit.label)\n",
" vectors_1 = result_1.get_bloch_vectors(target_qubit.label)\n",
"\n",
" indices = (times >= cr_ramp) & (times < times[-1] - cr_ramp)\n",
" times_ = times[indices] - cr_ramp * 0.5\n",
" indices = (times >= cr_ramptime) & (times < times[-1] - cr_ramptime)\n",
" times_ = times[indices] - cr_ramptime * 0.5\n",
" vectors_0_ = vectors_0[indices]\n",
" vectors_1_ = vectors_1[indices]\n",
"\n",
Expand Down Expand Up @@ -441,7 +441,7 @@
" target_drive_frequency=target_drive_frequency,\n",
" cr_amplitude=cr_amplitude,\n",
" cr_duration=cr_duration,\n",
" cr_ramp=cr_ramp,\n",
" cr_ramptime=cr_ramptime,\n",
" cr_phase=cr_phase,\n",
" cross_talk_amplitude=crosstalk_amplitude,\n",
" cross_talk_phase=crosstalk_phase,\n",
Expand Down Expand Up @@ -474,7 +474,7 @@
" target_drive_frequency=target_drive_frequency,\n",
" cr_amplitude=cr_amplitude,\n",
" cr_duration=cr_duration,\n",
" cr_ramp=cr_ramp,\n",
" cr_ramptime=cr_ramptime,\n",
" cr_phase=cr_phase + cr_phase_est,\n",
" cross_talk_amplitude=crosstalk_amplitude,\n",
" cross_talk_phase=crosstalk_phase,\n",
Expand Down Expand Up @@ -509,7 +509,7 @@
" target_drive_frequency=target_drive_frequency,\n",
" cr_amplitude=cr_amplitude,\n",
" cr_duration=cr_duration,\n",
" cr_ramp=cr_ramp,\n",
" cr_ramptime=cr_ramptime,\n",
" cr_phase=cr_phase + cr_phase_est,\n",
" cross_talk_amplitude=crosstalk_amplitude,\n",
" cross_talk_phase=crosstalk_phase,\n",
Expand All @@ -532,7 +532,7 @@
" target_drive_frequency=target_drive_frequency,\n",
" cr_amplitude=cr_amplitude,\n",
" cr_duration=cr_duration,\n",
" cr_ramp=cr_ramp,\n",
" cr_ramptime=cr_ramptime,\n",
" cr_phase=cr_phase + cr_phase_est,\n",
" crosstalk_amplitude=crosstalk_amplitude,\n",
" crosstalk_phase=crosstalk_phase,\n",
Expand Down Expand Up @@ -567,7 +567,7 @@
" target_drive_frequency=target_drive_frequency,\n",
" cr_amplitude=cr_amplitude,\n",
" cr_duration=cr_duration,\n",
" cr_ramp=cr_ramp,\n",
" cr_ramptime=cr_ramp,\n",
" cr_phase=cr_phase,\n",
" crosstalk_amplitude=crosstalk_amplitude,\n",
" crosstalk_phase=crosstalk_phase,\n",
Expand All @@ -583,7 +583,7 @@
" target_drive_frequency=target_drive_frequency,\n",
" cr_amplitude=cr_amplitude,\n",
" cr_duration=cr_duration,\n",
" cr_ramp=cr_ramp,\n",
" cr_ramptime=cr_ramp,\n",
" cr_phase=cr_phase,\n",
" crosstalk_amplitude=crosstalk_amplitude,\n",
" crosstalk_phase=crosstalk_phase,\n",
Expand Down Expand Up @@ -621,7 +621,7 @@
" target_drive_frequency=target_qubit_frequency,\n",
" cr_amplitude=cr_amplitude,\n",
" cr_duration=duration,\n",
" cr_ramp=cr_ramp,\n",
" cr_ramp=cr_ramptime,\n",
" cr_phase=cr_phase + cr_phase_est,\n",
" cancel_amplitude=cancel_amplitude_est,\n",
" cancel_phase=cancel_phase_est,\n",
Expand Down Expand Up @@ -677,7 +677,7 @@
" target_drive_frequency=target_qubit_frequency,\n",
" cr_amplitude=cr_amplitude,\n",
" cr_duration=cr_duration_est,\n",
" cr_ramp=cr_ramp,\n",
" cr_ramp=cr_ramptime,\n",
" cr_phase=cr_phase + cr_phase_est,\n",
" cancel_amplitude=cancel_amplitude_est,\n",
" cancel_phase=cancel_phase_est,\n",
Expand All @@ -695,7 +695,7 @@
" target_drive_frequency=target_drive_frequency,\n",
" cr_amplitude=cr_amplitude,\n",
" cr_duration=cr_duration_est,\n",
" cr_ramp=cr_ramp,\n",
" cr_ramptime=cr_ramptime,\n",
" cr_phase=cr_phase + cr_phase_est,\n",
" crosstalk_amplitude=crosstalk_amplitude,\n",
" crosstalk_phase=crosstalk_phase,\n",
Expand All @@ -718,7 +718,7 @@
" target_drive_frequency=target_drive_frequency,\n",
" cr_duration=cr_duration_est,\n",
" cr_amplitude=cr_amplitude,\n",
" cr_ramp=cr_ramp,\n",
" cr_ramptime=cr_ramptime,\n",
" cr_phase=cr_phase + cr_phase_est,\n",
" crosstalk_amplitude=crosstalk_amplitude,\n",
" crosstalk_phase=crosstalk_phase,\n",
Expand Down Expand Up @@ -748,7 +748,7 @@
" target_drive_frequency=target_drive_frequency,\n",
" cr_amplitude=cr_amplitude,\n",
" cr_duration=cr_duration_est,\n",
" cr_ramp=cr_ramp,\n",
" cr_ramptime=cr_ramptime,\n",
" cr_phase=cr_phase,\n",
" crosstalk_amplitude=crosstalk_amplitude,\n",
" crosstalk_phase=crosstalk_phase,\n",
Expand All @@ -764,7 +764,7 @@
" target_drive_frequency=target_drive_frequency,\n",
" cr_amplitude=cr_amplitude,\n",
" cr_duration=cr_duration_est,\n",
" cr_ramp=cr_ramp,\n",
" cr_ramptime=cr_ramptime,\n",
" cr_phase=cr_phase,\n",
" crosstalk_amplitude=crosstalk_amplitude,\n",
" crosstalk_phase=crosstalk_phase,\n",
Expand Down Expand Up @@ -884,7 +884,7 @@
" target_drive_frequency=target_drive_frequency,\n",
" cr_amplitude=cr_amplitude_opt,\n",
" cr_duration=cr_duration_est,\n",
" cr_ramp=cr_ramp,\n",
" cr_ramptime=cr_ramptime,\n",
" cr_phase=cr_phase_opt,\n",
" crosstalk_amplitude=crosstalk_amplitude,\n",
" crosstalk_phase=crosstalk_phase,\n",
Expand All @@ -907,7 +907,7 @@
" target_drive_frequency=target_drive_frequency,\n",
" cr_amplitude=cr_amplitude_opt,\n",
" cr_duration=cr_duration_est,\n",
" cr_ramp=cr_ramp,\n",
" cr_ramptime=cr_ramptime,\n",
" cr_phase=cr_phase_opt,\n",
" crosstalk_amplitude=crosstalk_amplitude,\n",
" crosstalk_phase=crosstalk_phase,\n",
Expand All @@ -930,7 +930,7 @@
" target_drive_frequency=target_drive_frequency,\n",
" cr_amplitude=cr_amplitude_opt,\n",
" cr_duration=cr_duration_est,\n",
" cr_ramp=cr_ramp,\n",
" cr_ramptime=cr_ramptime,\n",
" cr_phase=cr_phase_opt,\n",
" crosstalk_amplitude=crosstalk_amplitude,\n",
" crosstalk_phase=crosstalk_phase,\n",
Expand All @@ -947,7 +947,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "3.9.18",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand Down
80 changes: 74 additions & 6 deletions src/qubex/experiment/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6370,7 +6370,7 @@ def measure_population_dynamics(

return result_pops, result_errs

def execute_cr(
def execute_cr_sequence(
self,
control_qubit: str,
target_qubit: str,
Expand Down Expand Up @@ -6439,7 +6439,7 @@ def cr_hamiltonian_tomography(
) -> dict:
time_range = np.array(time_range)

result_0 = self.execute_cr(
result_0 = self.execute_cr_sequence(
time_range=time_range,
control_qubit=control_qubit,
target_qubit=target_qubit,
Expand All @@ -6453,7 +6453,7 @@ def cr_hamiltonian_tomography(
shots=shots,
interval=interval,
)
result_1 = self.execute_cr(
result_1 = self.execute_cr_sequence(
time_range=time_range,
control_qubit=control_qubit,
target_qubit=target_qubit,
Expand All @@ -6471,18 +6471,18 @@ def cr_hamiltonian_tomography(
indices = (time_range >= cr_ramptime) & (
time_range < time_range[-1] - cr_ramptime
)
times = time_range[indices] - cr_ramptime * 0.5
flat_time_range = time_range[indices] - cr_ramptime
target_states_0 = result_0["target_states"][indices]
target_states_1 = result_1["target_states"][indices]

fit_0 = fitting.fit_rotation(
times,
flat_time_range,
target_states_0,
plot=plot,
)
vis.display_bloch_sphere(target_states_0)
fit_1 = fitting.fit_rotation(
times,
flat_time_range,
target_states_1,
plot=plot,
)
Expand Down Expand Up @@ -6523,6 +6523,74 @@ def cr_hamiltonian_tomography(
"cancel_phase_est": cancel_phase_est,
}

def calibrate_cr_sequence(
self,
control_qubit: str,
target_qubit: str,
*,
time_range: ArrayLike = np.arange(100, 401, 20),
cr_amplitude: float = 1.0,
cr_ramptime: float = 50,
n_iteraions: int = 2,
shots: int = DEFAULT_SHOTS,
interval: int = DEFAULT_INTERVAL,
) -> dict:
cr_phase = 0.0
cancel_amplitude = 0.0
cancel_phase = 0.0

for i in range(n_iteraions):
print(f"Iteration {i + 1}/{n_iteraions}")
step_1 = self.cr_hamiltonian_tomography(
control_qubit=control_qubit,
target_qubit=target_qubit,
time_range=time_range,
cr_amplitude=cr_amplitude,
cr_ramptime=cr_ramptime,
cr_phase=cr_phase,
cancel_amplitude=cancel_amplitude,
cancel_phase=cancel_phase,
shots=shots,
interval=interval,
plot=True,
)
cr_phase = step_1["cr_phase_est"]
print(f"cr_phase : {cr_phase:+.6f} rad")

step_2 = self.cr_hamiltonian_tomography(
control_qubit=control_qubit,
target_qubit=target_qubit,
time_range=time_range,
cr_amplitude=cr_amplitude,
cr_ramptime=cr_ramptime,
cr_phase=cr_phase,
cancel_amplitude=cancel_amplitude,
cancel_phase=cancel_phase,
shots=shots,
interval=interval,
plot=True,
)

cancel_amplitude = step_2["cancel_amplitude_est"]
cancel_phase = step_2["cancel_phase_est"]
print(f"cancel_amplitude : {cancel_amplitude:+.6f}")
print(f"cancel_phase : {cancel_phase:+.6f} rad")

result = self.cr_hamiltonian_tomography(
control_qubit=control_qubit,
target_qubit=target_qubit,
time_range=time_range,
cr_amplitude=cr_amplitude,
cr_ramptime=cr_ramptime,
cr_phase=cr_phase,
cancel_amplitude=cancel_amplitude,
cancel_phase=cancel_phase,
shots=shots,
interval=interval,
plot=True,
)
return result


class ExperimentUtil:
@staticmethod
Expand Down

0 comments on commit eda71b1

Please sign in to comment.