Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
yomach committed Dec 21, 2023
1 parent a3dbb0d commit b12fe6a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 101 deletions.
79 changes: 17 additions & 62 deletions qualang_tools/bakery/bakery.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@ def _init_dict(self):
"freq": 0,
"time_track": 0, # Value used for negative waits, to know where to add the samples (negative int)
}
if (
"mixInputs" in self._local_config["elements"][qe]
or "RF_inputs" in self._local_config["elements"][qe]
):
if "mixInputs" in self._local_config["elements"][qe] or "RF_inputs" in self._local_config["elements"][qe]:
sample_dict[qe] = {"I": [], "Q": []}

elif "singleInput" in self._local_config["elements"][qe]:
Expand Down Expand Up @@ -269,14 +266,8 @@ def __exit__(self, exc_type, exc_value, exc_traceback):

elif self._padding_method == "left":
if "mixInputs" in elements[qe] or "RF_inputs" in elements[qe]:
qe_samples["I"] = (
qe_samples["I"][end_samples:]
+ qe_samples["I"][0:end_samples]
)
qe_samples["Q"] = (
qe_samples["Q"][end_samples:]
+ qe_samples["Q"][0:end_samples]
)
qe_samples["I"] = qe_samples["I"][end_samples:] + qe_samples["I"][0:end_samples]
qe_samples["Q"] = qe_samples["Q"][end_samples:] + qe_samples["Q"][0:end_samples]
elif "singleInput" in elements[qe]:
qe_samples["single"] = qe_samples["single"][end_samples:] + qe_samples["single"][0:end_samples]

Expand Down Expand Up @@ -320,12 +311,8 @@ def __exit__(self, exc_type, exc_value, exc_traceback):
self._update_config(qe, qe_samples)

if "mixInputs" in elements[qe] or "RF_inputs" in elements[qe]:
self.override_waveforms_dict["waveforms"][
f"{qe}_baked_wf_I_{self._ctr}"
] = qe_samples["I"]
self.override_waveforms_dict["waveforms"][
f"{qe}_baked_wf_Q_{self._ctr}"
] = qe_samples["Q"]
self.override_waveforms_dict["waveforms"][f"{qe}_baked_wf_I_{self._ctr}"] = qe_samples["I"]
self.override_waveforms_dict["waveforms"][f"{qe}_baked_wf_Q_{self._ctr}"] = qe_samples["Q"]

elif "singleInput" in elements[qe]:
self.override_waveforms_dict["waveforms"][f"{qe}_baked_wf_{self._ctr}"] = qe_samples["single"]
Expand Down Expand Up @@ -425,10 +412,7 @@ def get_current_length(self, qe: Optional[str] = None) -> int:
max_length = length
return max_length
else:
if (
"mixInputs" in self._local_config["elements"][qe]
or "RF_inputs" in self._local_config["elements"][qe]
):
if "mixInputs" in self._local_config["elements"][qe] or "RF_inputs" in self._local_config["elements"][qe]:
return len(self._samples_dict[qe]["I"])
elif "singleInput" in self._local_config["elements"][qe]:
return len(self._samples_dict[qe]["single"])
Expand Down Expand Up @@ -545,10 +529,7 @@ def remove_op(q):
if f"baked_Op_{self._ctr}" in self.config["elements"][q]["operations"]:
del self.config["elements"][q]["operations"][f"baked_Op_{self._ctr}"]
del self.config["pulses"][f"{q}_baked_pulse_{self._ctr}"]
if (
"mixInputs" in self.config["elements"][q]
or "RF_inputs" in self.config["elements"][q]
):
if "mixInputs" in self.config["elements"][q] or "RF_inputs" in self.config["elements"][q]:
del self.config["waveforms"][f"{q}_baked_wf_I_{self._ctr}"]
del self.config["waveforms"][f"{q}_baked_wf_Q_{self._ctr}"]
elif "singleInput" in self.config["elements"][q]:
Expand Down Expand Up @@ -598,15 +579,8 @@ def get_op_length(self, qe: Optional[str] = None) -> int:
if not (qe in self._qe_set):
raise KeyError(f"{qe} is not in the set of quantum elements of the baking object ")
else:
if (
"mixInputs" in self._config["elements"][qe]
or "RF_inputs" in self._config["elements"][qe]
):
return len(
self._config["waveforms"][f"{qe}_baked_wf_I_{self._ctr}"][
"samples"
]
)
if "mixInputs" in self._config["elements"][qe] or "RF_inputs" in self._config["elements"][qe]:
return len(self._config["waveforms"][f"{qe}_baked_wf_I_{self._ctr}"]["samples"])
else:
return len(self._config["waveforms"][f"{qe}_baked_wf_{self._ctr}"]["samples"])
else:
Expand Down Expand Up @@ -667,13 +641,8 @@ def add_op(

index = self._get_pulse_index(qe)
Op = {name: f"{qe}_baked_pulse_b{self._ctr}_{index}"}
if (
"mixInputs" in self._local_config["elements"][qe]
or "RF_inputs" in self._local_config["elements"][qe]
):
assert (
len(samples) == 2
), f"{qe} is a mixInputs/RF_inputs element, two lists should be provided"
if "mixInputs" in self._local_config["elements"][qe] or "RF_inputs" in self._local_config["elements"][qe]:
assert len(samples) == 2, f"{qe} is a mixInputs/RF_inputs element, two lists should be provided"
assert len(samples[0]) == len(
samples[1]
), "Error : samples provided for I and Q do not have the same length"
Expand Down Expand Up @@ -754,9 +723,7 @@ def play(self, Op: str, qe: str, amp: Union[float, Tuple[float]] = 1.0) -> None:
assert isinstance(
samples, list
), f"{qe} is a mixInputs/RF_inputs element, two lists should be provided"
assert (
len(samples) == 2
), f"{qe} is a mixInputs/RF_inputs element, two lists should be provided"
assert len(samples) == 2, f"{qe} is a mixInputs/RF_inputs element, two lists should be provided"
assert type(samples[0] == list) and type(
samples[1] == list
), f"{qe} is a mixInputs/RF_inputs element, two lists should be provided"
Expand All @@ -782,14 +749,8 @@ def play(self, Op: str, qe: str, amp: Union[float, Tuple[float]] = 1.0) -> None:
else:
I2[i] = amp[0] * I[i] + amp[1] * Q[i]
Q2[i] = amp[2] * I[i] + amp[3] * Q[i]
I3[i] = (
np.cos(freq * i * 1e-9 + phi) * I2[i]
- np.sin(freq * i * 1e-9 + phi) * Q2[i]
)
Q3[i] = (
np.sin(freq * i * 1e-9 + phi) * I2[i]
+ np.cos(freq * i * 1e-9 + phi) * Q2[i]
)
I3[i] = np.cos(freq * i * 1e-9 + phi) * I2[i] - np.sin(freq * i * 1e-9 + phi) * Q2[i]
Q3[i] = np.sin(freq * i * 1e-9 + phi) * I2[i] + np.cos(freq * i * 1e-9 + phi) * Q2[i]
self._samples_dict[qe]["I"].append(I3[i])
self._samples_dict[qe]["Q"].append(Q3[i])
self._update_qe_time(qe, len(I))
Expand Down Expand Up @@ -856,12 +817,9 @@ def play_at(self, Op: str, qe: str, t: int, amp: Union[float, Tuple[float]] = 1.
assert isinstance(
samples, list
), f"{qe} is a mixInputs/RF_inputs element, two lists should be provided"
assert (
len(samples) == 2
), f"{qe} is a mixInputs/RF_inputs element, two lists should be provided"
assert len(samples) == 2, f"{qe} is a mixInputs/RF_inputs element, two lists should be provided"
assert type(samples[0] == list) and type(samples[1] == list), (
f"{qe} is a mixInputs/RF_inputs element, "
f"two lists should be provided"
f"{qe} is a mixInputs/RF_inputs element, " f"two lists should be provided"
)

assert len(samples[0]) == len(
Expand Down Expand Up @@ -987,10 +945,7 @@ def ramp(self, amp: float, duration: int, qe: str) -> None:
ramp_sample = [amp * t for t in range(duration)]
if "singleInput" in self._local_config["elements"][qe]:
self._samples_dict[qe]["single"] += ramp_sample
elif (
"mixInputs" in self._local_config["elements"][qe]
or "RF_inputs" in self._local_config["elements"][qe]
):
elif "mixInputs" in self._local_config["elements"][qe] or "RF_inputs" in self._local_config["elements"][qe]:
self._samples_dict[qe]["Q"] += ramp_sample
self._samples_dict[qe]["I"] += [0] * duration
self._update_qe_time(qe, duration)
Expand Down
20 changes: 5 additions & 15 deletions qualang_tools/config/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,23 +420,13 @@ 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

assert len(self.element_analog_inputs) <= 2
self.type = (
"singleInput" if len(self.element_analog_inputs) == 1 else "mixInputs"
)
self.type = "singleInput" if len(self.element_analog_inputs) == 1 else "mixInputs"
self.mixer: Mixer = mixer

if len(self.element_analog_inputs) > 0:
Expand Down
23 changes: 5 additions & 18 deletions qualang_tools/external_frameworks/qcodes/opx_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,7 @@ def open_qm(self, close_other_machines: bool):
Open a quantum machine with a given configuration ready to execute a program.
Beware that each call will close the existing quantum machines and interrupt the running jobs.
"""
self.qm = self.qmm.open_qm(
self.config, close_other_machines=close_other_machines
)
self.qm = self.qmm.open_qm(self.config, close_other_machines=close_other_machines)
self.qm_id = self.qm.id

def update_qm(self):
Expand Down Expand Up @@ -423,9 +421,7 @@ def get_measurement_parameter(self, scale_factor=((),)):
self.axis1_stop(int(self.readout_pulse_length()))
self.axis1_step(1)
self.axis1_npoints(int(self.readout_pulse_length()))
self.axis1_full_list(
np.arange(self.axis1_start(), self.axis1_stop(), self.axis1_step())
)
self.axis1_full_list(np.arange(self.axis1_start(), self.axis1_stop(), self.axis1_step()))
self.axis1_axis.unit = "ns"
self.axis1_axis.label = "Readout time"
# Rescale the results if a scale factor is provided
Expand Down Expand Up @@ -487,9 +483,7 @@ def get_measurement_parameter(self, scale_factor=((),)):
setpoint_labels=((),) * len(self.results["names"]),
)

def update_readout_length(
self, readout_element: str, readout_operation: str, new_length: int
):
def update_readout_length(self, readout_element: str, readout_operation: str, new_length: int):
"""
Update the readout length of a given readout operation and readout element.
This only works if the corresponding integration weights are constant.
Expand Down Expand Up @@ -568,12 +562,7 @@ def live_plotting(self, results_to_plot: list = (), number_of_runs: int = 0):

else:
# Convert the results into Volts
data = (
-data[-1]
* 4096
/ int(self.readout_pulse_length())
* self.demod_factor
)
data = -data[-1] * 4096 / int(self.readout_pulse_length()) * self.demod_factor
# Plot results
if len(data.shape) == 1:
if len(results_to_plot) > 1:
Expand All @@ -592,9 +581,7 @@ def live_plotting(self, results_to_plot: list = (), number_of_runs: int = 0):
plt.title(results_to_plot[i] + " [V]")
i += 1

plt.suptitle(
f"Iteration: {progress}/{number_of_runs} = {progress / number_of_runs * 100:.1f} %"
)
plt.suptitle(f"Iteration: {progress}/{number_of_runs} = {progress / number_of_runs * 100:.1f} %")
plt.pause(1)
plt.tight_layout()

Expand Down
8 changes: 2 additions & 6 deletions qualang_tools/units/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,7 @@ def raw2volts(self, data: Union[float, ndarray]) -> Union[float, ndarray]:
return data * self.V / 4096

@staticmethod
def volts2dBm(
Vp: Union[float, ndarray], Z: Union[float, int] = 50
) -> Union[float, ndarray]:
def volts2dBm(Vp: Union[float, ndarray], Z: Union[float, int] = 50) -> Union[float, ndarray]:
"""Converts the peak voltage (amplitude) from volts to dBm.
:param Vp: the peak voltage (amplitude) in volts. Must be a python variable or array.
Expand All @@ -223,9 +221,7 @@ def volts2dBm(
return 10 * log10(((Vp / sqrt(2)) ** 2 * 1000) / Z)

@staticmethod
def dBm2volts(
P_dBm: Union[float, ndarray], Z: Union[float, int] = 50
) -> Union[float, ndarray]:
def dBm2volts(P_dBm: Union[float, ndarray], Z: Union[float, int] = 50) -> Union[float, ndarray]:
"""Converts the power from dBm to volts (peak voltage or amplitude).
:param P_dBm: the power in dBm. Must be a python variable or array.
Expand Down

0 comments on commit b12fe6a

Please sign in to comment.