Skip to content

Commit

Permalink
feat: Update flattop_range and cancel amplitude calculations for impr…
Browse files Browse the repository at this point in the history
…oved flexibility; add x180 parameter support in Experiment class
  • Loading branch information
Akinori Machino committed Dec 29, 2024
1 parent c3f88b7 commit 350d5e2
Showing 1 changed file with 39 additions and 13 deletions.
52 changes: 39 additions & 13 deletions src/qubex/experiment/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6546,7 +6546,7 @@ def calibrate_cr_params(
*,
control_qubit: str,
target_qubit: str,
flattop_range: ArrayLike = np.arange(0, 301, 10),
flattop_range: ArrayLike = np.arange(0, 401, 10),
cr_amplitude: float = 1.0,
cr_ramptime: float = 50,
n_iterations: int = 2,
Expand Down Expand Up @@ -6604,11 +6604,10 @@ def update_params(
if i == 1:
start = float(flattop_range[0])
end = float(flattop_range[-1])
duration = float(end - start)
step = float(flattop_range[1] - flattop_range[0])
flattop_range = np.arange(
start,
start + duration * 2,
end,
step * 2,
)

Expand Down Expand Up @@ -6690,12 +6689,15 @@ def update_params(
if plot:
fig.show()

cr_cancel_ratio = cancel_pulse["amplitude"] / cr_pulse["amplitude"]

self._system_note.put(
CR_PARAMS,
{
f"{control_qubit}-{target_qubit}": {
"cr_pulse": cr_pulse,
"cancel_pulse": cancel_pulse,
"cr_cancel_ratio": cr_cancel_ratio,
"ramptime": cr_ramptime,
},
},
Expand All @@ -6704,6 +6706,7 @@ def update_params(
return {
"cr_pulse": cr_pulse,
"cancel_pulse": cancel_pulse,
"cr_cancel_ratio": cr_cancel_ratio,
"hamiltonian_coeffs": hamiltonian_coeffs,
}

Expand All @@ -6715,6 +6718,7 @@ def calibrate_zx90_by_amplitude(
duration: float = 100,
amplitude_range: ArrayLike = np.linspace(0.0, 1.0, 51),
degree: int = 3,
x180: TargetMap[Waveform] | Waveform | None = None,
use_zvalues: bool = False,
shots: int = DEFAULT_SHOTS,
interval: int = DEFAULT_INTERVAL,
Expand All @@ -6729,6 +6733,15 @@ def calibrate_zx90_by_amplitude(
cr_phase = cr_params["cr_pulse"]["phase"]
cancel_amplitude = cr_params["cancel_pulse"]["amplitude"]
cancel_phase = cr_params["cancel_pulse"]["phase"]
cr_cancel_ratio = cancel_amplitude / cr_amplitude

if x180 is None:
if target_qubit in self.drag_pi_pulse:
x180 = self.drag_pi_pulse
else:
x180 = self.pi_pulse
elif isinstance(x180, Waveform):
x180 = {target_qubit: x180}

sweep_result = self.sweep_parameter(
lambda amplitude: CrossResonance(
Expand All @@ -6738,10 +6751,10 @@ def calibrate_zx90_by_amplitude(
cr_duration=duration,
cr_ramptime=cr_ramptime,
cr_phase=cr_phase,
cancel_amplitude=cancel_amplitude * amplitude / cr_amplitude,
cancel_amplitude=amplitude * cr_cancel_ratio,
cancel_phase=cancel_phase,
echo=True,
pi_pulse=self.pi_pulse[target_qubit],
pi_pulse=x180[target_qubit],
),
sweep_range=amplitude_range,
shots=shots,
Expand Down Expand Up @@ -6777,7 +6790,7 @@ def calibrate_zx90_by_amplitude(
"phase": cr_phase,
},
"cancel_pulse": {
"amplitude": cancel_amplitude * amplitude / cr_amplitude,
"amplitude": amplitude * cr_cancel_ratio,
"phase": cancel_phase,
},
},
Expand All @@ -6795,9 +6808,10 @@ def calibrate_zx90_by_duration(
*,
control_qubit: str,
target_qubit: str,
amplitude: float = 1.0,
duration_range: ArrayLike = np.arange(100, 501, 10),
amplitude: float = 0.5,
duration_range: ArrayLike = np.arange(100, 201, 2),
degree: int = 3,
x180: TargetMap[Waveform] | Waveform | None = None,
use_zvalues: bool = False,
shots: int = DEFAULT_SHOTS,
interval: int = DEFAULT_INTERVAL,
Expand All @@ -6812,6 +6826,15 @@ def calibrate_zx90_by_duration(
cr_phase = cr_params["cr_pulse"]["phase"]
cancel_amplitude = cr_params["cancel_pulse"]["amplitude"]
cancel_phase = cr_params["cancel_pulse"]["phase"]
cr_cancel_ratio = cancel_amplitude / cr_amplitude

if x180 is None:
if target_qubit in self.drag_pi_pulse:
x180 = self.drag_pi_pulse
else:
x180 = self.pi_pulse
elif isinstance(x180, Waveform):
x180 = {target_qubit: x180}

sweep_result = self.sweep_parameter(
lambda duration: CrossResonance(
Expand All @@ -6821,10 +6844,10 @@ def calibrate_zx90_by_duration(
cr_duration=duration,
cr_ramptime=cr_ramptime,
cr_phase=cr_phase,
cancel_amplitude=cancel_amplitude * amplitude / cr_amplitude,
cancel_amplitude=amplitude * cr_cancel_ratio,
cancel_phase=cancel_phase,
echo=True,
pi_pulse=self.pi_pulse[target_qubit],
pi_pulse=x180[target_qubit],
),
sweep_range=duration_range,
shots=shots,
Expand Down Expand Up @@ -6860,7 +6883,7 @@ def calibrate_zx90_by_duration(
"phase": cr_phase,
},
"cancel_pulse": {
"amplitude": cancel_amplitude * amplitude / cr_amplitude,
"amplitude": amplitude * cr_cancel_ratio,
"phase": cancel_phase,
},
},
Expand Down Expand Up @@ -6890,7 +6913,10 @@ def zx90(
cr_params = self._system_note.get(CR_PARAMS)[cr_label]

if x180 is None:
x180 = self.pi_pulse
if target_qubit in self.drag_pi_pulse:
x180 = self.drag_pi_pulse
else:
x180 = self.pi_pulse
elif isinstance(x180, Waveform):
x180 = {target_qubit: x180}

Expand All @@ -6911,7 +6937,7 @@ def zx90(
cancel_amplitude=cancel_amplitude or cr_params["cancel_pulse"]["amplitude"],
cancel_phase=cancel_phase or cr_params["cancel_pulse"]["phase"],
echo=echo,
pi_pulse=self.pi_pulse[target_qubit],
pi_pulse=x180[target_qubit],
)


Expand Down

0 comments on commit 350d5e2

Please sign in to comment.