Closed NinaOmejc closed 1 year ago
Hi Nina,
thank you for giving PyRates a try and for bringing this to my attention!
Indeed, it is not supported at the moment to save non-state variables as output variables.
The issue with supporting non-state variables is that it leads to compatibility issues with external differential equation solving tools such as scipy.integrate.solve_ivp
. These tools require a function that returns only a state-vector which has the same dimensionality as the differential equation system that governs the dynamics.
I have been thinking of a way to include this feature, but have not yet found a way to do it without substantial drawbacks. At the moment, there are two work-arounds you could use:
(I) Store whatever state-variable you use your wrap function on as an output and manually apply the wrap function after the simulation.
OR
(II) Add an observer state variable to your model that tracks the dynamics of your variable of interest with a small low-pass filtering time constant. If you have a variable wrap
, you could include d/dt wrap_obs = (wrap-wrap_obs)/tau_obs
, where tau_obs
is smaller than any other time constant in your system.
Let me know if I can help any further!
Hi,
Ok, thank you for the information. I have been using the first option you mentioned, but as I saw the option to wrap angle theta in sinus function in your exemplary YAML model definition for Kuramoto oscillator, I thought I have missed something.
Thank you also for a quick response! Best, Nina
Hi,
thank you for this tool, i find it very useful! I have one problem though, if you might help me out.
Below I attached the file with Kuramoto model as is more or less defined in your example script. When I run the model it works and it outputs the angles, if my outputs are:
outputs_dict = {f"{inode}_theta": f"{inode}/kmo_oper_basic/theta" for inode in model.nodes.keys()}
However, when I want to include the wrapper version as an ouput:i get the error, which is not really informative:
_Traceback (most recent call last): File "C:\Users\NinaO\AppData\Local\Programs\Python\Python310\lib\site-packages\IPython\core\interactiveshell.py", line 3508, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 29, in
phases = model.run(outputs=outputs_dict, simulation_time=simulation_time, step_size=step_size, sampling_step_size=sampling_step_size,
File "D:\Experiments\simulation_EEG\venv\lib\site-packages\pyrates\frontend\template\circuit.py", line 468, in run
outputs = net._ir.run(simulation_time=simulation_time, solver=solver, sampling_step_size=sampling_step_size,
File "D:\Experiments\simulation_EEG\venv\lib\site-packages\pyrates\ir\circuit.py", line 1046, in run
results = self.graph.run(func=func, func_args=func_args, T=simulation_time, dt=self._dt, dts=sampling_step_size,
File "D:\Experiments\simulation_EEG\venv\lib\site-packages\pyrates\backend\computegraph.py", line 464, in run
outputs[key] = self._state_varindices[var]
KeyError: 'wrap'
I think the error is because my variable 'wrap' is not a state variable. Is there a way to nevertheless get the output of 'wrap', so the angle wrapped inside sin function? Or is there another problem?
Thank you for your help!
kuramoto_model.zip