-
Notifications
You must be signed in to change notification settings - Fork 16
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
Classes to compute active/reactive power loads of the Coil Power Supply System #2967
base: feature/powercycle
Are you sure you want to change the base?
Conversation
57cc8b6
to
d620c38
Compare
d620c38
to
c40e519
Compare
bluemira/power_cycle/coilsupply.py
Outdated
subclass_name = "CoilSupplyParameter" | ||
single_value_types = (bool, int, float, list, tuple, np.ndarray) | ||
|
||
@classmethod | ||
def validate_parameter(cls, obj): | ||
""" | ||
Validate 'obj' to be of the same class as the object testing it. | ||
|
||
Substitute method for 'isinstance', since it fails in this | ||
implementation. | ||
""" | ||
return obj.__class__.__name__ == cls.__name__ | ||
|
||
@classmethod | ||
def init_subclass(cls, argument: Any = None): | ||
""" | ||
Create a 'CoilSupplyParameter' subclass instance from argument. | ||
|
||
If 'None' is given to instantiate the class, an empty instance | ||
is created. | ||
If an object of this class is given to instantiate the class, it | ||
is returned as is. | ||
If a 'dict' is given to instantiate the class, keys must match | ||
class attributes and their values are distributed. | ||
If a value of one of the 'single_value_types' classes is given | ||
to instantiate the class, copy that value to all attributes. | ||
""" | ||
if argument is None: | ||
return cls() | ||
if cls.validate_parameter(argument): | ||
return argument | ||
if isinstance(argument, dict): | ||
return cls(**argument) | ||
if isinstance(argument, cls.single_value_types): | ||
args = {} | ||
all_fields = fields(cls) | ||
for one_field in all_fields: | ||
args[one_field.name] = argument | ||
return cls(**args) | ||
raise ValueError( | ||
"A 'CoilSupplyParameter' instance must be initialized " | ||
f"with 'None' for an empty instance, a '{cls.__name__}' " | ||
"instance for no alteration, a 'dict' for a distributed " | ||
"instantiation or any of the following types for a " | ||
f"single-value instantiation: {cls.single_value_types}. " | ||
f"Argument was '{type(argument)}' instead." | ||
) |
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.
None of this is needed please remove, its over complicating things again
subclass_name = "CoilSupplyParameter" | |
single_value_types = (bool, int, float, list, tuple, np.ndarray) | |
@classmethod | |
def validate_parameter(cls, obj): | |
""" | |
Validate 'obj' to be of the same class as the object testing it. | |
Substitute method for 'isinstance', since it fails in this | |
implementation. | |
""" | |
return obj.__class__.__name__ == cls.__name__ | |
@classmethod | |
def init_subclass(cls, argument: Any = None): | |
""" | |
Create a 'CoilSupplyParameter' subclass instance from argument. | |
If 'None' is given to instantiate the class, an empty instance | |
is created. | |
If an object of this class is given to instantiate the class, it | |
is returned as is. | |
If a 'dict' is given to instantiate the class, keys must match | |
class attributes and their values are distributed. | |
If a value of one of the 'single_value_types' classes is given | |
to instantiate the class, copy that value to all attributes. | |
""" | |
if argument is None: | |
return cls() | |
if cls.validate_parameter(argument): | |
return argument | |
if isinstance(argument, dict): | |
return cls(**argument) | |
if isinstance(argument, cls.single_value_types): | |
args = {} | |
all_fields = fields(cls) | |
for one_field in all_fields: | |
args[one_field.name] = argument | |
return cls(**args) | |
raise ValueError( | |
"A 'CoilSupplyParameter' instance must be initialized " | |
f"with 'None' for an empty instance, a '{cls.__name__}' " | |
"instance for no alteration, a 'dict' for a distributed " | |
"instantiation or any of the following types for a " | |
f"single-value instantiation: {cls.single_value_types}. " | |
f"Argument was '{type(argument)}' instead." | |
) |
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.
Hi @je-cook,
this one is a bit more complicated than that... I have made a "dataclass factory" to create dataclasses to store vectors for a CoilSupplySystem
object. This ensures the dataclass has one vector for each coil defined in the CoilSupplySystem
. These methods are not so much for validation, but rather automatized creation of these containers. I call the related methods "validation" but they are used to instantiate the container objects independent of the input so maybe the term is not the most appropriate.
In short, the workflow is as follows:
- a
CoilSupplyInputs
object is initialized, with a certain list of coils inconfig.coil_names
- this automatically specifies what fields the container dataclass must have, so a
CoilSupplyParameter
class is defined as child ofCoilSupplyParameterABC
, and stored in theparameter
attribute ofCoilSupplyInputs
- a
CoilSupplySystem
object is initialized with theCoilSupplyInputs
object, so all methods that need to create a container can do it easily, either empty (full ofNone
values) or passing an object tovalidate_parameter
... dictionaries are distributed in the dataclass, other objects are just copied.
Perhaps that's not the best way to do this, but this was meant to be discussed with you and @oliverfunk
Let me know what you think,
bluemira/power_cycle/coilsupply.py
Outdated
if self.validate_parameter(other): | ||
other_value = getattr(other, one_field.name) |
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.
stop validating
if self.validate_parameter(other): | |
other_value = getattr(other, one_field.name) |
e929c15
to
a2ed0f0
Compare
a2ed0f0
to
bfed83d
Compare
9576e11
to
be9c3dc
Compare
5905d59
to
8a699ab
Compare
be9c3dc
to
4fc3da8
Compare
Quality Gate passedIssues Measures |
9ae94a0
to
b43893d
Compare
b43893d
to
0d0e724
Compare
4b7d1c4
to
fd885c4
Compare
@je-cook, I assume this one should also be rebased on |
Quality Gate passedIssues Measures |
dd2df2b
to
12564fa
Compare
@tplobo can this be rebase on top of feature/powercycle please? It a bit impossible to review at the moment |
…rameter` and `verbose` argument to `compute_wallplug_loads`
…ere rms is calculated
…ms_deviation` implementation
…ix typo in coilsupply test
f1857da
to
e3891f1
Compare
Quality Gate passedIssues Measures |
@je-cook, I have followed your instructions, but as I mentioned I had to make some corrections while interactively merging due to some conflicts; I've run my tests but you might encounter a bug or another. I have also added the IDM files used in verification as ignored files in a local |
Linked Issues
Closes #3017.
Description
Interface Changes
Checklist
I confirm that I have completed the following checks:
pytest tests --reactor
pre-commit run --from-ref develop --to-ref HEAD
sphinx-build -W documentation/source documentation/build