Skip to content

Allow flexible signatures for simulation runtime methods in process classes #40

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

Closed
benbovy opened this issue May 8, 2018 · 0 comments · Fixed by #59
Closed

Allow flexible signatures for simulation runtime methods in process classes #40

benbovy opened this issue May 8, 2018 · 0 comments · Fixed by #59
Milestone

Comments

@benbovy
Copy link
Member

benbovy commented May 8, 2018

Currently, the signatures of all process runtime methods are implicitly fixed. Among these, only .run_step(self, dt) accepts one more argument than just self (it corresponds to the current time step duration).

However, in other (potentially many) cases, additional runtime information (such as, e.g., the current time t) may be needed too. This information might be needed in other methods like .finalize_step() as well.

So, how to make available this information as additional method arguments in next releases without breaking the signatures of all methods in existing users' codes? How to be more flexible in the signature of those methods?

I see two options:

  • A. Always use **kwargs, e.g.,
@xsimlab.process
class Diffusion(object):

    def run_step(self, **kwargs):
        # use kwargs['time_step'] and/or kwargs['time']
  • B. Provide an optional decorator to clarify the signature, e.g.,
@xsimlab.process
class Diffusion(object):

    @xsimlab.runtime_args('time,time_step')
    def run_step(self, t, dt):
        # use t or dt

IMO option B looks better. By default, if a method is not decorated then it should not accept any other argument than self. As a temporary exception (with depreciation warning), .run_step would still accept a default signature (self, dt).

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 a pull request may close this issue.

1 participant