Skip to content

Commit

Permalink
Revert "change black to 120 chars"
Browse files Browse the repository at this point in the history
This reverts commit 5a5fff9.
  • Loading branch information
yomach committed Dec 5, 2023
1 parent 5a5fff9 commit 47549e7
Show file tree
Hide file tree
Showing 28 changed files with 1,525 additions and 482 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ interplot = ["dill", "pypiwin32", "ipython"]
configbuilder = ["pandas", "dash", "dash-html-components", "dash-core-components", "dash-bootstrap-components", "dash-cytoscape", "dash-table", "dash-dangerously-set-inner-html", "docutils", "waitress"]

[tool.black]
line-length = 120
line-length = 88 # Defaults
exclude = "qualang_tools/bakery/randomized_benchmark_c1.py"

[tool.poe.tasks]
Expand Down
395 changes: 304 additions & 91 deletions qualang_tools/addons/InteractivePlotLib.py

Large diffs are not rendered by default.

257 changes: 196 additions & 61 deletions qualang_tools/addons/calibration/calibrations.py

Large diffs are not rendered by default.

243 changes: 182 additions & 61 deletions qualang_tools/bakery/bakery.py

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions qualang_tools/bakery/randomized_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ def __init__(self, config: dict, d_max: int, qubit: str):
self.d_max = d_max
self.config = config
self.qubit = qubit
self.state_tracker = [0] * d_max # Keeps track of all transformations done on qubit state
self.state_tracker = [
0
] * d_max # Keeps track of all transformations done on qubit state
self.state_init = 0
self.revert_ops = [0] * d_max # Keeps track of inverse op index associated to each sequence
self.revert_ops = [
0
] * d_max # Keeps track of inverse op index associated to each sequence
self.duration_tracker = [0] * d_max # Keeps track of each Clifford's duration
# self.baked_cliffords = self.generate_cliffords() # List of baking objects for running Cliffords
self.operations_list = [None] * d_max
Expand Down Expand Up @@ -176,7 +180,9 @@ def generate_RB_sequence(self):
self.operations_list[d] = random_clifford
for op in random_clifford:
b.play(op, self.qubit)
self.duration_tracker[d] += 1 # Add additional duration for each pulse played to build Clifford
self.duration_tracker[
d
] += 1 # Add additional duration for each pulse played to build Clifford

if d == 0: # Handle the case for qubit set to original/ground state
self.state_tracker[d] = c1_table[self.state_init][i]
Expand Down
8 changes: 6 additions & 2 deletions qualang_tools/bakery/xeb.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def __init__(
self.m_max = m_max
self.duration_tracker = [0] * m_max
self.operations_list = {qe: [] for qe in ["q1", "q2"]}
self.baked_sequence = self._generate_xeb_sequence(q1_ops, q2_ops, two_qubit_op, align_op)
self.baked_sequence = self._generate_xeb_sequence(
q1_ops, q2_ops, two_qubit_op, align_op
)

def _generate_xeb_sequence(self, q1_ops, q2_ops, two_qubit_op, align_op):
rand_seq1 = np.random.randint(3, size=self.m_max)
Expand Down Expand Up @@ -101,4 +103,6 @@ def play_all_ops(current_bake, sub_bake):


def get_total_len(baking_sequence):
return max(baking_sequence.get_op_length(element) for element in baking_sequence.elements)
return max(
baking_sequence.get_op_length(element) for element in baking_sequence.elements
)
8 changes: 6 additions & 2 deletions qualang_tools/config/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ def build(self, config=None):
elif isinstance(obj, Oscillator):
self.configuration.add_oscillator(obj)
else:
raise NotImplementedError("Can not add objects of type {0}".format(type(obj)))
raise NotImplementedError(
"Can not add objects of type {0}".format(type(obj))
)
return self.configuration.config

def find_instances(self, obj_type):
Expand Down Expand Up @@ -192,7 +194,9 @@ def find_users_of(
elif isinstance(elm, Mixer):
return self._find_users_of_mixer(elm)
else:
raise NotImplementedError("can not find objects of type {}".format(type(elm)))
raise NotImplementedError(
"can not find objects of type {}".format(type(elm))
)

def _find_users_of_port(self, port: Port):
objects = []
Expand Down
103 changes: 80 additions & 23 deletions qualang_tools/config/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ def _use_analog_input_port(self, port_num: int, offset: float = 0.0):
"""
if port_num not in self.dict["analog_inputs"]:
self.dict["analog_inputs"][port_num] = {"offset": offset}
self.analog_input_ports += [AnalogInputPort(self.name, port_num, offset=offset)]
self.analog_input_ports += [
AnalogInputPort(self.name, port_num, offset=offset)
]

def _use_analog_output_port(self, port_num: int, offset: float = 0.0):
"""Adds an instance of AnalogOutputPort to configuration if it is not used
Expand All @@ -139,7 +141,9 @@ def _use_analog_output_port(self, port_num: int, offset: float = 0.0):
"""
if port_num not in self.dict["analog_outputs"]:
self.dict["analog_outputs"][port_num] = {"offset": offset}
self.analog_output_ports += [AnalogOutputPort(self.name, port_num, offset=offset)]
self.analog_output_ports += [
AnalogOutputPort(self.name, port_num, offset=offset)
]

def _use_digital_output_port(self, port_num: int):
"""Adds an instance of DigitalOutputPort to configuration if it is not used
Expand Down Expand Up @@ -168,7 +172,12 @@ def ports(self):
:return:
:rtype: Set
"""
return self.digital_input_ports + self.digital_output_ports + self.analog_input_ports + self.analog_output_ports
return (
self.digital_input_ports
+ self.digital_output_ports
+ self.analog_input_ports
+ self.analog_output_ports
)


class ArbitraryWaveform(Waveform):
Expand Down Expand Up @@ -224,7 +233,9 @@ def __init__(self, name: str, samples: List[DigitalSample]):
if isinstance(samples[0], DigitalSample):
self._samples = samples
else:
self._samples = [DigitalSample(state, duration) for (state, duration) in samples]
self._samples = [
DigitalSample(state, duration) for (state, duration) in samples
]
dic = dict()
dic["samples"] = [(ds.state, ds.duration) for ds in self._samples]
super(DigitalWaveform, self).__init__(name, dic)
Expand All @@ -238,7 +249,9 @@ def samples(self, samples: Union[List[Tuple[int, int]], List[DigitalSample]]):
if isinstance(samples[0], DigitalSample):
self._samples = samples
else:
self._samples = [DigitalSample(state, duration) for (state, duration) in samples]
self._samples = [
DigitalSample(state, duration) for (state, duration) in samples
]
self.dict["samples"] = [(ds.state, ds.duration) for ds in self._samples]


Expand Down Expand Up @@ -325,7 +338,9 @@ def add(self, data: MixerData):


class Oscillator(ConfigBuilderElement):
def __init__(self, name: str, intermediate_frequency: int, lo_frequency: int, mixer: str):
def __init__(
self, name: str, intermediate_frequency: int, lo_frequency: int, mixer: str
):
"""An internal oscillator.
:param name: name of the oscillator
:type name: str
Expand Down Expand Up @@ -422,10 +437,18 @@ def __init__(
self.pulses = []
if pulses is not None:
self.pulses = pulses
self.element_analog_inputs = [] if element_analog_inputs is None else element_analog_inputs
self.element_analog_outputs = [] if element_analog_outputs is None else element_analog_outputs
self.element_digital_outputs = [] if element_digital_outputs is None else element_digital_outputs
self.element_digital_inputs = [] if element_digital_inputs is None else element_digital_inputs
self.element_analog_inputs = (
[] if element_analog_inputs is None else element_analog_inputs
)
self.element_analog_outputs = (
[] if element_analog_outputs is None else element_analog_outputs
)
self.element_digital_outputs = (
[] if element_digital_outputs is None else element_digital_outputs
)
self.element_digital_inputs = (
[] if element_digital_inputs is None else element_digital_inputs
)
self.mixer: Mixer = mixer

if len(self.element_analog_inputs) > 0:
Expand Down Expand Up @@ -517,7 +540,9 @@ def _add_operation(self, op: Operation):
self.dict["operations"][op.name] = op.pulse.name
self.pulses.append(op.pulse)

def _add(self, obj: Union[Operation, Mixer, ControlPulse, MeasurePulse, Oscillator]):
def _add(
self, obj: Union[Operation, Mixer, ControlPulse, MeasurePulse, Oscillator]
):
"""A method to add components to an element
:param obj: The component to be added
Expand Down Expand Up @@ -561,11 +586,19 @@ def waveform_names(self):

@property
def ports(self):
return self.analog_input_ports + self.analog_output_ports + self.digital_output_ports + self.digital_input_ports
return (
self.analog_input_ports
+ self.analog_output_ports
+ self.digital_output_ports
+ self.digital_input_ports
)

@property
def has_signal_threshold(self):
return "outputPulseParameters" in self.dict and "signalThreshold" in self.dict["outputPulseParameters"].keys()
return (
"outputPulseParameters" in self.dict
and "signalThreshold" in self.dict["outputPulseParameters"].keys()
)

@property
def signal_threshold(self):
Expand All @@ -582,7 +615,10 @@ def signal_threshold(self, val: int):

@property
def has_signal_polarity(self):
return "outputPulseParameters" in self.dict and "signalPolarity" in self.dict["outputPulseParameters"].keys()
return (
"outputPulseParameters" in self.dict
and "signalPolarity" in self.dict["outputPulseParameters"].keys()
)

@property
def signal_polarity(self):
Expand All @@ -600,7 +636,8 @@ def signal_polarity(self, val: str):
@property
def has_derivative_threshold(self):
return (
"outputPulseParameters" in self.dict and "derivativeThreshold" in self.dict["outputPulseParameters"].keys()
"outputPulseParameters" in self.dict
and "derivativeThreshold" in self.dict["outputPulseParameters"].keys()
)

@property
Expand All @@ -619,7 +656,8 @@ def derivative_threshold(self, val: int):
@property
def has_derivative_polarity(self):
return (
"outputPulseParameters" in self.dict and "derivativePolarity" in self.dict["outputPulseParameters"].keys()
"outputPulseParameters" in self.dict
and "derivativePolarity" in self.dict["outputPulseParameters"].keys()
)

@property
Expand Down Expand Up @@ -749,7 +787,9 @@ def __init__(
tot_duration_sin = 0
for e in sines:
tot_duration_sin += e[1]
assert tot_duration_sin == tot_duration_cos, "Total duration of the sine and cosine weights must be same"
assert (
tot_duration_sin == tot_duration_cos
), "Total duration of the sine and cosine weights must be same"

super(PiecewiseConstantIntegrationWeights, self).__init__(
name,
Expand All @@ -773,7 +813,9 @@ def __init__(self, name: str, cosine: float, sine: float, duration: int):
self._duration = duration
self._cosine = cosine
self._sine = sine
super(ConstantIntegrationWeights, self).__init__(name, [(cosine, duration)], [(sine, duration)])
super(ConstantIntegrationWeights, self).__init__(
name, [(cosine, duration)], [(sine, duration)]
)

@property
def cosine(self):
Expand Down Expand Up @@ -1033,7 +1075,14 @@ def mixer(self, mixer: Mixer):


class Transmon(ElementCollection):
def __init__(self, name: str, I: AnalogOutputPort, Q: AnalogOutputPort, intermediate_frequency: int, **kwargs):
def __init__(
self,
name: str,
I: AnalogOutputPort,
Q: AnalogOutputPort,
intermediate_frequency: int,
**kwargs
):
"""A superconducting transmon qubit
:param name: A name for this transmon
Expand Down Expand Up @@ -1214,17 +1263,23 @@ def _add(self, op: Union[Operation, ControlPulse]):
elif len(op.pulse.wfs) == 1:
self.flux_operations.append(op)
else:
raise ConfigurationError("Can not add a pulse with {0} waveforms".format(len(op.pulse.wfs)))
raise ConfigurationError(
"Can not add a pulse with {0} waveforms".format(len(op.pulse.wfs))
)
elif isinstance(op, ControlPulse):
if len(op.wfs) == 2:
super(FluxTunableTransmon, self)._add(op)
elif len(op.wfs) == 1:
self.flux_operations.append(op)
else:
raise ConfigurationError("Can not add a pulse with {0} waveforms".format(len(op.wfs)))
raise ConfigurationError(
"Can not add a pulse with {0} waveforms".format(len(op.wfs))
)

else:
raise ConfigurationError("adding unsupported object of type {}".format(type(op)))
raise ConfigurationError(
"adding unsupported object of type {}".format(type(op))
)


class Coupler(ElementCollection):
Expand Down Expand Up @@ -1252,7 +1307,9 @@ def _add(self, op: Operation):
if len(op.pulse.wfs) == 1:
self.operations.append(op)
else:
raise ConfigurationError("Can not add a pulse with {0} waveforms".format(len(op.pulse.wfs)))
raise ConfigurationError(
"Can not add a pulse with {0} waveforms".format(len(op.pulse.wfs))
)

def add(self, op: Union[List[Operation], Operation]):
if isinstance(op, list):
Expand Down
34 changes: 24 additions & 10 deletions qualang_tools/config/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def __init__(self, controllers: List[Controller] = None, version: int = 1):
self.config["version"] = 1
self.config["controllers"] = dict()
for cont in controllers:
self.config["controllers"][cont.name] = self._call_dict_parameters(cont.dict)
self.config["controllers"][cont.name] = self._call_dict_parameters(
cont.dict
)
self.config["elements"] = dict()
self.config["pulses"] = dict()
self.config["waveforms"] = dict()
Expand Down Expand Up @@ -113,14 +115,16 @@ def add_pulse(self, pulse: Pulse):
self.add_waveforms(pulse.wfs)
if pulse.digital_marker is not None:
_dict["digital_marker"] = pulse.digital_marker.name
self.config["digital_waveforms"][pulse.digital_marker.name] = self._call_dict_parameters(
pulse.digital_marker.dict
)
self.config["digital_waveforms"][
pulse.digital_marker.name
] = self._call_dict_parameters(pulse.digital_marker.dict)
if isinstance(pulse, MeasurePulse):
_dict["integration_weights"] = dict()
for w in pulse.integration_weights:
_dict["integration_weights"][w.name] = w.weights.name
self.config["integration_weights"][w.weights.name] = self._call_weights_dict(w.weights.dict)
self.config["integration_weights"][
w.weights.name
] = self._call_weights_dict(w.weights.dict)
self.config["pulses"][pulse.name] = self._call_dict_parameters(_dict)

def add_pulses(self, pulses: List[Pulse]):
Expand Down Expand Up @@ -171,7 +175,9 @@ def update_integration_weights(self, pulse_name: str, iw: IntegrationWeights):
assert self.config["pulses"][pulse_name]["operation"] == "measure"
assert len(self.config["pulses"][pulse_name]["waveforms"].keys()) == 2
weight_name = pulse_name + "_weight"
self.config["integration_weights"][weight_name] = self._call_dict_parameters(iw.dict)
self.config["integration_weights"][weight_name] = self._call_dict_parameters(
iw.dict
)

def update_constant_waveform(self, wf_name: str, amp: float):
"""Update the amplitude of an existing constant waveform
Expand Down Expand Up @@ -202,7 +208,9 @@ def reset(self, controllers=None):
controllers = []
self.__init__(controllers)

def update_intermediate_frequency(self, elm_name: str, freq: float, update_mixer: bool = True):
def update_intermediate_frequency(
self, elm_name: str, freq: float, update_mixer: bool = True
):
self.config["elements"][elm_name]["intermediate_frequency"] = freq
if update_mixer:
m_name = self.config["elements"][elm_name]["mixer"]
Expand Down Expand Up @@ -253,20 +261,26 @@ def add_integration_weights(self, weight: IntegrationWeights):
:param weight: an IntegrationWeights object
:type weight: IntegrationWeights
"""
self.config["integration_weights"][weight.name] = self._call_dict_parameters(weight.dict)
self.config["integration_weights"][weight.name] = self._call_dict_parameters(
weight.dict
)

def add_mixer(self, mixer: Mixer):
"""Add a mixer to this configuration
:param mixer: A Mixer object
:type mixer: Mixer
"""
self.config["mixers"][mixer.name] = [self._call_dict_parameters(data) for data in mixer.dict]
self.config["mixers"][mixer.name] = [
self._call_dict_parameters(data) for data in mixer.dict
]

def add_oscillator(self, oscillator: Oscillator):
"""Add an oscillator to this configuration
:param oscillator: an Oscillator object
:type oscillator: Oscillator
"""
self.config["oscillators"][oscillator.name] = self._call_dict_parameters(oscillator.dict)
self.config["oscillators"][oscillator.name] = self._call_dict_parameters(
oscillator.dict
)
Loading

0 comments on commit 47549e7

Please sign in to comment.