step delay
tau = 3
blocks that define the system
Src = Source(lambda t: int(t>tau))
Int = Integrator()
Amp = Amplifier(-1)
Add = Adder()
Sco = Scope(labels=["step", "response"])
blocks = [Src, Int, Amp, Add, Sco]
the connections between the blocks
connections = [
Connection(Src, Add[0], Sco[0]),
Connection(Amp, Add[1]),
Connection(Add, Int),
Connection(Int, Amp, Sco[1])
]
initialize simulation with the blocks, connections, timestep and logging enabled
Sim = Simulation(blocks, connections, dt=dt, log=True)
print(Sim)
becomes this:
code
{
"metadata": {
"name": "Model",
"description": "",
"created": "2025-02-28T21:13:42.847434"
},
"blocks": [
{
"id": "2037130594352",
"type": "Source",
"params": {
"func": {
"type": "lambda",
"name": "<lambda>",
"source": "lambda t: int(t>tau))",
"globals": {
"tau": 3
},
"closures": {}
}
}
},
{
"id": "2037130594688",
"type": "Integrator",
"params": {
"initial_value": 0.0
}
},
{
"id": "2037130595024",
"type": "Amplifier",
"params": {
"gain": -1
}
},
{
"id": "2037130595360",
"type": "Adder",
"params": {}
},
{
"id": "2037130595696",
"type": "Scope",
"params": {
"sampling_rate": null,
"t_wait": 0.0,
"labels": [
"step",
"response"
]
}
}
],
"connections": [
{
"id": "2037130596032",
"source": {
"block": "2037130594352",
"port": 0
},
"targets": [
{
"block": "2037130595360",
"port": 0
},
{
"block": "2037130595696",
"port": 0
}
]
},
{
"id": "2037129492624",
"source": {
"block": "2037130595024",
"port": 0
},
"targets": [
{
"block": "2037130595360",
"port": 1
}
]
},
{
"id": "2037129493584",
"source": {
"block": "2037130595360",
"port": 0
},
"targets": [
{
"block": "2037130594688",
"port": 0
}
]
},
{
"id": "2037130549568",
"source": {
"block": "2037130594688",
"port": 0
},
"targets": [
{
"block": "2037130595024",
"port": 0
},
{
"block": "2037130595696",
"port": 1
}
]
}
],
"events": [],
"simulation": {
"dt": 0.02,
"dt_min": 1e-16,
"dt_max": null,
"solver": "SSPRK22",
"tolerance_fpi": 1e-12,
"iterations_min": 2,
"iterations_max": 200
}
}
In the future this will be utilized for saving simulations and models to and loading them from external files that are readable and editable.