Skip to content

Commit

Permalink
Typo and formatting fixes (#262)
Browse files Browse the repository at this point in the history
* Fixed typo in script name &
reformatted using black 24.8.0

* Typo and formatting fixes
  • Loading branch information
BradColeQM authored Nov 14, 2024
1 parent 5f1fc7f commit 46e7bde
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,20 @@
f = declare(int) # QUA variable for the qubit pulse duration
i = declare(int) # QUA variable for the magnetic field sweep
j = declare(int) # QUA variable for the lo frequency sweep
chirp_var = declare(int, value = chirp_rate)
chirp_var = declare(int, value=chirp_rate)
n_st = declare_stream() # Stream for the iteration number (progress bar)
with for_(i, 0, i < len(B_fields) + 1, i + 1):
with for_(j, 0, j < len(lo_frequencies), j + 1):
#pause() # Needs to be uncommented when not simulating
# pause() # Needs to be uncommented when not simulating
with for_(n, 0, n < n_avg, n + 1): # The averaging loop
with for_(*from_array(f, IFs)): # Loop over the qubit pulse amplitude
update_frequency("qubit", f)

# Navigate through the charge stability map
seq.add_step(voltage_point_name="initialization")
seq.add_step(voltage_point_name="idle", duration=chirp_duration + processing_time + delay_before_readout) # Processing time is time it takes to calculate the chirp pulse
seq.add_step(
voltage_point_name="idle", duration=chirp_duration + processing_time + delay_before_readout
) # Processing time is time it takes to calculate the chirp pulse
seq.add_step(voltage_point_name="readout", duration=duration_readout)
seq.add_compensation_pulse(duration=duration_compensation_pulse)

Expand All @@ -97,7 +99,11 @@
play("chirp", "qubit", chirp=(chirp_var, chirp_units))

# Measure the dot right after the qubit manipulation
wait((duration_init + chirp_duration + processing_time + delay_before_readout)* u.ns, "tank_circuit", "TIA",) #
wait(
(duration_init + chirp_duration + processing_time + delay_before_readout) * u.ns,
"tank_circuit",
"TIA",
) #
I, Q, I_st, Q_st = RF_reflectometry_macro()
dc_signal, dc_signal_st = DC_current_sensing_macro()

Expand All @@ -108,16 +114,12 @@
n_st.save("iteration")
# Cast the data into a 2D matrix and performs a global averaging of the received 2D matrices together.
# RF reflectometry
I_st.buffer(len(IFs)).buffer(n_avg).map(FUNCTIONS.average()).buffer(
len(lo_frequencies)
).save_all("I")
Q_st.buffer(len(IFs)).buffer(n_avg).map(FUNCTIONS.average()).buffer(
len(lo_frequencies)
).save_all("Q")
I_st.buffer(len(IFs)).buffer(n_avg).map(FUNCTIONS.average()).buffer(len(lo_frequencies)).save_all("I")
Q_st.buffer(len(IFs)).buffer(n_avg).map(FUNCTIONS.average()).buffer(len(lo_frequencies)).save_all("Q")
# DC current sensing
dc_signal_st.buffer(len(IFs)).buffer(n_avg).map(FUNCTIONS.average()).buffer(
len(lo_frequencies)
).save_all("dc_signal")
dc_signal_st.buffer(len(IFs)).buffer(n_avg).map(FUNCTIONS.average()).buffer(len(lo_frequencies)).save_all(
"dc_signal"
)

#####################################
# Open Communication with the QOP #
Expand Down Expand Up @@ -193,9 +195,7 @@
wait_until_job_is_paused(job)
if i == 0:
# Get results from QUA program and initialize live plotting
results = fetching_tool(
job, data_list=["I", "Q", "dc_signal", "iteration"], mode="live"
)
results = fetching_tool(job, data_list=["I", "Q", "dc_signal", "iteration"], mode="live")
# Fetch the data from the last OPX run corresponding to the current slow axis iteration
I, Q, DC_signal, iteration = results.fetch_all()
# Convert results into Volts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,8 @@
n_avg = 50
num_of_sequences = 50 # Number of random sequences
max_circuit_depth = 1000 # Maximum circuit depth
delta_clifford = (
10 # Play each sequence with a depth step equals to 'delta_clifford - Must be > 0
)
assert (
max_circuit_depth / delta_clifford
).is_integer(), "max_circuit_depth / delta_clifford must be an integer."
delta_clifford = 10 # Play each sequence with a depth step equals to 'delta_clifford - Must be > 0
assert (max_circuit_depth / delta_clifford).is_integer(), "max_circuit_depth / delta_clifford must be an integer."

seed = 34553 # Pseudo-random number generator seed

Expand Down Expand Up @@ -172,8 +168,9 @@ def play_sequence(sequence_list, depth):
play("y90", "qubit")
play("-x90", "qubit")


# Macro to calculate exact duration of generated sequence at a given depth
def generate_sequence_time(sequence_list, depth):
def generate_sequence_time(sequence_list, depth):
j = declare(int)
duration = declare(int)
assign(duration, 0) # Ensures duration is reset to 0 for every depth calculated
Expand Down Expand Up @@ -280,19 +277,15 @@ def generate_sequence_time(sequence_list, depth):
###################
with program() as rb:
depth = declare(int) # QUA variable for the varying depth
depth_target = declare(
int
) # QUA variable for the current depth (changes in steps of delta_clifford)
depth_target = declare(int) # QUA variable for the current depth (changes in steps of delta_clifford)
# QUA variable to store the last Clifford gate of the current sequence which is replaced by the recovery gate
saved_gate = declare(int)
m = declare(int) # QUA variable for the loop over random sequences
n = declare(int) # QUA variable for the averaging loop
I = declare(fixed) # QUA variable for the 'I' quadrature
Q = declare(fixed) # QUA variable for the 'Q' quadrature
state = declare(bool) # QUA variable for state discrimination
sequence_time = declare(
int
) # QUA variable for RB sequence duration for a given depth
sequence_time = declare(int) # QUA variable for RB sequence duration for a given depth
dc_signal = declare(fixed) # QUA variable for the measured dc signal
# Ensure that the result variables are assigned to the measurement elements
assign_variables_to_element("tank_circuit", I, Q)
Expand All @@ -306,19 +299,13 @@ def generate_sequence_time(sequence_list, depth):
I_st = declare_stream()
Q_st = declare_stream()

with for_(
m, 0, m < num_of_sequences, m + 1
): # QUA for_ loop over the random sequences
with for_(m, 0, m < num_of_sequences, m + 1): # QUA for_ loop over the random sequences

sequence_list, inv_gate_list = (
generate_sequence()
) # Generate the random sequence of length max_circuit_depth
sequence_list, inv_gate_list = generate_sequence() # Generate the random sequence of length max_circuit_depth

assign(depth_target, 1) # Initialize the current depth to 1

with for_(
depth, 1, depth <= max_circuit_depth, depth + 1
): # Loop over the depths
with for_(depth, 1, depth <= max_circuit_depth, depth + 1): # Loop over the depths

# Replacing the last gate in the sequence with the sequence's inverse gate
# The original gate is saved in 'saved_gate' and is being restored at the end
Expand Down Expand Up @@ -350,9 +337,7 @@ def generate_sequence_time(sequence_list, depth):
"TIA",
) # Includes calculated RB duration as well as RB sequence processing time
I, Q, I_st, Q_st = RF_reflectometry_macro(I=I, Q=Q)
dc_signal, dc_signal_st = DC_current_sensing_macro(
dc_signal=dc_signal
)
dc_signal, dc_signal_st = DC_current_sensing_macro(dc_signal=dc_signal)

# Make sure you updated the ge_threshold and angle if you want to use state discrimination
# Save the results to their respective streams
Expand Down Expand Up @@ -384,23 +369,23 @@ def generate_sequence_time(sequence_list, depth):
max_circuit_depth / delta_clifford
).average().save("state_avg")
else:
I_st.buffer(n_avg).map(FUNCTIONS.average()).buffer(
max_circuit_depth / delta_clifford
).buffer(num_of_sequences).save("I")
Q_st.buffer(n_avg).map(FUNCTIONS.average()).buffer(
max_circuit_depth / delta_clifford
).buffer(num_of_sequences).save("Q")
I_st.buffer(n_avg).map(FUNCTIONS.average()).buffer(
max_circuit_depth / delta_clifford
).average().save("I_avg")
Q_st.buffer(n_avg).map(FUNCTIONS.average()).buffer(
max_circuit_depth / delta_clifford
).average().save("Q_avg")
I_st.buffer(n_avg).map(FUNCTIONS.average()).buffer(max_circuit_depth / delta_clifford).buffer(
num_of_sequences
).save("I")
Q_st.buffer(n_avg).map(FUNCTIONS.average()).buffer(max_circuit_depth / delta_clifford).buffer(
num_of_sequences
).save("Q")
I_st.buffer(n_avg).map(FUNCTIONS.average()).buffer(max_circuit_depth / delta_clifford).average().save(
"I_avg"
)
Q_st.buffer(n_avg).map(FUNCTIONS.average()).buffer(max_circuit_depth / delta_clifford).average().save(
"Q_avg"
)

# DC current sensing
dc_signal_st.buffer(n_avg).map(FUNCTIONS.average()).buffer(
max_circuit_depth / delta_clifford
).buffer(num_of_sequences).save("dc_signal")
dc_signal_st.buffer(n_avg).map(FUNCTIONS.average()).buffer(max_circuit_depth / delta_clifford).buffer(
num_of_sequences
).save("dc_signal")
dc_signal_st.buffer(n_avg).map(FUNCTIONS.average()).buffer(
max_circuit_depth / delta_clifford
).average().save("dc_signal_avg")
Expand All @@ -409,9 +394,7 @@ def generate_sequence_time(sequence_list, depth):
#####################################
# Open Communication with the QOP #
#####################################
qmm = QuantumMachinesManager(
host=qop_ip, port=qop_port, cluster_name=cluster_name, octave=octave_config
)
qmm = QuantumMachinesManager(host=qop_ip, port=qop_port, cluster_name=cluster_name, octave=octave_config)

###########################
# Run or Simulate Program #
Expand Down Expand Up @@ -441,9 +424,7 @@ def generate_sequence_time(sequence_list, depth):
if state_discrimination:
results = fetching_tool(job, data_list=["state_avg", "iteration"], mode="live")
else:
results = fetching_tool(
job, data_list=["I_avg", "Q_avg", "iteration"], mode="live"
)
results = fetching_tool(job, data_list=["I_avg", "Q_avg", "iteration"], mode="live")
# Live plotting
fig = plt.figure()
interrupt_on_close(fig, job) # Interrupts the job when closing the figure
Expand All @@ -460,9 +441,7 @@ def generate_sequence_time(sequence_list, depth):

print(job.execution_report())
# Progress bar
progress_counter(
iteration, num_of_sequences, start_time=results.get_start_time()
)
progress_counter(iteration, num_of_sequences, start_time=results.get_start_time())
# Plot averaged values
plt.cla()
plt.plot(x, value_avg, marker=".")
Expand Down Expand Up @@ -497,9 +476,7 @@ def generate_sequence_time(sequence_list, depth):
print("#########################")
print("### Fitted Parameters ###")
print("#########################")
print(
f"A = {pars[0]:.3} ({stdevs[0]:.1}), B = {pars[1]:.3} ({stdevs[1]:.1}), p = {pars[2]:.3} ({stdevs[2]:.1})"
)
print(f"A = {pars[0]:.3} ({stdevs[0]:.1}), B = {pars[1]:.3} ({stdevs[1]:.1}), p = {pars[2]:.3} ({stdevs[2]:.1})")
print("Covariance Matrix")
print(cov)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def add_points(self, name: str, coordinates: list, duration: int) -> None:
duration_init = 2500
duration_manip = 1000
duration_readout = readout_len + 100
duration_compensation_pulse = 4 * u.us #Note, may need to be increased when running long RB sequences
duration_compensation_pulse = 4 * u.us # Note, may need to be increased when running long RB sequences

# Step parameters
step_length = 16 # in ns
Expand Down Expand Up @@ -344,16 +344,16 @@ def add_points(self, name: str, coordinates: list, duration: int) -> None:
cw_amp = 0.3 # in V
cw_len = 100 # in ns

#Chirp Pulse
chirp_duration = 1000 #in clock cycles
# Chirp Pulse
chirp_duration = 1000 # in clock cycles
chirp_rate = 5000
chirp_units = 'Hz/nsec'
chirp_amp = 0.05 #0.3
processing_time = 196 #time in ns for chirp to be calculated
chirp_units = "Hz/nsec"
chirp_amp = 0.05 # 0.3
processing_time = 196 # time in ns for chirp to be calculated

#RB Gate specifics
# RB Gate specifics
x180_len = 100
x180_amp = 0.1 #0.35
x180_amp = 0.1 # 0.35

x90_len = x180_len
x90_amp = x180_amp / 2
Expand Down Expand Up @@ -486,12 +486,12 @@ def add_points(self, name: str, coordinates: list, duration: int) -> None:
"pi_half": "pi_half_pulse",
"gauss": "gaussian_pulse",
"chirp": "chirp_pulse",
"x180" : "x180_pulse",
"x90" : "x90_pulse",
"x180": "x180_pulse",
"x90": "x90_pulse",
"-x90": "minus_x90_pulse",
"y180" : "y180_pulse",
"y90" : "y90_pulse",
"-y90" : "minus_y90_pulse",
"y180": "y180_pulse",
"y90": "y90_pulse",
"-y90": "minus_y90_pulse",
},
},
"tank_circuit": {
Expand Down Expand Up @@ -614,47 +614,47 @@ def add_points(self, name: str, coordinates: list, duration: int) -> None:
},
"digital_marker": "ON",
},
"x180_pulse":{
"x180_pulse": {
"operation": "control",
"length": x180_len,
"waveforms": {
"I": "x180_I_wf",
"Q": "x180_Q_wf",
},
},
"x90_pulse":{
"x90_pulse": {
"operation": "control",
"length": x90_len,
"waveforms": {
"I": "x90_I_wf",
"Q": "x90_Q_wf",
},
},
"minus_x90_pulse":{
"minus_x90_pulse": {
"operation": "control",
"length": x90_len,
"waveforms": {
"I": "-x90_I_wf",
"Q": "-x90_Q_wf",
},
},
"y180_pulse":{
"y180_pulse": {
"operation": "control",
"length": y180_len,
"waveforms": {
"I": "y180_I_wf",
"Q": "y180_Q_wf",
},
},
"y90_pulse":{
"y90_pulse": {
"operation": "control",
"length": y90_len,
"waveforms": {
"I": "y90_I_wf",
"Q": "y90_Q_wf",
},
},
"minus_y90_pulse":{
"minus_y90_pulse": {
"operation": "control",
"length": y90_len,
"waveforms": {
Expand All @@ -677,20 +677,20 @@ def add_points(self, name: str, coordinates: list, duration: int) -> None:
"reflect_wf": {"type": "constant", "sample": reflectometry_readout_amp},
"const_wf": {"type": "constant", "sample": cw_amp},
"zero_wf": {"type": "constant", "sample": 0.0},
"chirp_wf":{"type":"constant","sample":chirp_amp},
"chirp_wf": {"type": "constant", "sample": chirp_amp},
"zero_wf": {"type": "constant", "sample": 0.0},
"x180_I_wf": {"type":"constant", "sample": x180_amp},
"x180_Q_wf": {"type":"constant", "sample": 0.0},
"x90_I_wf": {"type":"constant", "sample": x90_amp},
"x90_Q_wf": {"type":"constant", "sample": 0.0},
"-x90_I_wf": {"type":"constant", "sample": minus_x90_amp},
"-x90_Q_wf": {"type":"constant", "sample": 0.0},
"y180_I_wf": {"type":"constant", "sample": 0.0},
"y180_Q_wf": {"type":"constant", "sample": y180_amp},
"y90_I_wf": {"type":"constant", "sample": 0.0},
"y90_Q_wf": {"type":"constant", "sample": y90_amp},
"-y90_I_wf": {"type":"constant", "sample": 0.0},
"-y90_Q_wf": {"type":"constant", "sample": minus_y90_amp},
"x180_I_wf": {"type": "constant", "sample": x180_amp},
"x180_Q_wf": {"type": "constant", "sample": 0.0},
"x90_I_wf": {"type": "constant", "sample": x90_amp},
"x90_Q_wf": {"type": "constant", "sample": 0.0},
"-x90_I_wf": {"type": "constant", "sample": minus_x90_amp},
"-x90_Q_wf": {"type": "constant", "sample": 0.0},
"y180_I_wf": {"type": "constant", "sample": 0.0},
"y180_Q_wf": {"type": "constant", "sample": y180_amp},
"y90_I_wf": {"type": "constant", "sample": 0.0},
"y90_Q_wf": {"type": "constant", "sample": y90_amp},
"-y90_I_wf": {"type": "constant", "sample": 0.0},
"-y90_Q_wf": {"type": "constant", "sample": minus_y90_amp},
},
"digital_waveforms": {
"ON": {"samples": [(1, 0)]},
Expand Down

0 comments on commit 46e7bde

Please sign in to comment.