镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

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

Closed

Description

@benbovy

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).

Activity

  1. added this to the 0.3 milestone on May 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions