I am using version 0.16.4
When using the reset method for the simulation, the StepSource blocks no longer behaved as expected. They only output a value of zero and did not "step". I found this while working on parameter fitting using repeated runs of the simulation model.
I found a way to make this work by modifying the reset method in _block.py. I used a kwarg defaulting to false so that this doesn't introduce unwanted behavior elsewhere.
def reset(self, reset_events=False):
"""Reset the blocks inputs and outputs and also its internal solver,
if the block has a solver instance.
"""
#reset inputs and outputs
self.inputs.reset()
self.outputs.reset()
#reset engine if block has solver
if self.engine: self.engine.reset()
#reset operators if defined
if self.op_alg: self.op_alg.reset()
if self.op_dyn: self.op_dyn.reset()
#reset events (re-arm event schedulers with a kwarg for backwards compatibility)
if reset_events:
for event in self.events:
event.reset()
Here is how to recreate the issue:
from pathsim import Simulation, Connection
from pathsim.blocks import StepSource, Scope
from pathsim.solvers import SSPRK22
step = StepSource(amplitude=1.0, tau=1.0)
scope = Scope()
sim = Simulation([step, scope], [Connection(step[0], scope[0])], Solver=SSPRK22, dt=0.1)
# First run works
sim.run(duration=5.0)
t1, y1 = scope.read()
print(f"First run: max={y1.max()}") # Should be 1
# Second run after reset produces zeros
sim.reset(time=0.0)
sim.run(duration=5.0)
t2, y2 = scope.read()
print(f"Second run: max={y2.max()}") # This is now 0 (BUG)
I am using version 0.16.4
When using the reset method for the simulation, the StepSource blocks no longer behaved as expected. They only output a value of zero and did not "step". I found this while working on parameter fitting using repeated runs of the simulation model.
I found a way to make this work by modifying the reset method in _block.py. I used a kwarg defaulting to false so that this doesn't introduce unwanted behavior elsewhere.
Here is how to recreate the issue: