Skip to content
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

Open
wants to merge 28 commits into
base: develop
Choose a base branch
from
Open

Declarative interface #195

wants to merge 28 commits into from

Conversation

LasseNT
Copy link
Collaborator

@LasseNT LasseNT commented Nov 10, 2022

A more declarative interface to writing models are being developed.

The aim is to have:

  • clearer models with less boilerplate
  • use declarations to allow static analysis of the models
  • Allow better debugging information during model development

@mrdobalina2k
Copy link
Collaborator

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:
Please create an example that can be followed, and fix the tests/linters that are failing. The example can at a later stage (post merging) be placed in an example gallery together with the other examples of use cases.

@LasseNT
Copy link
Collaborator Author

LasseNT commented Nov 24, 2022

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: Please create an example that can be followed, and fix the tests/linters that are failing. The example can at a later stage (post merging) be placed in an example gallery together with the other examples of use cases.
Hey @mrdobalina2k. Checks are passing now and I have added an example as per last commit. Please have a look and let me know if ok.

Copy link
Collaborator

@mrdobalina2k mrdobalina2k left a 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this >> operator?

Copy link
Collaborator Author

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

Copy link
Collaborator

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
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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)
Copy link
Collaborator

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 ?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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__":

Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator

@mrdobalina2k mrdobalina2k left a 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)
Copy link
Collaborator

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
Copy link
Collaborator

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__":

Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants