-
Notifications
You must be signed in to change notification settings - Fork 9
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
Declarative interface #195
base: develop
Are you sure you want to change the base?
Conversation
It's unclear from the description what level of functionality is affected: is this a breaking change, a fix, or a new feature? It is important when prioritizing the review process, so please add some additional description. Perhaps we should create a pull request template @artem-chupryna to standardize this? @LasseNT: |
|
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.
Thanks @LasseNT. I looked at the example and here're my comments.
|
||
with create_connections() as connections: | ||
# connect oscillators via the coupling | ||
items.oscillator1.coupling >> items.coupling.side1 |
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.
What is this >> operator?
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.
The >> or << operators are used as a short hand for connecting items.oscillator1.couplin with items.coupling.side1. Alternatives could be:
items.oscillator1.coupling.connect(items.coupling.side1)
connect(items.oscillator1.coupling, items.coupling.side1)
The intent is that when the user has familiarized with this syntax it is faster to read and produced a cleaner looking code
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 normally in programming languages >> or << refers to bit-shifts.
from numerous.engine.system import Subsystem, ConnectorTwoWay, ItemsStructure | ||
from numerous.declarative.specification import ScopeSpec, ItemsSpec, Module, EquationSpec | ||
from numerous.declarative.variables import Parameter, Constant, State | ||
from numerous.declarative.bus import Connector, create_connections, get_value_for, set_value_from |
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.
Do these new methods/classes have documentation already?
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.
They have a very basic docstring.
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.
can this docstring be expanded beyond the basic one?
|
||
self.mechanics.set_values(k=k) | ||
|
||
@EquationSpec(mechanics) |
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.
Why do you need @EquationSpec here and not @equation ?
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.
The equation spec allows passing of the instance of the ScopeSpec which internally adds the equation to the namespace mechanics. In this way the previous code of add_to_namespace can be omitted, while it is still explicit that the equation is connected to the namespace.
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.
could you add a parameter, 'equation_spec', to the @equation decorator instead of creating a new equation decorator?
|
||
|
||
if __name__ == "__main__": | ||
|
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 some description is needed, rather than only the code. Like what are we trying to solve here? And why do you chose this method over the "standard" numerous syntax with Subsystem etc.
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.
Yes, I think a dedicated documentation file introducing the concept should be added before the next release.
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.
Also there is a short bullet list in the description of this pull request.
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 suggest adding r""" strings at the top of the example, which can later be parsed by sphinx to create an example gallery. I think there's no time as the present, and best that we add this before the final approval. This is a major release after all.
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.
a late reply, but better late than never.
|
||
self.mechanics.set_values(k=k) | ||
|
||
@EquationSpec(mechanics) |
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.
could you add a parameter, 'equation_spec', to the @equation decorator instead of creating a new equation decorator?
|
||
with create_connections() as connections: | ||
# connect oscillators via the coupling | ||
items.oscillator1.coupling >> items.coupling.side1 |
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 normally in programming languages >> or << refers to bit-shifts.
|
||
|
||
if __name__ == "__main__": | ||
|
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 suggest adding r""" strings at the top of the example, which can later be parsed by sphinx to create an example gallery. I think there's no time as the present, and best that we add this before the final approval. This is a major release after all.
A more declarative interface to writing models are being developed.
The aim is to have: