Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed May 27, 2024
1 parent 917e9ba commit 0719f15
Showing 1 changed file with 53 additions and 33 deletions.
86 changes: 53 additions & 33 deletions src/qumada/measurement/measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def generate_lists(self) -> None:
self.buffers: set = set() # All buffers of gettable parameters
self.trigger_ins: set = set() # All trigger inputs that do not belong to buffers
self.priorities: dict = {}
self.loop: int = 0 #For usage with looped measurements
self.loop: int = 0 # For usage with looped measurements

Check warning on line 286 in src/qumada/measurement/measurement.py

View check run for this annotation

Codecov / codecov/patch

src/qumada/measurement/measurement.py#L286

Added line #L286 was not covered by tests

for gate, parameters in self.gate_parameters.items():
for parameter, channel in parameters.items():
Expand All @@ -309,8 +309,10 @@ def generate_lists(self) -> None:
try:
self.compensating_parameters_values.append(self.properties[gate][parameter]["value"])
except KeyError as e:
print(f"No value assigned for compensating parameter \
{self.compensating_parameters[-1]}")
print(

Check warning on line 312 in src/qumada/measurement/measurement.py

View check run for this annotation

Codecov / codecov/patch

src/qumada/measurement/measurement.py#L306-L312

Added lines #L306 - L312 were not covered by tests
f"No value assigned for compensating parameter \
{self.compensating_parameters[-1]}"
)
raise e
try:
leverarms = self.properties[gate][parameter]["leverarms"]
Expand All @@ -320,23 +322,26 @@ def generate_lists(self) -> None:
print(f"No leverarm specified for parameters {self.compensating_parameters[-1]}!")
raise e
try:
comp_list= []
comp_list = []
for entry in self.properties[gate][parameter]["compensated_gates"]:
assert isinstance(entry, dict)
comp_list.append({"gate": entry["terminal"],
"parameter": entry["parameter"]})
comp_list.append({"gate": entry["terminal"], "parameter": entry["parameter"]})
self.compensated_parameters.append(comp_list)
except KeyError as e:
print(f"The terminal to be compensated for with {self.compensating_parameters[-1]} \
print(

Check warning on line 331 in src/qumada/measurement/measurement.py

View check run for this annotation

Codecov / codecov/patch

src/qumada/measurement/measurement.py#L316-L331

Added lines #L316 - L331 were not covered by tests
f"The terminal to be compensated for with {self.compensating_parameters[-1]} \
is not properly specified! Make sure to define a dictionary with \
terminal and parameter as keys.")
terminal and parameter as keys."
)
raise e
try:
limits = self.properties[gate][parameter]["limits"]
self.compensating_limits.append(limits)
except KeyError as e:
print(f"No limits assigned to compensating parameter \
{self.compensating_parameters[-1]}!")
print(

Check warning on line 341 in src/qumada/measurement/measurement.py

View check run for this annotation

Codecov / codecov/patch

src/qumada/measurement/measurement.py#L336-L341

Added lines #L336 - L341 were not covered by tests
f"No limits assigned to compensating parameter \
{self.compensating_parameters[-1]}!"
)
raise e

Check warning on line 345 in src/qumada/measurement/measurement.py

View check run for this annotation

Codecov / codecov/patch

src/qumada/measurement/measurement.py#L345

Added line #L345 was not covered by tests

elif self.properties[gate][parameter]["type"].find("dynamic") >= 0:
Expand All @@ -345,8 +350,7 @@ def generate_lists(self) -> None:
if self.properties[gate][parameter].get("_is_triggered", False) and self.buffered:
if "num_points" in self.properties[gate][parameter].keys():
try:
assert self.properties[
gate][parameter]["num_points"] == self.buffered_num_points
assert self.properties[gate][parameter]["num_points"] == self.buffered_num_points
except AssertionError:
logger.warning(
f"Number of datapoints from buffer_settings\
Expand All @@ -356,8 +360,7 @@ def generate_lists(self) -> None:
)
elif "setpoints" in self.properties[gate][parameter].keys():
try:
assert len(
self.properties[gate][parameter]["setpoints"]) == self.buffered_num_points
assert len(self.properties[gate][parameter]["setpoints"]) == self.buffered_num_points
except AssertionError:
logger.warning(
f"Number of datapoints from buffer_settings\
Expand Down Expand Up @@ -423,8 +426,7 @@ def generate_lists(self) -> None:
if self.groups[group]["priority"] in self.priorities.keys():
raise Exception("Assigned the same priority to multiple groups")
elif self.groups[group]["priority"] is None:
self.groups[group]["priority"] = int(
self.properties[gate][parameter]["priority"])
self.groups[group]["priority"] = int(self.properties[gate][parameter]["priority"])
self.priorities[int(self.groups[group]["priority"])] = self.groups[group]
else:
try:
Expand Down Expand Up @@ -617,11 +619,13 @@ def initialize(self, dyn_ramp_to_val=False, inactive_dyn_channels: list | None =
try:
i = self.compensating_parameters.index({"gate": gate, "parameter": parameter})
leverarms = self.compensating_leverarms[i]
comped_params = copy.deepcopy(self.compensated_parameters[i]) #list of parameters compensated by the current parameter
comped_params = copy.deepcopy(

Check warning on line 622 in src/qumada/measurement/measurement.py

View check run for this annotation

Codecov / codecov/patch

src/qumada/measurement/measurement.py#L618-L622

Added lines #L618 - L622 were not covered by tests
self.compensated_parameters[i]
) # list of parameters compensated by the current parameter
comped_sweeps = [] # Sweeps that are compensated by current param
comped_leverarms = [] # Leverarms of the current param
comping_sweeps = [] # List to store only the sweeps for the current param
k=0
comped_leverarms = [] # Leverarms of the current param
comping_sweeps = [] # List to store only the sweeps for the current param
k = 0
for comped_param in comped_params.copy():

Check warning on line 629 in src/qumada/measurement/measurement.py

View check run for this annotation

Codecov / codecov/patch

src/qumada/measurement/measurement.py#L625-L629

Added lines #L625 - L629 were not covered by tests
# Check if the parameter is actually ramped in this part of the measurement
if comped_param in inactive_dyn_params:
Expand All @@ -631,13 +635,15 @@ def initialize(self, dyn_ramp_to_val=False, inactive_dyn_channels: list | None =
try:
comped_index = self.dynamic_parameters.index(comped_param)
except ValueError as e:
logger.exception("Watch out, there is an Exception incoming!" +
"Did you try to compensate for a not dynamic parameter?")
logger.exception(

Check warning on line 638 in src/qumada/measurement/measurement.py

View check run for this annotation

Codecov / codecov/patch

src/qumada/measurement/measurement.py#L635-L638

Added lines #L635 - L638 were not covered by tests
"Watch out, there is an Exception incoming!"
+ "Did you try to compensate for a not dynamic parameter?"
)
raise e
comped_sweeps.append(self.dynamic_sweeps[comped_index])
comped_leverarms.append(leverarms[k])
self.active_compensated_channels.append(self.dynamic_channels[comped_index])
k+=1
k += 1
compensating_param = self.compensating_parameters[i]
self.active_compensating_parameters.append(compensating_param)
if len(comped_params) > 0:
Expand All @@ -646,20 +652,34 @@ def initialize(self, dyn_ramp_to_val=False, inactive_dyn_channels: list | None =
# Here we create lists/sweeps only containing the difference required for compensation.
# Still has to be substracted from the set value in the measurement script as this can depend
# on the measurement script used (e.g. 1D vs 2D sweeps)
comping_setpoints = -1*float(comped_leverarms[j])*(np.array(comped_sweeps[j].get_setpoints()) - comped_sweeps[j].get_setpoints()[0])
comping_setpoints = (

Check warning on line 655 in src/qumada/measurement/measurement.py

View check run for this annotation

Codecov / codecov/patch

src/qumada/measurement/measurement.py#L655

Added line #L655 was not covered by tests
-1
* float(comped_leverarms[j])
* (np.array(comped_sweeps[j].get_setpoints()) - comped_sweeps[j].get_setpoints()[0])
)
# This creates an inner list of required setpoint differences only for the param that is currently iterated over!
# The final self.compensating_sweeps list will contain list for each compensating parameters with one sweep per
# parameter that is compensated by this compensating parameters.
comping_sweeps.append(CustomSweep(
channel,
comping_setpoints,
delay=self.properties[gate][parameter].setdefault("delay", 0))
comping_sweeps.append(

Check warning on line 663 in src/qumada/measurement/measurement.py

View check run for this annotation

Codecov / codecov/patch

src/qumada/measurement/measurement.py#L663

Added line #L663 was not covered by tests
CustomSweep(
channel,
comping_setpoints,
delay=self.properties[gate][parameter].setdefault("delay", 0),
)
)
self.compensating_sweeps.append(comping_sweeps)
if any(
[self.properties[param["gate"]][param["parameter"]].get(
"_is_triggered", False) for param in comped_params]) and self.buffered:
self.properties[compensating_param["gate"]][compensating_param["parameter"]]["_is_triggered"] = True
if (

Check warning on line 671 in src/qumada/measurement/measurement.py

View check run for this annotation

Codecov / codecov/patch

src/qumada/measurement/measurement.py#L670-L671

Added lines #L670 - L671 were not covered by tests
any(
[
self.properties[param["gate"]][param["parameter"]].get("_is_triggered", False)
for param in comped_params
]
)
and self.buffered
):
self.properties[compensating_param["gate"]][compensating_param["parameter"]][

Check warning on line 680 in src/qumada/measurement/measurement.py

View check run for this annotation

Codecov / codecov/patch

src/qumada/measurement/measurement.py#L680

Added line #L680 was not covered by tests
"_is_triggered"
] = True
# TODO: This part has to be moved into the measurement script, as the final setpoints for the comping params
# are now set at the measurement script. A helper method would be nice to have.
# if min(self.compensating_sweeps[-1].get_setpoints()) < min(*self.compensating_limits[i]) or max(
Expand All @@ -674,7 +694,7 @@ def initialize(self, dyn_ramp_to_val=False, inactive_dyn_channels: list | None =
)
except ValueError as e:
raise e

Check warning on line 696 in src/qumada/measurement/measurement.py

View check run for this annotation

Codecov / codecov/patch

src/qumada/measurement/measurement.py#L695-L696

Added lines #L695 - L696 were not covered by tests

if self.buffered:
for gettable_param in list(set(self.gettable_channels) - set(self.static_gettable_channels)):
if is_bufferable(gettable_param):
Expand Down

0 comments on commit 0719f15

Please sign in to comment.