Skip to content

Commit

Permalink
refactor: Rename cr_params to cr_pulse and cancel_params to cancel_pu…
Browse files Browse the repository at this point in the history
…lse for clarity; update related logic in Experiment class
  • Loading branch information
Akinori Machino committed Dec 28, 2024
1 parent dda7482 commit 21df44d
Showing 1 changed file with 47 additions and 34 deletions.
81 changes: 47 additions & 34 deletions src/qubex/experiment/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@
USER_NOTE_PATH = ".user_note.json"
SYSTEM_NOTE_PATH = ".system_note.json"

RABI_PARAMS = "rabi_params"
STATE_CENTERS = "state_centers"
RABI_PARAMS = "rabi_params"
CR_PARAMS = "cr_params"

HPI_AMPLITUDE = "hpi_amplitude"
HPI_DURATION = 30
Expand Down Expand Up @@ -6478,15 +6479,17 @@ def cr_hamiltonian_tomography(
target_states_0,
plot=plot,
)
vis.display_bloch_sphere(target_states_0)
if plot:
vis.display_bloch_sphere(target_states_0)
fit_1 = fitting.fit_rotation(
effective_time_range,
target_states_1,
plot=plot,
title="CR Hamiltonian tomography",
xlabel="Effective drive time (ns)",
)
vis.display_bloch_sphere(target_states_1)
if plot:
vis.display_bloch_sphere(target_states_1)
Omega_0 = fit_0["Omega"]
Omega_1 = fit_1["Omega"]
Omega = np.concatenate(
Expand Down Expand Up @@ -6536,44 +6539,44 @@ def calibrate_cr_sequence(
interval: int = DEFAULT_INTERVAL,
plot: bool = True,
) -> dict:
cr_params = {
cr_pulse = {
"phase": 0.0,
}
cancel_params = {
cancel_pulse = {
"amplitude": 0.0,
"phase": 0.0,
}
coeffs = defaultdict(list)

def update_params(
tomography_result: dict,
update_cr_params: bool = False,
update_cancel_params: bool = False,
update_cr_pulse: bool = False,
update_cancel_pulse: bool = False,
):
# append coeffs
for key, value in tomography_result["coeffs"].items():
coeffs[key].append(value)

# update cr params
if update_cr_params:
phase = cr_params["phase"]
# update cr pulse
if update_cr_pulse:
phase = cr_pulse["phase"]
phase_diff = tomography_result["cr_phase"]
new_phase = phase + phase_diff
cr_params["phase"] = new_phase
cr_pulse["phase"] = new_phase
print(f"CR phase: {phase:+.6f} -> {new_phase:+.6f}")

# update cancel params
if update_cancel_params:
amplitude = cancel_params["amplitude"]
phase = cancel_params["phase"]
# update cancel pulse
if update_cancel_pulse:
amplitude = cancel_pulse["amplitude"]
phase = cancel_pulse["phase"]
pulse = amplitude * np.exp(1j * phase)
amplitude_diff = tomography_result["cancel_amplitude"]
phase_diff = tomography_result["cancel_phase"]
new_pulse = pulse + amplitude_diff * np.exp(1j * phase_diff)
new_amplitude = np.abs(new_pulse)
new_phase = np.angle(new_pulse)
cancel_params["amplitude"] = new_amplitude
cancel_params["phase"] = new_phase
cancel_pulse["amplitude"] = new_amplitude
cancel_pulse["phase"] = new_phase
print(f"Cancel amplitude: {amplitude:+.6f} -> {new_amplitude:+.6f}")
print(f"Cancel phase: {phase:+.6f} -> {new_phase:+.6f}")

Expand All @@ -6585,17 +6588,17 @@ def update_params(
flattop_range=flattop_range,
cr_amplitude=cr_amplitude,
cr_ramptime=cr_ramptime,
cr_phase=cr_params["phase"],
cancel_amplitude=cancel_params["amplitude"],
cancel_phase=cancel_params["phase"],
cr_phase=cr_pulse["phase"],
cancel_amplitude=cancel_pulse["amplitude"],
cancel_phase=cancel_pulse["phase"],
shots=shots,
interval=interval,
plot=plot,
)
update_params(
step_1,
update_cr_params=True,
update_cancel_params=False,
update_cr_pulse=True,
update_cancel_pulse=False,
)

step_2 = self.cr_hamiltonian_tomography(
Expand All @@ -6604,17 +6607,17 @@ def update_params(
flattop_range=flattop_range,
cr_amplitude=cr_amplitude,
cr_ramptime=cr_ramptime,
cr_phase=cr_params["phase"],
cancel_amplitude=cancel_params["amplitude"],
cancel_phase=cancel_params["phase"],
cr_phase=cr_pulse["phase"],
cancel_amplitude=cancel_pulse["amplitude"],
cancel_phase=cancel_pulse["phase"],
shots=shots,
interval=interval,
plot=plot,
)
update_params(
step_2,
update_cr_params=False,
update_cancel_params=True,
update_cr_pulse=False,
update_cancel_pulse=True,
)

tomography_result = self.cr_hamiltonian_tomography(
Expand All @@ -6623,9 +6626,9 @@ def update_params(
flattop_range=flattop_range,
cr_amplitude=cr_amplitude,
cr_ramptime=cr_ramptime,
cr_phase=cr_params["phase"],
cancel_amplitude=cancel_params["amplitude"],
cancel_phase=cancel_params["phase"],
cr_phase=cr_pulse["phase"],
cancel_amplitude=cancel_pulse["amplitude"],
cancel_phase=cancel_pulse["phase"],
shots=shots,
interval=interval,
plot=plot,
Expand All @@ -6651,13 +6654,23 @@ def update_params(
yaxis_title="Coefficient (MHz)",
xaxis=dict(tickmode="array", tickvals=np.arange(len(value))),
)
fig.show()
if plot:
fig.show()

self._system_note.put(
CR_PARAMS,
{
f"{control_qubit}-{target_qubit}": {
"cr_pulse": cr_pulse,
"cancel_pulse": cancel_pulse,
},
},
)

return {
"cr_params": cr_params,
"cancel_params": cancel_params,
"cr_pulse": cr_pulse,
"cancel_pulse": cancel_pulse,
"hamiltonian_coeffs": hamiltonian_coeffs,
"tomography_result": tomography_result,
}


Expand Down

0 comments on commit 21df44d

Please sign in to comment.