Hope this issue finds you well
I'm still working on my simulation project, and find another issue which prevents sequential simulation caused by the global cache defined as dict OperatorTemplate.cache.
My code involves simulation with different durations, thus, I need to create stimulation patterns with different length. The code looks like the following:
# First time, 5 seconds of simulation
arrStimPattern = CreateStimWave(dDuration=5)
jrcModel = CreateStandardJRC()
dctResult = jrcModel.run(
simulation_time=5.0,
step_size=1e-4,
sampling_step_size=1.0/500.0,
inputs={
"PATH/TO/INPUT/SIG" : arrStimPattern
},
# Outputs ignored
clear=True,
verbose=False
)
# Data postprocessing & plotting
# Second time, 200 seconds of simulation
arrStimPattern = CreateStimWave(dDuration=200)
jrcModel = CreateStandardJRC()
dctResult = jrcModel.run(
simulation_time=200.0,
step_size=1e-4,
sampling_step_size=1.0/500.0,
inputs={
"PATH/TO/INPUT/SIG" : arrStimPattern
},
# Outputs ignored
clear=True,
verbose=False
)
# Data postprocessing & plotting
The first simulation ends successfully. However, when running the second simulation, the simulator crashes and says:
IndexError: index 50000 is out of bounds for axis 0 with size 50000
After checking my own code, I'm very sure that the length of stimulation pattern generated by CreateStimWave() function is Okay. I also found that if I run the simulation in a child process with concurrent.futures.ProcessPoolExecutor() sequentially, it works fine.
Then, I used a debugger to follow the code path. When leaving the in_op = OperatorTemplate(...) line in create_input_node() (called by CircuitTemplate._add_input()) during second simulation, the length of input signal goes wrong in the NodeTemplate instance created. It's still using the value stored in global static cache OperatorTemplate.cache, and CircuitTemplate.clear() won't clear it.
I modified CircuitTemplate.clear(), adding a line before gc.collect():
OperatorTemplate.cache.clear()
Now, the sequential simulation works fine.
Hope this issue finds you well
I'm still working on my simulation project, and find another issue which prevents sequential simulation caused by the global cache defined as dict
OperatorTemplate.cache.My code involves simulation with different durations, thus, I need to create stimulation patterns with different length. The code looks like the following:
The first simulation ends successfully. However, when running the second simulation, the simulator crashes and says:
After checking my own code, I'm very sure that the length of stimulation pattern generated by
CreateStimWave()function is Okay. I also found that if I run the simulation in a child process withconcurrent.futures.ProcessPoolExecutor()sequentially, it works fine.Then, I used a debugger to follow the code path. When leaving the
in_op = OperatorTemplate(...)line increate_input_node()(called byCircuitTemplate._add_input()) during second simulation, the length of input signal goes wrong in theNodeTemplateinstance created. It's still using the value stored in global static cacheOperatorTemplate.cache, andCircuitTemplate.clear()won't clear it.I modified
CircuitTemplate.clear(), adding a line beforegc.collect():Now, the sequential simulation works fine.