-
Notifications
You must be signed in to change notification settings - Fork 82
Report offending input in channels module error messages #1102
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -221,7 +221,8 @@ def __post_init__(self) -> None: | |||||
| parameters += local_only | ||||||
| if self.propagation_dir is not None: | ||||||
| raise NotImplementedError( | ||||||
| "'propagation_dir' must be left as None in Local channels." | ||||||
| "'propagation_dir' must be left as None in Local " | ||||||
| f"channels; got {self.propagation_dir}." | ||||||
| ) | ||||||
|
|
||||||
| for param in parameters: | ||||||
|
|
@@ -444,18 +445,20 @@ def validate_duration(self, duration: int, round_up: bool = True) -> int: | |||||
| _duration = int(duration) | ||||||
| except (TypeError, ValueError): | ||||||
| raise TypeError( | ||||||
| "duration needs to be castable to an int but " | ||||||
| "type %s was provided" % type(duration) | ||||||
| "'duration' needs to be castable to an int; got " | ||||||
| f"{duration!r} of type {type(duration)}." | ||||||
| ) | ||||||
|
|
||||||
| if duration < self.min_duration: | ||||||
| raise ValueError( | ||||||
| "duration has to be at least " + f"{self.min_duration} ns." | ||||||
| f"'duration' has to be at least {self.min_duration} ns; " | ||||||
| f"got {duration}." | ||||||
| ) | ||||||
|
|
||||||
| if self.max_duration is not None and duration > self.max_duration: | ||||||
| raise ValueError( | ||||||
| "duration can be at most " + f"{self.max_duration} ns." | ||||||
| f"'duration' can be at most {self.max_duration} ns; " | ||||||
| f"got {duration}." | ||||||
| ) | ||||||
|
|
||||||
| if round_up and duration % self.clock_period != 0: | ||||||
|
|
@@ -482,25 +485,26 @@ def validate_pulse(self, pulse: Pulse) -> None: | |||||
| amp_samples_np = pulse.amplitude.samples.as_array(detach=True) | ||||||
| if self.max_amp is not None and np.any(amp_samples_np > self.max_amp): | ||||||
| raise ValueError( | ||||||
| "The pulse's amplitude goes over the maximum " | ||||||
| "value allowed for the chosen channel." | ||||||
| "The pulse's amplitude goes over the maximum value allowed " | ||||||
| f"for the chosen channel ({self.max_amp}); got " | ||||||
| f"{amp_samples_np.max()}." | ||||||
| ) | ||||||
| if self.max_abs_detuning is not None and np.any( | ||||||
| np.round( | ||||||
| if self.max_abs_detuning is not None: | ||||||
| abs_detuning = np.round( | ||||||
| np.abs(pulse.detuning.samples.as_array(detach=True)), | ||||||
| decimals=6, | ||||||
| ) | ||||||
| > self.max_abs_detuning | ||||||
| ): | ||||||
| raise ValueError( | ||||||
| "The pulse's detuning values go out of the range " | ||||||
| "allowed for the chosen channel." | ||||||
| ) | ||||||
| if np.any(abs_detuning > self.max_abs_detuning): | ||||||
| raise ValueError( | ||||||
| "The pulse's detuning values go out of the range allowed " | ||||||
| f"for the chosen channel ({self.max_abs_detuning}); got " | ||||||
| f"a maximum absolute value of {abs_detuning.max()}." | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Likewise, it is important to return the pulse in this error message
Suggested change
|
||||||
| ) | ||||||
| avg_amp = np.average(amp_samples_np) | ||||||
| if 0 < avg_amp < self.min_avg_amp: | ||||||
| raise ValueError( | ||||||
| "The pulse's average amplitude is below the chosen " | ||||||
| f"channel's limit ({self.min_avg_amp})." | ||||||
| f"channel's limit ({self.min_avg_amp}); got {avg_amp}." | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Likewise, it is important to return the pulse here
Suggested change
|
||||||
| ) | ||||||
|
|
||||||
| @property | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -161,7 +161,10 @@ def validate_pulse( | |||||
| ) | ||||||
| # Check that detuning is negative | ||||||
| if np.any(round_detuning > 0): | ||||||
| raise ValueError("The detuning in a DMM must not be positive.") | ||||||
| raise ValueError( | ||||||
| "The detuning in a DMM must not be positive; got a maximum " | ||||||
| f"of {round_detuning.max()}." | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe what matters here is the detuning of the pulse (maybe not necessarily the pulse, as it's a DMM)
Suggested change
|
||||||
| ) | ||||||
| # Check that detuning on each atom is above bottom_detuning | ||||||
| min_round_detuning = np.min(round_detuning) | ||||||
| max_weight = np.max(detuning_map.weights) | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -175,8 +175,8 @@ def __post_init__(self) -> None: | |||||
| if not isinstance(self.controlled_beams, tuple): | ||||||
| if not isinstance(self.controlled_beams, list): | ||||||
| raise TypeError( | ||||||
| "The 'controlled_beams' must be provided as a tuple " | ||||||
| "or list." | ||||||
| "The 'controlled_beams' must be provided as a tuple or " | ||||||
| f"list, not {type(self.controlled_beams)}." | ||||||
| ) | ||||||
| # Convert list to tuple to keep RydbergEOM hashable | ||||||
| object.__setattr__( | ||||||
|
|
@@ -192,7 +192,7 @@ def __post_init__(self) -> None: | |||||
| ): | ||||||
| raise TypeError( | ||||||
| "Every beam must be one of options of the `RydbergBeam`" | ||||||
| f" enumeration, not {self.limiting_beam}." | ||||||
| f" enumeration, not {beam}." | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch! Actually, I think it would be more interesting to say which attribute has an incorrect type. Perhaps we could use a dict instead of a chain, having {"limiting_beam":self.limiting_beam, "controlled_beams":self.controlled_beams} and
Suggested change
|
||||||
| ) | ||||||
|
|
||||||
| @property | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should specify the pulse that generated this error.