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

Non-constant parameters #24

Open
LSchueler opened this issue Aug 4, 2021 · 2 comments
Open

Non-constant parameters #24

LSchueler opened this issue Aug 4, 2021 · 2 comments

Comments

@LSchueler
Copy link

Hi and thanks for this package!

I want to solve a set of ODEs where one of the parameters is a step function with prescribed times at which it can jump. What would be the recommended way of implementing something like that with sunode?

@LSchueler
Copy link
Author

Any updates on this? Or on this page?

@makaspacex
Copy link

makaspacex commented Dec 21, 2022

I solve this problem by python closure. The demo codes are as follows:

def get_dydt_func(prescribed_times_func):
    def _dydt_func(c, y, params):
        # use function variable prescribed_times_func in this block
        pass
    return _dydt_func

def prescribed_times_func1():
    pass

def prescribed_times_func2():
    pass


func1 =  get_dydt_func(prescribed_times_func1)
func2 = get_dydt_func(prescribed_times_func2)
y_hat, _, problem, solver, _, _ =  
    sunode.wrappers.as_pytensor.solve_ivp(
    y0=c0,
    params=parames,
    rhs=func1,
    tvals=times,
    t0=times[0],
    )

Now, func1 has local and bind variable prescribed_times_func1 which value is 5, while it is prescribed_times_func2 in func2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants