class ExampleProcess:
    """A process with complete interface for testing."""

    in_var = xs.variable(dims=["x", ("x", "y")], description="input variable")
    out_var = xs.variable(groups="example_group", intent="out")
    inout_var = xs.variable(intent="inout", converter=int)
    od_var = xs.on_demand()
    obj_var = xs.any_object(description="arbitrary object")

    in_foreign_var = xs.foreign(SomeProcess, "some_var")
    in_foreign_var2 = xs.foreign(AnotherProcess, "some_var")
    out_foreign_var = xs.foreign(AnotherProcess, "another_var", intent="out")
    in_foreign_od_var = xs.foreign(SomeProcess, "some_od_var")

    in_global_var = xs.global_ref("some_global_var")
    out_global_var = xs.global_ref("another_global_var", intent="out")

    group_var = xs.group("some_group")
    group_dict_var = xs.group_dict("some_group")

    other_attrib = attr.attrib(init=False, repr=False)
    other_attr = "this is not a xsimlab variable attribute"

    @od_var.compute
    def compute_od_var(self):
        return 0
예제 #2
0
    class Bar:
        var = xs.global_ref("global_var")
        idx = xs.global_ref("global_idx")
        obj = xs.global_ref("global_obj")

        actual = xs.variable(intent="out")

        def initialize(self):
            self.actual = self.var + self.obj * np.sum(self.idx)
예제 #3
0
def test_global_ref():
    with pytest.raises(ValueError, match="intent='inout' is not supported.*"):
        xs.global_ref("some_var", intent="inout")

    # test constructor
    @attr.attrs
    class Foo:
        some_var = xs.global_ref("some_var")
        another_var = xs.global_ref("another_var", intent="out")

    assert Foo(some_var=2).some_var == 2

    with pytest.raises(TypeError):
        # intent='out' not in constructor
        Foo(another_var=2)
예제 #4
0
def gen_properties(externs, modules, modulestoconsider = None, globaldependencies = {}, propertymapping = {}):
    """ Generate the properties of the xs Process class that will run the lpyfile """
    import numpy as np
    externs = externs.difference(predefined_variables)
    if not modulestoconsider is None:
        mmodules = dict()
        for name, pnames in modules.items():
            if name in modulestoconsider:
                mmodules[name] = pnames
        modules = mmodules
    properties = {}
    properties['modules'] = modules
    for m, v in modules.items():
        properties[m] = xs.index(dims=m)
        for p in v:
            pname = m+'_'+p
            properties[pname] = propertymapping.get(pname,
                                    xs.global_ref(pname, intent='in')
                                    if pname in globaldependencies else
                                    xs.variable( dims=m, intent='out', encoding={'dtype': np.float}))
    properties['globaldependencies'] = globaldependencies
    properties['externs'] = externs
    for e in externs:
        properties[e] = xs.variable()
    return properties
예제 #5
0
 class Bar:
     var = xs.global_ref("global_var")
예제 #6
0
 class NotFound:
     var = xs.global_ref("missing")
예제 #7
0
 class Foo:
     some_var = xs.global_ref("some_var")
     another_var = xs.global_ref("another_var", intent="out")