Skip to content

Commit

Permalink
CR fixes (#266)
Browse files Browse the repository at this point in the history
* fix ports for cancel pulse

* change port and cluster name

* add manual mixer calibration and automatic mixer calibration

* change scripts' numbers and import configuration

* formatting
  • Loading branch information
MichalGQM authored Nov 26, 2024
1 parent 53302b9 commit a1225b9
Show file tree
Hide file tree
Showing 38 changed files with 197 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
"""
MIXER CALIBRATION
The program is designed to play a continuous single tone to calibrate an IQ mixer. To do this, connect the mixer's
output to a spectrum analyzer. Adjustments for the DC offsets, gain, and phase must be made manually.
If you have access to the API for retrieving data from the spectrum analyzer, you can utilize the commented lines below
to semi-automate the process.
Before proceeding to the next node, take the following steps:
- Update the DC offsets in the configuration at: config/controllers/"con1"/analog_outputs.
- Modify the DC gain and phase for the IQ signals in the configuration, under either:
mixer_qubit_g & mixer_qubit_g or mixer_resonator_g & mixer_resonator_g.
"""

from qm import QuantumMachinesManager
from qm.qua import *
from configuration import *

###################
# The QUA program #
###################
element = "rr1"

with program() as cw_output:
with infinite_loop_():
# It is best to calibrate LO leakage first and without any power played (cf. note below)
play("cw" * amp(0), element)

#####################################
# Open Communication with the QOP #
#####################################
qmm = QuantumMachinesManager(host=qop_ip, port=qop_port, cluster_name=cluster_name, octave=octave_config)
qm = qmm.open_qm(config)

job = qm.execute(cw_output)

# When done, the halt command can be called and the offsets can be written directly into the config file.

# job.halt()

# These are the 2 commands used to correct for mixer imperfections. The first is used to set the DC of the `I` and `Q`
# channels to compensate for the LO leakage. The 2nd command is used to correct for the phase and amplitude mismatches
# between the channels.
# The output of the IQ Mixer should be connected to a spectrum analyzer and values should be chosen as to minimize the
# unwanted peaks.
# If python can read the output of the spectrum analyzer, then this process can be automated and the correct values can
# be found using an optimization method such as Nelder-Mead:
# https://docs.scipy.org/doc/scipy/reference/optimize.minimize-neldermead.html

# qm.set_output_dc_offset_by_element('rr1', ('I', 'Q'), (-0.001, 0.003))
# qm.set_mixer_correction('mixer_resonator', int(resonator_IF_q1), int(resonator_LO), IQ_imbalance(0.015, 0.01))

# Note that the LO leakage (DC Offset) depends on the 'I' & 'Q' powers, it is advised to run this step with no input power.
# This will ensure that there is no LO leakage while the pulses are not played in the case where the is no switch.
# This can be achieved by changing the line above to `play("cw" * amp(0), "qubit")`

# Automatic LO leakage correction
# centers = [0.5, 0]
# span = 0.1
#
# fig1 = plt.figure()
# for n in range(3):
# offset_i = np.linspace(centers[0] - span, centers[0] + span, 21)
# offset_q = np.linspace(centers[1] - span, centers[1] + span, 31)
# lo_leakage = np.zeros((len(offset_q), len(offset_i)))
# for i in range(len(offset_i)):
# for q in range(len(offset_q)):
# qm.set_output_dc_offset_by_element(element, ("I", "Q"), (offset_i[i], offset_q[q]))
# sleep(0.01)
# # Write functions to extract the lo leakage from the spectrum analyzer
# # lo_leakage[q][i] =
# minimum = np.argwhere(lo_leakage == np.min(lo_leakage))[0]
# centers = [offset_i[minimum[0]], offset_q[minimum[1]]]
# span = span / 10
# plt.subplot(131)
# plt.pcolor(offset_i, offset_q, lo_leakage.transpose())
# plt.xlabel("I offset [V]")
# plt.ylabel("Q offset [V]")
# plt.title(f"Minimum at (I={centers[0]:.3f}, Q={centers[1]:.3f}) = {lo_leakage[minimum[0]][minimum[1]]:.1f} dBm")
# plt.suptitle(f"LO leakage correction for {element}")
#
# print(f"For {element}, I offset is {centers[0]} and Q offset is {centers[1]}")
#
# # Automatic image cancellation
# centers = [0.5, 0]
# span = [0.2, 0.5]
#
# fig2 = plt.figure()
# for n in range(3):
# gain = np.linspace(centers[0] - span, centers[0] + span, 21)
# phase = np.linspace(centers[1] - span, centers[1] + span, 31)
# image = np.zeros((len(phase), len(gain)))
# for g in range(len(gain)):
# for p in range(len(phase)):
# qm.set_mixer_correction(
# config["elements"][element]["mixInputs"]["mixer"],
# int(config["elements"][element]["intermediate_frequency"]),
# int(config["elements"][element]["mixInputs"]["lo_frequency"]),
# IQ_imbalance(gain[g], phase[p]),
# )
# sleep(0.01)
# # Write functions to extract the image from the spectrum analyzer
# # image[q][i] =
# minimum = np.argwhere(image == np.min(image))[0]
# centers = [gain[minimum[0]], phase[minimum[1]]]
# span = (np.array(span) / 10).tolist()
# plt.subplot(131)
# plt.pcolor(gain, phase, image.transpose())
# plt.xlabel("Gain")
# plt.ylabel("Phase imbalance [rad]")
# plt.title(f"Minimum at (I={centers[0]:.3f}, Q={centers[1]:.3f}) = {image[minimum[0]][minimum[1]]:.1f} dBm")
# plt.suptitle(f"Image cancellation for {element}")
#
# print(f"For {element}, gain is {centers[0]} and phase is {centers[1]}")
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
This file is used to configure the Octave's clock and do the automatic calibration.
"""

from qm import QuantumMachinesManager
from qm.octave import ClockMode
from configuration import *


# Configure the Octave according to the elements settings and calibrate
qmm = QuantumMachinesManager(host=qop_ip, port=qop_port, octave=octave_config, log_level="ERROR")
qm = qmm.open_qm(config)

##################
# Clock settings #
##################
qm.octave.set_clock("octave1", clock_mode=ClockMode.Internal)
# If using external LO change this line to one of the following:
# qm.octave.set_clock("octave1", clock_mode=ClockMode.External_10MHz)
# qm.octave.set_clock("octave1", clock_mode=ClockMode.External_100MHz)
# qm.octave.set_clock("octave1", clock_mode=ClockMode.External_1000MHz)

##################
# Calibration #
##################
calibration = True

if calibration:
elements = ["rr1", "rr2", "q1_xy", "q2_xy"]
for element in elements:
print("-" * 37 + f" Calibrates {element}")
qm.calibrate_element(element)
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from qm.qua import *
from qm import QuantumMachinesManager, SimulationConfig
from configuration_mw_fem import *
from configuration import *
from qualang_tools.results import fetching_tool
from qualang_tools.loops import from_array
import matplotlib.pyplot as plt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from qm.qua import *
from qm import QuantumMachinesManager, SimulationConfig
from configuration_mw_fem import *
from configuration import *
from qualang_tools.results import progress_counter, fetching_tool
from qualang_tools.plot import interrupt_on_close
from qualang_tools.loops import from_array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from qm.qua import *
from qm import QuantumMachinesManager, SimulationConfig
from configuration_mw_fem import *
from configuration import *
from qualang_tools.results import progress_counter, fetching_tool
from qualang_tools.plot import interrupt_on_close
from qualang_tools.loops import from_array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

from qm.qua import *
from qm import QuantumMachinesManager, SimulationConfig
from configuration_mw_fem import *
from configuration import *
from qualang_tools.results import progress_counter, fetching_tool
from qualang_tools.plot import interrupt_on_close
from qualang_tools.loops import from_array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from qm import QuantumMachinesManager
from qm.qua import *
from qm import SimulationConfig
from configuration_mw_fem import *
from configuration import *
import matplotlib.pyplot as plt
from qualang_tools.loops import from_array
from qualang_tools.results import fetching_tool, progress_counter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from qm import QuantumMachinesManager, SimulationConfig
from qm.qua import *
from configuration_mw_fem import *
from configuration import *
import matplotlib.pyplot as plt
from qualang_tools.loops import from_array
from qualang_tools.results import fetching_tool, progress_counter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from qm import QuantumMachinesManager, SimulationConfig
from qm.qua import *
from configuration_mw_fem import *
from configuration import *
import matplotlib.pyplot as plt
from qualang_tools.loops import from_array
from qualang_tools.results import fetching_tool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from qm import QuantumMachinesManager
from qm.qua import *
from qm import SimulationConfig
from configuration_mw_fem import *
from configuration import *
import matplotlib.pyplot as plt
from qualang_tools.loops import from_array
from qualang_tools.results import fetching_tool, progress_counter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from qm import QuantumMachinesManager, SimulationConfig
from qm.qua import *
from configuration_mw_fem import *
from configuration import *
import matplotlib.pyplot as plt
from qualang_tools.loops import from_array
from qualang_tools.results import fetching_tool, progress_counter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from qm import QuantumMachinesManager, SimulationConfig
from qm.qua import *
from configuration_mw_fem import *
from configuration import *
import matplotlib.pyplot as plt
from qualang_tools.results import fetching_tool, progress_counter
import math
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from qm import QuantumMachinesManager, SimulationConfig
from qm.qua import *
from configuration_mw_fem import *
from configuration import *
import matplotlib.pyplot as plt
from qualang_tools.results import fetching_tool, progress_counter
from qualang_tools.plot import interrupt_on_close
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from qm import QuantumMachinesManager, SimulationConfig
from qm.qua import *
from configuration_mw_fem import *
from configuration import *
import matplotlib.pyplot as plt
from qualang_tools.results import fetching_tool
from macros import qua_declaration, multiplexed_readout, active_reset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from qm import QuantumMachinesManager, SimulationConfig
from qm.qua import *
from configuration_mw_fem import *
from configuration import *
import matplotlib.pyplot as plt
from qualang_tools.results import fetching_tool
from qualang_tools.plot import interrupt_on_close
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from qm import QuantumMachinesManager, SimulationConfig
from qm.qua import *
from configuration_mw_fem import *
from configuration import *
import matplotlib.pyplot as plt
from qualang_tools.results import fetching_tool
from qualang_tools.plot import interrupt_on_close
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from qm import QuantumMachinesManager, SimulationConfig
from qm.qua import *
from configuration_mw_fem import *
from configuration import *
import matplotlib.pyplot as plt
from qualang_tools.loops import from_array
from qualang_tools.results import fetching_tool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from qm import QuantumMachinesManager, SimulationConfig
from qm.qua import *
from configuration_mw_fem import *
from configuration import *
import matplotlib.pyplot as plt
from qualang_tools.loops import from_array
from qualang_tools.results import fetching_tool, progress_counter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from qm import QuantumMachinesManager, SimulationConfig
from qm.qua import *
from configuration_mw_fem import *
from configuration import *
import matplotlib.pyplot as plt
from qualang_tools.loops import from_array
from qualang_tools.results import fetching_tool, progress_counter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from qm.qua import *
from qm import QuantumMachinesManager
from configuration_mw_fem import *
from configuration import *
import matplotlib.pyplot as plt
from qm import SimulationConfig
from qualang_tools.results import fetching_tool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from qm.qua import *
from qm import QuantumMachinesManager
from qm import SimulationConfig
from configuration_mw_fem import *
from configuration import *
import matplotlib.pyplot as plt
import numpy as np
from qualang_tools.bakery.randomized_benchmark_c1 import c1_table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from qm.qua import *
from qm import QuantumMachinesManager
from qm import SimulationConfig
from configuration_mw_fem import *
from configuration import *
import matplotlib.pyplot as plt
import numpy as np
from qualang_tools.bakery.randomized_benchmark_c1 import c1_table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from qm.qua import *
from qm import QuantumMachinesManager
from configuration_mw_fem import *
from configuration import *
import matplotlib.pyplot as plt
from qm import SimulationConfig
from qualang_tools.loops import from_array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from qm.qua import *
from qm import QuantumMachinesManager
from configuration_mw_fem import *
from configuration import *
import matplotlib.pyplot as plt
from qm import SimulationConfig
from qualang_tools.loops import from_array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from qm.qua import *
from qm import QuantumMachinesManager
from configuration_mw_fem import *
from configuration import *
import matplotlib.pyplot as plt
from qm import SimulationConfig
from qualang_tools.loops import from_array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

from qm.qua import *
from qm import QuantumMachinesManager
from configuration_mw_fem import *
from configuration import *
import matplotlib.pyplot as plt
from qm import SimulationConfig
from qualang_tools.loops import from_array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

from qm.qua import *
from qm import QuantumMachinesManager
from configuration_mw_fem import *
from configuration import *
import matplotlib.pyplot as plt
from qm import SimulationConfig
from qualang_tools.loops import from_array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

from qm.qua import *
from qm import QuantumMachinesManager
from configuration_mw_fem import *
from configuration import *
import matplotlib.pyplot as plt
from qm import SimulationConfig
from qualang_tools.loops import from_array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

from qm.qua import *
from qm import QuantumMachinesManager
from configuration_mw_fem import *
from configuration import *
import matplotlib.pyplot as plt
from qm import SimulationConfig
from qualang_tools.loops import from_array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

from qm.qua import *
from qm import QuantumMachinesManager
from configuration_mw_fem import *
from configuration import *
import matplotlib.pyplot as plt
from qm import SimulationConfig
from qualang_tools.loops import from_array
Expand Down
Loading

0 comments on commit a1225b9

Please sign in to comment.