A Model is an object that can be run. It is generally used to define algorithms or process.

A model has inputs, outputs and an internal state. Inputs and outputs are used to allow communication between environnement and models and between models. Internal state is used by the model itself but cannot be reached from outside. This internal step is generally used when user want to execute model step by step, each step depending on previous one.

To define model instructions, you need to define at least "step" instructions. To do that, you can use:

To use a Model, you also need to define set_code method that is able to extract inputs, outpus and step, init, ... from given source code.

Animate notification are not yet implemented.

To reset internal state, use init() method. To run one step, use step() method.

Two convenience methods, see run() and "call" can be used to reset internal state and run a given number of step (one by default)

By default, functions are generated for "init", "run" and "animate"

class core.model.IModel(**kwds)[source]

Bases: object

animate(*args, **kwargs)[source]

Like run but send notification at each step.

init(*args, **kwargs)[source]

Reset internal state, fill namespace and run "init code" if defined.

run(*args, **kwargs)[source]

Init model and run "nstep" step(s).

set_code(code)[source]

extract and set inputs, outputs and functions from code. For example, if "code" is:

'''
input = a, b:int=5
output = c
'''
def step():
    c = a+b

you can extract input, output and step function. So, m = Model("m1") m.set_code(code)

is equivalent to

m = Model("m1") m.set_func_code("step", "c=a+b") m.inputs_info = [InputObj('a'), InputObj('b:int=5')] m.outputs_info = [OutputObj('c')]

set_func_code(fname, code)[source]
Parameters:
  • fname -- function name: "step", "init", "animate", ...
  • code -- python source code
set_step_code(code)[source]

convenience method equivalent to set_func_code("step", code)

step(*args, **kwargs)[source]

run "step code" if defined.

stop(*args, **kwargs)[source]

Stop execution.

dtype = None
mimetype = None
class core.model.Model(name=None, **kwds)[source]

Bases: object

animate(*args, **kwds)[source]
eval_value(value)[source]
execute(code)[source]
get_documentation()[source]
Returns:a string with the documentation of the model
init(*args, **kwds)[source]
inputs_from_ns(inputs, ns, *args, **kwargs)[source]
output_from_ns(namespace)[source]

Get outputs from namespace and set them inside self.outputs

Parameters:namespace -- dict where the model will search the outputs
repr_code()[source]
run(*args, **kwds)[source]
run_code(code, namespace)[source]
set_code(code)[source]
set_func_code(fname, code)[source]
set_step_code(code)[source]
step(*args, **kwds)[source]
code
icon = ''
step_code[source]
class core.model.PythonModel(**kwargs)[source]

Bases: core.model.Model

get_documentation()[source]
Returns:a string with the documentation of the model
repr_code()[source]
set_code(code)[source]
default_name = 'Python'
dtype = 'Python'
mimetype = 'text/x-python'

Previous topic

<no title>

Next topic

<no title>

This Page