-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor calc #44
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
Refactor calc #44
Changes from all commits
a20b7ec
d977d75
74e129c
0c47e78
7b5a82b
1b3ad46
ecf31b4
d404add
ed4acc9
61dc316
870c418
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 |
|---|---|---|
| @@ -1,116 +1,21 @@ | ||
| """Interface to different QSE calculators.""" | ||
|
|
||
| __all__ = ["abc", "calculator", "signal"] | ||
| from typing import Union | ||
| __all__ = [ | ||
| "calculator", | ||
| "Signal", | ||
| "PropertyNotImplementedError", | ||
| "PropertyNotPresent", | ||
| "CalculatorSetupError", | ||
| "CalculationFailed", | ||
| ] | ||
|
|
||
| import qse.calc.abc | ||
| import qse.calc.calculator | ||
|
|
||
|
Collaborator
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. This and content below goes into
Contributor
Author
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. All the Error classes defined in |
||
| np = qse.np | ||
|
|
||
|
|
||
| class signal(object): | ||
| """ | ||
| signal class to represent a a signal with a duration. | ||
| It has two components: values, and duration. | ||
| Instantiation of this class supports '+' in two ways. | ||
| If w1, w2 are instantiation of signal, then | ||
| - w1 + 3 gives a signal with values, w1.values + 3 and | ||
| same duration. | ||
| - w = w1 + w2 gives signal with concatenated values, i.e., | ||
| w.values = [w1.values, w2.values], and added duration. | ||
| w.duration = w1.duration + w2.duration | ||
| Note: Currently, the object gets created for multi-dim | ||
| arrays as well. However, it should be used for 1D only, | ||
| we haven't made it useful or consistent for multi-dim usage. | ||
| """ | ||
|
|
||
| # | ||
| # __slots__ = ('duration', 'values') | ||
| def __init__(self, values, duration=None) -> None: | ||
| self.values = np.asarray(values) | ||
| self._duration = len(self.values) if duration is None else int(duration) | ||
|
|
||
| # | ||
| @property | ||
| def duration(self): | ||
| """time duration of signal""" | ||
| return self._duration | ||
|
|
||
| @duration.setter | ||
| def duration(self, value): | ||
| self._duration = value | ||
|
|
||
| def __iter__(self): | ||
| return iter(self.values) | ||
|
|
||
| # | ||
| def __getitem__(self, i): | ||
| return self.values[i] | ||
|
|
||
| # | ||
| def __eq__(self, other) -> bool: | ||
| return (self.duration == other.duration) and (self.values == other.values).all() | ||
|
|
||
| # | ||
| def __add__(self, other): | ||
| if isinstance(other, signal): | ||
| res = signal( | ||
| values=np.append(self.values, other.values), | ||
| duration=self.duration + other.duration, | ||
| ) | ||
| else: | ||
| if isinstance(other, Union[float, int]): | ||
| res = signal(values=self.values + other, duration=self.duration) | ||
| else: | ||
| raise TypeError(f"wrong type for operand {type(other)}") | ||
| return res | ||
|
|
||
| # | ||
| def __radd__(self, other): | ||
| return self.__add__(other) | ||
|
|
||
| # | ||
| def __iadd__(self, other): | ||
| if isinstance(other, signal): | ||
| self.values = np.append(self.values, other.values) | ||
| self.duration += other.duration | ||
| else: | ||
| if isinstance(other, Union[float, int]): | ||
| self.values += other | ||
| else: | ||
| raise TypeError(f"wrong type for operand {type(other)}") | ||
| return self | ||
|
|
||
| # | ||
| def __mul__(self, other): | ||
| if isinstance(other, Union[float, int]): | ||
| res = signal(values=self.values * other, duration=self.duration) | ||
| else: | ||
| raise TypeError(f"wrong type for operand {type(other)}") | ||
| return res | ||
|
|
||
| # | ||
| def __rmul__(self, other): | ||
| return self.__mul__(other) | ||
|
|
||
| # | ||
| def __imul__(self, other): | ||
| if isinstance(other, Union[float, int]): | ||
| self.values *= other | ||
| else: | ||
| raise TypeError(f"wrong type for operand {type(other)}") | ||
| return self | ||
|
|
||
| # | ||
| def __repr__(self) -> str: | ||
| return f"signal(duration={self.duration}, values={self.values})" | ||
|
|
||
| # we need to define interpolating scheme to resample points if duration is changed externally. | ||
|
|
||
|
|
||
| # | ||
| from qse.calc.messages import ( | ||
| CalculationFailed, | ||
| CalculatorSetupError, | ||
| PropertyNotImplementedError, | ||
| PropertyNotPresent, | ||
| ) | ||
|
|
||
| from .myqlm import Myqlm | ||
| from .pulser import Pulser | ||
This file was deleted.
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.
looks good