Skip to content

Implicitly link processes with "public" variables #142

@ethho

Description

@ethho

TL;DR

Add a variable type xsimlab.public that allows for implicit process linking.


I am a relatively new user of this package. When I first started learning about it, I noticed that there was one aspect of xsimlab design that was unexpected:

from another_class import AnotherClass

xsimlab.foreign(AnotherClass, 'my_var')

In other words, the user must explicitly link two processes. This approach has many benefits as explained in the docs. A major detriment to this approach, however, is significantly reduced modularity and reusability of the user-defined processes. For example, let's consider the minimal use case:

@xs.process
class DefaultInput:
    some_input = xs.foreign(UseInput, 'some_input', intent='out')

    def initialize(self):
        self.some_input = 'foo'

@xs.process
class UseInput:
    some_input = xs.variable(intent='in')

Replacing the DefaultInput process with a InputFromFile process requires updates to every other linked process. In this simple case, we only need to do this for UseInput, but for larger connected networks of processes this is non-trivial.

My proposal (a mere point of discussion at this stage) is addition of a new public variable type:

@xs.process
class DefaultInput:
    # Very similar to xs.foreign!
    some_input = xs.public('unique_name', intent='out')

    def initialize(self):
        self.some_input = 'foo'

@xs.process
class UseInput:
    some_input = xs.variable(name='unique_name', public=True, intent='in')

Replacing DefaultInput with InputFromFile is now trivial, even for large scale use cases. A public variable is processed at the model scope, so it can be read or provided by any other process in the model. The group variable type already behaves this way (if I'm reading the package code right), except that intent='in' is required for group variables only. A group variable would be a special case of public variable.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions