Open artfin opened 7 years ago
How many particles are you targeting?
Sorry, hasn't been clear. I'm targeting not so many particles (5-7 in the nearest future), but I need to solve ODE system varying initial conditions to obtain 100.000 and more classical trajectories.
Have you considered writing the particle state as a vector (numpy array), and write the hamiltonian as a sequence of vector operators on the state vector? I heard autograd is slow when there are lots of list and Python objects.
I don't think it's possible, because the particle state should consist of differentiable functions (both the coordinates and derivatives of coordinates are needed to construct hamiltonian
).
I am not so sure about this. Could you write down the equation of motion?
The system of equations to solve looks like this. The derivatives of hamiltonian by angular momentum components are calculated from derivatives of hamiltonian by angles (theta
, varphi
-- the spherical angles describing the direction of angular momentum vector, they are passed to hamiltonian
function).
The thing is, that to construct the hamiltonian I need first to calculate the lagrangian (or the matrices that it is constructed from -- a
, A
, inertia tensor
in code snippet above), here is the math form of the matrices a
, A
:
There are derivatives of radius vector (of each particle) by internal coordinates (in the code snippet above there is the only one internal coordinate q
). For each particle I specify the functional form of a radius vector, so that in the hamiltonian
these derivatives by internal coordinates could be taken. I think the radius vectors and derivatives of the radius vectors could be used in the numerical form, but it can get tricky for a system with multiple internal coordinates. And I don't see how it would provide speed up.
EDIT.
https://github.com/artfin/classical-trajectories/blob/master/automatic-solver/automatic_solver.py
Here's how I did it. I thought that the ODE part doesn't relate too much too autograd
, so decided not to attach additional code.
Thank you for this amazing library!
I'm using it for modeling classical behaviour of some systems. The idea is to solve complex (4-10 equations) system of ODEs with scipy's
odeint
, while the right-hand side is evaluated using derivatives ofhamiltonian
provided byautograd
. Everything works nice for simple systems, but even for middle-sized systems the derivatives ofhamiltonian
are evaluated rather long. Are there any methods to optimize it? (During the solving of ODEs derivatives are being calculated 10.000-50.000 times.)Sorry for lengthy example, but it seems to be the minimal working bit of code, containing
hamiltonian
function.