Commit 191eecc5 authored by Romain Baptiste Dominique Albert's avatar Romain Baptiste Dominique Albert
Browse files

Correction for the QM.

parent 8343f70f
import qm.qua as qua
import numpy as np
import math
import functools
import inspect
from experiment import BondedParameter
......@@ -10,11 +10,10 @@ from DataHandling.core import Measurement, DataSet
class BondedQMParameter(BondedParameter):
"""
This class is an helper to create parameter which are execute by the program in the quantum
machine.
This class is an helper to create parameter
"""
def __init__(self, parameter_name, instrument_name, data, unit=None):
def __init__(self, parameter_name, instrument_name, data, unit=''):
super().__init__(parameter_name, instrument_name, BondedQuantumMachine.store_parameters, data, unit)
......@@ -29,7 +28,7 @@ class BondedQMParameter(BondedParameter):
def __str__(self):
## Could be improved
return 'Quantum machine parameter used: '+self.elements[self.last_value]+' for '+self.name
return self.name+' (QM): '+str(self.last_value)
class BondedQMParameterSweptByProgram(BondedParameter):
......@@ -51,7 +50,7 @@ class BondedQMParameterSweptByProgram(BondedParameter):
def __str__(self):
## Could be improved
return 'Swept by the quantum machine: '+self.name
return 'Swept by the quantum machine: '+self.name+'. Start: '+str(self.data[0])+', Stop: '+str(self.data[-1])+', points: '+str(len(self.data))
class BondedQMParameterText(BondedParameter):
......@@ -93,6 +92,7 @@ class BondedQMMeasurement():
self.shape_swept_parameter = None
self.size_measurement = None
self.previous_program = None
self.instance = None
def __call__(self, instruments, additionnal_option = {}):
"""
......@@ -105,14 +105,16 @@ class BondedQMMeasurement():
except KeyError:
pass
program = self.get_program(instruments[self.instrument_name].get_current_parameters())
program = self.get_program(**instruments[self.instrument_name].get_current_parameters())
self.quantum_machine_job = instruments[self.instrument_name].execute_program(program)
try:
if additionnal_option['synchrone'] == False:
if 'synchrone' in additionnal_option.keys():
if additionnal_option['synchrone'] == True:
return self.get_data(instruments)
except KeyError:
return
else:
return
else:
return self.get_data(instruments)
def get_order_swept_parameters(self):
"""
......@@ -132,7 +134,10 @@ class BondedQMMeasurement():
order_parameter = self.get_order_swept_parameters()
parameters = instance.get_current_parameters()
self.shape_swept_parameter = [len(parameters[par]) for par in order_parameter]
self.size_measurement = math.prod(self.shape_swept_parameter)
## We full size of the measurement (product of all shape)
self.size_measurement = functools.reduce(lambda number_element, size: number_element*size,
self.shape_swept_parameter,
1)
def before_first_measurement(self, instance):
"""
......@@ -182,6 +187,7 @@ class BondedQMIQMeasurement(BondedQMMeasurement):
"""
def before_first_measurement(self, instance):
self.instance = instance
order_parameter = self.get_order_swept_parameters()
## It is important to fix the shape which will be used
......@@ -194,9 +200,9 @@ class BondedQMIQMeasurement(BondedQMMeasurement):
parameters = instance.get_parameters()
return DataSet(parameters,
[Measurement('I', np.empty((1), dtype=np.float64), '', order_parameter),
Measurement('Q', np.empty((1), dtype=np.float64), '', order_parameter)],
instance.get_config())
{'I': Measurement('I', np.empty((1), dtype=np.float64), '', order_parameter),
'Q': Measurement('Q', np.empty((1), dtype=np.float64), '', order_parameter)},
instance.get_sanetized_config())
def get_data(self, instruments):
......@@ -209,9 +215,9 @@ class BondedQMIQMeasurement(BondedQMMeasurement):
order_parameter = self.get_order_swept_parameters()
return DataSet([],
[Measurement('I', I_r, '', order_parameter),
Measurement('Q', Q_r, '', order_parameter)],
return DataSet({},
{'I': Measurement('I', I_r, '', order_parameter),
'Q': Measurement('Q', Q_r, '', order_parameter)},
{})
......@@ -225,12 +231,13 @@ class CavitySpectroscopy(BondedQMIQMeasurement):
**kwargs):
"""
Parameters which are swept internally by the quantum machine:
cavity_frequencies, cavity_amplitude, qubit_frequencies, qubit_amplitudes
cavity_frequencies, cavity_amplitude
All the other parameters can be swept by the experiment class.
"""
## Add security
cavity_frequencies = self.instance.get_IF_frequencies(cavity_element, cavity_frequencies)
cavity_frequencies = np.rint(cavity_frequencies).astype(np.int32).tolist()
cavity_amplitudes = cavity_amplitudes.astype(np.float64).tolist()
......@@ -243,7 +250,7 @@ class CavitySpectroscopy(BondedQMIQMeasurement):
Q = qua.declare(qua.fixed)
Q_stream = qua.declare_stream()
cavity_frequency = qua.declare(qua.int)
cavity_frequency = qua.declare(int)
cavity_amplitude = qua.declare(qua.fixed)
with qua.for_(N, 0, N < int(number_repetition), N + 1):
......@@ -287,19 +294,6 @@ class QubitSpectroscopyCavitySpectroscopy(BondedQMMeasurement):
Measurement('Q', np.empty((1), dtype=np.complex128), '', order_parameter)],
instance.get_config())
def get_data(self, instruments):
self.quantum_machine_job.result_handles.wait_for_all_values()
Ires = self.quantum_machine_job.result_handles.I_res.fetch_all()
Qres = self.quantum_machine_job.result_handles.Q_res.fetch_all()
swept_parameters = instruments[self.instrument_name].get_parameters()
I_r = Ires.reshape(self.shape_swept_parameter)
Q_r = Qres.reshape(self.shape_swept_parameter)
return DataSet([])
def get_program(self, number_repetition, wait_time,
cavity_element, cavity_pulse, cavity_frequencies, cavity_amplitudes,
qubit_element, qubit_pulse, qubit_frequencies, qubit_amplitudes,
......
MAX_AMPLITUDE = 0.4
MAX_FREQUENCY_OUTPUT = 400e6
......@@ -41,7 +41,7 @@ def gaussian(amplitude, sigma, get_length=False):
t = np.linspace(-sigma*3/2, sigma*3/2, length)
gauss_wave = amplitude * np.exp(-(t**2)/(2*sigma**2))
return {'type': 'arbitrary', 'sample': gauss_wave.tolist()}
return {'type': 'arbitrary', 'samples': gauss_wave.tolist()}
def square(amplitude, duty_cycle, start, length, offset = 0., get_length=False):
......@@ -81,4 +81,4 @@ def square(amplitude, duty_cycle, start, length, offset = 0., get_length=False):
x[start_pulse:stop_pulse] += amplitude
return {'type': 'arbitrary', 'sample': x.tolist()}
\ No newline at end of file
return {'type': 'arbitrary', 'samples': x.tolist()}
\ No newline at end of file
import numpy as np
import qm.qua as qua
from Instruments.Drivers.QuantumMachines.basic_measurements import BondedQMIQMeasurement
class TriggerCavitySpectroscopy(BondedQMIQMeasurement):
def get_order_swept_parameters(self):
return ['cavity_frequencies', 'cavity_amplitudes', 'delay_readout']
def get_program(self, number_repetition, wait_time,
cavity_element, cavity_pulse, cavity_frequencies, cavity_amplitudes,
trigger_element, trigger_pulse, delay_readout,
**kwargs):
"""
Parameters which are swept internally by the quantum machine:
cavity_frequencies, cavity_amplitude, qubit_frequencies, qubit_amplitudes
All the other parameters can be swept by the experiment class.
"""
## Add security
cavity_frequencies = self.instance.get_IF_frequencies(cavity_element, cavity_frequencies)
cavity_frequencies = np.rint(cavity_frequencies).astype(np.int32).tolist()
cavity_amplitudes = cavity_amplitudes.astype(np.float64).tolist()
delay_readout = np.rint(delay_readout/4e-9).astype(np.int32).tolist()
if wait_time < 200e-6:
raise ValueError('The fast AWG cannot trigger more regulary than every 200us.')
with qua.program() as program:
N = qua.declare(int)
I = qua.declare(qua.fixed)
I_stream = qua.declare_stream()
Q = qua.declare(qua.fixed)
Q_stream = qua.declare_stream()
cavity_frequency = qua.declare(int)
delay = qua.declare(int)
cavity_amplitude = qua.declare(qua.fixed)
with qua.for_(N, 0, N < int(number_repetition), N + 1):
with qua.for_each_(delay, delay_readout):
with qua.for_each_(cavity_frequency, cavity_frequencies):
qua.update_frequency(cavity_element, cavity_frequency)
qua.align()
with qua.for_each_(cavity_amplitude, cavity_amplitudes):
qua.play(trigger_pulse, trigger_element)
qua.wait(delay, trigger_element)
qua.align()
qua.measure(cavity_pulse * qua.amp(cavity_amplitude), cavity_element, None,
(cavity_pulse+"_integW1", "out1", I),
(cavity_pulse+"_integW2", "out1", Q)) ## Likely to be still changed
qua.save(I, I_stream)
qua.save(Q, Q_stream)
qua.wait(int(wait_time*1e9/4), cavity_element)
with qua.stream_processing():
I_stream.buffer(self.size_measurement).average().save("I_res")
Q_stream.buffer(self.size_measurement).average().save("Q_res")
return program
\ No newline at end of file
This diff is collapsed.
......@@ -31,7 +31,7 @@ class BondedParameter():
"""
def __init__(self, parameter_name, instrument_name, instrument_func,
data=[], unit=None, settle_time = 0.):
data=[], unit='', settle_time = 0.):
self.name = parameter_name
self._instrument_name = instrument_name
self.instrument_func = instrument_func
......@@ -71,7 +71,7 @@ class BondedParameter():
class BondedOnOffParameter(BondedParameter):
def __init__(self, parameter_name, instrument_name, instrument_func,
data=[], off_value=None, unit=None):
data=[], off_value=None, unit=''):
super().__init__(parameter_name, instrument_name, instrument_func, data, unit)
......@@ -348,9 +348,7 @@ class Experiment():
for parameter in fixed_parameters:
self.parameters[parameter](self.instruments, self.parameters[parameter].data[0])
string_fixed_parameters += '\t '+str(self.parameters[parameter])+'\n'
print(string_fixed_parameters)
return DataSet({parameter : Parameter(parameter,
np.array([self.parameters[parameter].last_value]),
self.parameters[parameter].unit,
......@@ -481,6 +479,18 @@ class Experiment():
if self.save_temperature:
list_measurements.append('temperature')
# First called all the parameter to their initial values: important for AWG
for i, parameter in enumerate(sweep_parameters):
print(self.parameters[parameter].name)
self.parameters[parameter](self.instruments, self.parameters[parameter].data[0])
for instrument in initialized_instruments:
# For the moment, only for AWG instruments.
try:
self.instruments[instrument].before_measurement()
except AttributeError:
pass
# Create the dataset for each measurement. Each dataset is multidimensional, axis_label
# is determined be the number of swept parameters
for measurement in list_measurements:
......@@ -516,27 +526,30 @@ class Experiment():
## Activate the output of all instrument:
self.start_all_instruments(initialized_instruments)
#print(self.parameters)
#all the possible combinations of the parameters that you want to sweep
#all the possible combinations of the parameters that you want to sweep
generator_indexes = itertools.product(*(np.arange(len(self.parameters[parameter].data)) \
for parameter in sweep_parameters))
# Total number of iteration.
number_iteration = functools.reduce(lambda number_element, parameter: number_element*len(self.parameters[parameter].data),
sweep_parameters,
1)
#print(number_iteration)
try:
with tqdm(generator_indexes, total=number_iteration,
bar_format="{l_bar}{bar}|{n:.0f}/{total_fmt} [{elapsed}<{remaining}, {rate_fmt}]{postfix}") as progress_bar_line1:
#with tqdm(total=number_iteration, bar_format="{postfix}") as progress_bar_line2:
for indexes in progress_bar_line1:
#Add settles
for i, parameter in enumerate(sweep_parameters):
self.parameters[parameter](self.instruments, self.parameters[parameter].data[indexes[i]])
for instrument in initialized_instruments:
# For the moment, only for AWG instruments.
try:
self.instruments[instrument].before_measurement()
except AttributeError:
pass
#progress_bar_line2.set_postfix_str(self.format_parameter(sweep_parameters), refresh=True)
progress_bar_line1.set_postfix_str(self.format_parameter(sweep_parameters), refresh=True)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment