Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: load eq_param_index of BundleSolvers correctly #212

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion neurodiffeq/solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ def __init__(self, ode_system, conditions, t_min, t_max,

def _diff_eqs_wrapper(*variables):
funcs_and_coords = variables[:N_FUNCTIONS + N_COORDS]
eq_params = tuple(variables[idx] for idx in eq_param_index)
eq_params = tuple(variables[idx] for idx in self.eq_param_index)
Copy link
Member

@shuheng-liu shuheng-liu Jan 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason we want to use self.eq_param_index instead of eq_param_index here? Both ways should have the same effect most of the time, but I don't want self.diff_eqs to be a closure that depends on self. This would make certain operations complicated, such as recreating a solver

solver1 = BundleSolver1D(..., eq_param_index1)
solver2 = BundleSolver1D(..., eq_param_index2)
solver2.diff_eqs = solver1.diff_eqs

If eq_param_index1 and eq_param_index2 are different, the above won't work, as solver1.diff_eqs will always depend on solver1.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm.. my motivation to use self.eq_param_index was to use this internal variable when loading a saved solver as otherwise we have to recompute eq_param_index again and pass it in the constructor.

return ode_system(*funcs_and_coords, *eq_params)

super(BundleSolver1D, self).__init__(
Expand Down
4 changes: 3 additions & 1 deletion neurodiffeq/solvers_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,9 @@ def load(cls,
t_min=t_min,
t_max=t_max,
theta_min=tuple(load_dict['solver'].r_min[1:]),
theta_max=tuple(load_dict['solver'].r_max[1:]))
theta_max=tuple(load_dict['solver'].r_max[1:]),
eq_param_index=load_dict['solver'].eq_param_index
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At a certain point we should consider refactoring the solver_utils package. A lot of the code seems to be a little ad-hoc. They are fine for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think we are due to think about refactoring and redesigning these pieces as they are pretty hard coded. I also have some thoughts on how parameters are saved - https://github.com/NeuroDiffGym/neurodiffeq/blob/master/neurodiffeq/solvers_utils.py#L99 which ties back to how parameters are used inside the function of the differential equation. I will open up an issue on this and we can discuss these things in detail.

)

if best_nets != None:
solver.best_nets = best_nets
Expand Down