Skip to content

Commit

Permalink
model template for creating models
Browse files Browse the repository at this point in the history
  • Loading branch information
JortGroen committed Dec 16, 2024
1 parent 4d18830 commit 3838133
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/illuminator/models/model_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from illuminator.builder import IlluminatorModel, ModelConstructor

# construct the model
class Modelname(ModelConstructor):

# Define the model parameters, inputs, outputs...
# all parameters will be directly available as attributes
parameters={'param1': 1,
'param2': 'value2'
}
inputs={'in1': 0
}
outputs={'out1': 0
}
states={'out1': 0
}

# define other attributes
time_step_size=1
time=None

# define step function
def step(self, time, inputs, max_advance=1) -> None: # step function always needs arguments self, time, inputs and max_advance. Max_advance needs an initial value.


input_data = self.unpack_inputs(inputs) # make input data easily accessible
self.time = time
eid = list(self.model_entities)[0] # there is only one entity per simulator, so get the first entity


# example logic, sets "out1" to be the result of adding input "in1" and parameter "param1"
self._model.outputs["out1"] = input_data['in1'] + self.param1


# return the time of the next step (time untill current information is valid)
return time + self._model.time_step_size


0 comments on commit 3838133

Please sign in to comment.