Skip to content

Changes from experiment (selene) #569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
fd43a0f
Clearer temporary variables naming
thangleiter Apr 7, 2021
c579b98
Fix crash from workaround
thangleiter Apr 7, 2021
111e10d
Indentation
thangleiter Apr 7, 2021
2de2074
Make HDAWG work
thangleiter Apr 7, 2021
8da770e
Fix bug where the wrong marker was selected
thangleiter Apr 7, 2021
b42d7d3
Use clear() method istead of setting empty dict
thangleiter Apr 7, 2021
8646bd5
Allow for marker channels to be handled by the pulse
thangleiter Apr 7, 2021
d71cd0b
Refactor default config behavior
thangleiter Apr 7, 2021
8ccafcd
Improve alazar auto update and actually use the buffer_strategy
thangleiter Sep 30, 2021
d2dcfd4
Do not manage ELF files ourselves because updating existing programs …
thangleiter Sep 30, 2021
5d617c3
Add missing imports
thangleiter Oct 4, 2021
cafe057
Merge branch 'master' into triton_200/master
shumpohl Nov 15, 2021
e79b0a5
Improve handling of arrays of sympy types
thangleiter Nov 22, 2021
c898d33
Merge branch 'master' into triton_200/master
thangleiter Feb 4, 2022
b3092aa
Fix handling of scalar ndarrays
thangleiter Jul 12, 2022
be5dc61
Remove circularity check in Loop.__repr__
shumpohl Jul 12, 2022
4f3927f
Fix hdawg compile if warning occures
thangleiter Jul 12, 2022
e620292
Add shuttle pulse test
thangleiter Jul 12, 2022
50e3673
Merge branch 'master' into triton_200/master
thangleiter Jul 12, 2022
68fcfe4
Fix bug in timereversalpt
shumpohl Jul 12, 2022
0f50159
Fix ArithmeticPT deserialization
shumpohl Jul 12, 2022
3420ab3
Fix zero duration FunctionPT
shumpohl Jul 13, 2022
4b1e03b
Fix buffer per window for single window mask
shumpohl Jul 13, 2022
adabd96
Add support for ChunkedAverage
shumpohl Jul 13, 2022
fa039f8
Fix "SyntaxError"
shumpohl Jul 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
690 changes: 376 additions & 314 deletions MATLAB/+qc/awg_program.m

Large diffs are not rendered by default.

665 changes: 342 additions & 323 deletions MATLAB/+qc/conf_seq.m

Large diffs are not rendered by default.

17 changes: 13 additions & 4 deletions MATLAB/+qc/daq_operations.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
% --- add ---------------------------------------------------------------
if strcmp(ctrl, 'add') % output is operations
% Call before qc.awg_program('arm')!



smdata.inst(instIndex).data.virtual_channel = struct( ...
'operations', {a.operations} ...
Expand Down Expand Up @@ -57,10 +59,10 @@
elseif strcmp(ctrl, 'get length') % output is length
% Operations need to have been added beforehand
mask_maker = py.getattr(daq, '_make_mask');
masks = util.py.py2mat(py.getattr(daq, '_registered_programs'));
masks = util.py.py2mat(masks.(a.program_name));
operations = masks.operations;
masks = util.py.py2mat(masks.masks(mask_maker));
programs = util.py.py2mat(py.getattr(daq, '_registered_programs'));
program = util.py.py2mat(programs.(a.program_name));
operations = program.operations;
masks = util.py.py2mat(program.masks(mask_maker));


maskIdsFromOperations = cellfun(@(x)(char(x.maskID)), util.py.py2mat(operations), 'UniformOutput', false);
Expand All @@ -81,6 +83,13 @@
error('daq_operations assumes that all masks should have the same length if using ComputeRepAverageDefinition.');
end
output(k) = n(1);
elseif isa(operations{k}, 'py.atsaverage._atsaverage_release.ComputeChunkedAverageDefinition')
chunk_size = operations{k}.chunkSize;
window_lengths = double(py.numpy.max(py.numpy.asarray(masks{maskIndex}.length, py.numpy.dtype('u8'))));
max_chunks_per_window = ceil(window_lengths / chunk_size);
n_windows = size(masks{maskIndex}.length);

output(k) = max_chunks_per_window * n_windows;
else
error('Operation ''%s'' not yet implemented', class(operations{k}));
end
Expand Down
78 changes: 40 additions & 38 deletions MATLAB/+qc/instantiate_pulse.m
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
function instantiated_pulse = instantiate_pulse(pulse, varargin)
% Plug in parameters

if qc.is_instantiated_pulse(pulse)
instantiated_pulse = pulse;

else
default_args = struct(...
'parameters', py.None, ...
'channel_mapping', py.None, ...
'window_mapping' , py.None, ...
'global_transformation', [], ...
'to_single_waveform', py.set() ...
);

args = util.parse_varargin(varargin, default_args);

args.channel_mapping = replace_empty_with_pynone(args.channel_mapping);
args.window_mapping = replace_empty_with_pynone(args.window_mapping);
args.global_transformation = qc.to_transformation(args.global_transformation);

kwargs = pyargs( ...
'parameters' , args.parameters, ...
'channel_mapping', args.channel_mapping, ...
'measurement_mapping' , args.window_mapping, ...
'global_transformation', args.global_transformation, ...
'to_single_waveform', args.to_single_waveform ...
);

instantiated_pulse = util.py.call_with_interrupt_check(py.getattr(pulse, 'create_program'), kwargs);
end
end
% Plug in parameters

if qc.is_instantiated_pulse(pulse)
instantiated_pulse = pulse;

else
default_args = struct(...
'parameters', py.None, ...
'channel_mapping', py.None, ...
'window_mapping' , py.None, ...
'global_transformation', [], ...
'to_single_waveform', py.set() ...
);

args = util.parse_varargin(varargin, default_args);

args.channel_mapping = replace_empty_with_pynone(args.channel_mapping);
args.window_mapping = replace_empty_with_pynone(args.window_mapping);
args.global_transformation = qc.to_transformation(args.global_transformation);

kwargs = pyargs( ...
'parameters' , args.parameters, ...
'channel_mapping', args.channel_mapping, ...
'measurement_mapping' , args.window_mapping, ...
'global_transformation', args.global_transformation, ...
'to_single_waveform', args.to_single_waveform ...
);

% Matlab crashes with this right now (12/20) 2020a, py37 TH
% instantiated_pulse = util.py.call_with_interrupt_check(py.getattr(pulse, 'create_program'), kwargs);
instantiated_pulse = pulse.create_program(kwargs);

end
end

function mappingStruct = replace_empty_with_pynone(mappingStruct)
for fn = fieldnames(mappingStruct)'
if isempty(mappingStruct.(fn{1}))
mappingStruct.(fn{1}) = py.None;
end
end

for fn = fieldnames(mappingStruct)'
if isempty(mappingStruct.(fn{1}))
mappingStruct.(fn{1}) = py.None;
end
end

end

4 changes: 4 additions & 0 deletions MATLAB/+qc/operations_to_python.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
pyOp = py.atsaverage.operations.RepAverage(args{:});
case 'RepeatedDownsample'
pyOp = py.atsaverage.operations.RepeatedDownsample(args{:});
case 'ChunkedAverage'
assert(numel(args) == 3);
args{3} = py.int(args{3});
pyOp = py.atsaverage.operations.ChunkedAverage(args{:});
otherwise
error('Operation %s not recognized', operations{k}{1});
end
Expand Down
142 changes: 71 additions & 71 deletions MATLAB/+qc/plot_pulse_4chan.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,76 +5,76 @@
% (c) 2018/06 Pascal Cerfontaine ([email protected])

defaultArgs = struct(...
'charge_diagram_data_structs', {{}}, ... Should contain 2 structs in a cell array with fields x, y
... and data, where data{1} contains the charge diagram data
'plot_charge_diagram', true, ...
'lead_points_cell', {{}}, ... Should contain a cell with a lead_points entry for each qubit
'special_points_cell', {{}}, ... Should contain a cell with a special_points entry for each qubit
'channels', {{'W', 'X', 'Y', 'Z'}}, ...
'measurements', {{'A', 'A', 'B', 'B'}}, ...
'markerChannels', {{'M1', '', 'M2', ''}} ...
);
'charge_diagram_data_structs', {{}}, ... Should contain 2 structs in a cell array with fields x, y
... and data, where data{1} contains the charge diagram data
'plot_charge_diagram', true, ...
'lead_points_cell', {{}}, ... Should contain a cell with a lead_points entry for each qubit
'special_points_cell', {{}}, ... Should contain a cell with a special_points entry for each qubit
'channels', {{'W', 'X', 'Y', 'Z'}}, ...
'measurements', {{'A', 'A', 'B', 'B'}}, ...
'markerChannels', {{'M1', '', 'M2', ''}} ...
);
args = util.parse_varargin(varargin, defaultArgs);
for chrgInd = 1:2
k = chrgInd + double(chrgInd==2);
q = 4 - k;
if numel(args.charge_diagram_data_structs) >= chrgInd
args.charge_diagram_data = args.charge_diagram_data_structs{chrgInd};
args.charge_diagram_data = {args.charge_diagram_data.x, args.charge_diagram_data.y, args.charge_diagram_data.data{1}};
else
args.charge_diagram_data = {};
end
if numel(args.lead_points_cell) >= chrgInd
args.lead_points = args.lead_points_cell{chrgInd};
else
args.lead_points = {};
end
if numel(args.special_points_cell) >= chrgInd
args.special_points = args.special_points_cell{chrgInd};
else
args.special_points = {};
end
args.charge_diagram = args.channels(k:k+1);
if args.plot_charge_diagram
args.subplots = [220+k 220+k+1];
else
args.subplots = [210+chrgInd];
end
args.clear_fig = k==1;
[t, channels, measurements, instantiatedPulse] = qc.plot_pulse(pulse, args);
xlabel(args.channels(k));
ylabel(args.channels(k+1));
if args.plot_charge_diagram
subplot(args.subplots(1));
end
set(findall(gca, 'DisplayName', sprintf('Chan: %s', args.channels{q})), 'Visible', 'off');
set(findall(gca, 'DisplayName', sprintf('Chan: %s', args.channels{q+1})), 'Visible', 'off');
set(findall(gca, 'DisplayName', sprintf('Chan: %s', args.markerChannels{q})), 'Visible', 'off');
set(findall(gca, 'DisplayName', sprintf('Chan: %s', args.markerChannels{q+1})), 'Visible', 'off');
set(findall(gca, 'DisplayName', sprintf('Meas: %s', args.measurements{q})), 'Visible', 'off');
set(findall(gca, 'DisplayName', sprintf('Meas: %s', args.measurements{q+1})), 'Visible', 'off');
[hLeg, hObj] = legend(gca);
for l = 1:numel(hLeg.String)
if strcmp(hLeg.String{l}, sprintf('Chan: %s', args.channels{q})) || ...
strcmp(hLeg.String{l}, sprintf('Chan: %s', args.channels{q+1})) || ...
strcmp(hLeg.String{l}, sprintf('Chan: %s', args.markerChannels{q})) || ...
strcmp(hLeg.String{l}, sprintf('Chan: %s', args.markerChannels{q+1})) || ...
strcmp(hLeg.String{l}, sprintf('Meas: %s', args.measurements{q})) || ...
strcmp(hLeg.String{l}, sprintf('Meas: %s', args.measurements{q+1}))
hLeg.String{l} = '';
end
findobj(hObj, 'type', 'line');
set(hObj, 'lineWidth', 2);
end


for chrgInd = 1:2
k = chrgInd + double(chrgInd==2);
q = 4 - k;
if numel(args.charge_diagram_data_structs) >= chrgInd
args.charge_diagram_data = args.charge_diagram_data_structs{chrgInd};
args.charge_diagram_data = {args.charge_diagram_data.x, args.charge_diagram_data.y, args.charge_diagram_data.data{1}};
else
args.charge_diagram_data = {};
end
if numel(args.lead_points_cell) >= chrgInd
args.lead_points = args.lead_points_cell{chrgInd};
else
args.lead_points = {};
end
if numel(args.special_points_cell) >= chrgInd
args.special_points = args.special_points_cell{chrgInd};
else
args.special_points = {};
end
args.charge_diagram = args.channels(k:k+1);
if args.plot_charge_diagram
args.subplots = [220+k 220+k+1];
else
args.subplots = [210+chrgInd];
end
args.clear_fig = k==1;
[t, channels, measurements, instantiatedPulse] = qc.plot_pulse(pulse, args);
xlabel(args.channels(k));
ylabel(args.channels(k+1));
if args.plot_charge_diagram
subplot(args.subplots(1));
end
set(findall(gca, 'DisplayName', sprintf('Chan: %s', args.channels{q})), 'Visible', 'off');
set(findall(gca, 'DisplayName', sprintf('Chan: %s', args.channels{q+1})), 'Visible', 'off');
set(findall(gca, 'DisplayName', sprintf('Chan: %s', args.markerChannels{q})), 'Visible', 'off');
set(findall(gca, 'DisplayName', sprintf('Chan: %s', args.markerChannels{q+1})), 'Visible', 'off');
set(findall(gca, 'DisplayName', sprintf('Meas: %s', args.measurements{q})), 'Visible', 'off');
set(findall(gca, 'DisplayName', sprintf('Meas: %s', args.measurements{q+1})), 'Visible', 'off');
[hLeg, hObj] = legend(gca);
for l = 1:numel(hLeg.String)
if strcmp(hLeg.String{l}, sprintf('Chan: %s', args.channels{q})) || ...
strcmp(hLeg.String{l}, sprintf('Chan: %s', args.channels{q+1})) || ...
strcmp(hLeg.String{l}, sprintf('Chan: %s', args.markerChannels{q})) || ...
strcmp(hLeg.String{l}, sprintf('Chan: %s', args.markerChannels{q+1})) || ...
strcmp(hLeg.String{l}, sprintf('Meas: %s', args.measurements{q})) || ...
strcmp(hLeg.String{l}, sprintf('Meas: %s', args.measurements{q+1}))
hLeg.String{l} = '';
end
findobj(hObj, 'type', 'line');
set(hObj, 'lineWidth', 2);
end
end
52 changes: 52 additions & 0 deletions MATLAB/+qc/resolve_mappings.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
function resolved = resolve_mappings(varargin)
% Takes a variable number of parameter mappings (structs) and resolves them
% sequentially. Eg. if the first maps A to B and the second B to C, returns
% a mapping A to C. Goes left-to-right (first to last).
%
% >> qc.resolve_mappings(struct('a', 'b'), struct('b', 'c', 'x', 'y'), ...
% struct('c', 'd'), struct('x', 'z', 'asdf', 'jkl'), ...
% struct('z', 'a', 'bla', 'foo'))
%
% Warning: Field clash. Value to the right supercedes.
% > In qc.resolve_mappings (line 14)
%
% ans =
%
% struct with fields:
%
% a: 'd'
% x: 'a'
% asdf: 'jkl'
% bla: 'foo'
% =========================================================================
resolved = varargin{1};
varargin = varargin(2:end);

while ~isempty(varargin)
visited_fields = {};
for f = fieldnames(resolved)'
field = f{1};
value = resolved.(field);
if isfield(varargin{1}, field)
warning('Field clash. Value to the right supercedes.')
resolved.(field) = varargin{1}.(field);
visited_fields = [visited_fields field];
elseif isfield(varargin{1}, value)
resolved.(field) = varargin{1}.(value);
visited_fields = [visited_fields value];
end
end

% Add unchanged new fields from varargin{1}
for f = fieldnames(varargin{1})'
field = f{1};
value = varargin{1}.(field);
if ~ismember(visited_fields, field)
resolved.(field) = value;
end
end

varargin = varargin(2:end);
end

end
8 changes: 4 additions & 4 deletions MATLAB/+qc/setup_alazar_measurements.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
nQubits = args.nQubits;
nMeasPerQubit = args.nMeasPerQubit;

py.setattr(hws, '_measurement_map', py.dict);
py.setattr(daq, '_mask_prototypes', py.dict);
py.getattr(hws, '_measurement_map').clear();
py.getattr(daq, '_mask_prototypes').clear();
warning('Removing measurement_map and measurement_map might break stuff if previously set. Needs testing.');

for q = 1:nQubits
Expand Down Expand Up @@ -81,12 +81,12 @@

% Q1 A1 qubitIndex, measIndex, hwChannel, auxFlag1, secondQubitIndex, secondHwChannel, auxFlag2
add_meas_and_mask(1, m, 2, false, 1, 0 , true);
% Q1 A2 qubitIndex, measIndex, hwChannel, auxFlag1, secondQubitIndex, secondHwChannel, auxFlag2
% Q1 A2 qubitIndex, measIndex, hwChannel, auxFlag1, secondQubitIndex, secondHwChannel, auxFlag2
add_meas_and_mask(1, m, 2, false, 2, 1 , true);

% Q2 A1 qubitIndex, measIndex, hwChannel, auxFlag1, secondQubitIndex, secondHwChannel, auxFlag2
add_meas_and_mask(2, m, 3, false, 1, 0 , true);
% Q2 A2 qubitIndex, measIndex, hwChannel, auxFlag1, secondQubitIndex, secondHwChannel, auxFlag2
% Q2 A2 qubitIndex, measIndex, hwChannel, auxFlag1, secondQubitIndex, secondHwChannel, auxFlag2
add_meas_and_mask(2, m, 3, false, 2, 1 , true);
end
end
Expand Down
4 changes: 0 additions & 4 deletions qupulse/_program/_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,6 @@ def _get_repr(self, first_prefix, other_prefixes) -> Generator[str, None, None]:
yield from cast(Loop, elem)._get_repr(other_prefixes + ' ->', other_prefixes + ' ')

def __repr__(self) -> str:
is_circular = is_tree_circular(self)
if is_circular:
return '{}: Circ {}'.format(id(self), is_circular)

str_len = 0
repr_list = []
for sub_repr in self._get_repr('', ''):
Expand Down
2 changes: 1 addition & 1 deletion qupulse/_program/seqc.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def markers_ch1(self):

@property
def markers_ch2(self):
return np.bitwise_and(self.marker_data, 0b1100)
return np.right_shift(np.bitwise_and(self.marker_data, 0b1100), 2)

@classmethod
def from_sampled(cls, ch1: Optional[np.ndarray], ch2: Optional[np.ndarray],
Expand Down
2 changes: 2 additions & 0 deletions qupulse/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def _parse_evaluate_numeric_result(self,
if isinstance(result, tuple):
result = numpy.array(result)
if isinstance(result, numpy.ndarray):
if result.shape == ():
return self._parse_evaluate_numeric_result(result[()], call_arguments)
if issubclass(result.dtype.type, allowed_types):
return result
else:
Expand Down
Loading