NeuroDiffGym / neurodiffeq

A library for solving differential equations using neural networks based on PyTorch, used by multiple research groups around the world, including at Harvard IACS.
http://pypi.org/project/neurodiffeq/
MIT License
664 stars 87 forks source link

Could we implement the differential equations in symbolic format? #219

Open HuynhTran0301 opened 1 month ago

HuynhTran0301 commented 1 month ago

Hello everyone, I am trying to solve the differential equations by using neurodiffeq. I need to implement a large system for example a system with 78 equations in total. I think expressing the equations in symbolic format will help to minimize the effort when implementing as well as make the package more universal usage.

Do you have any documents or instructions on implementing the system in symbolic format? Thank you for your time and consideration.

shuheng-liu commented 1 month ago

Hi Huynh, can you provide a sample code snippet so that I can know what kind of symbolic format you want us to implement?

sathvikbhagavan commented 1 month ago

Is usage of sympy applicable here? It would be good to some existing library of symbolics for parsing and lowering.

HuynhTran0301 commented 1 month ago

@shuheng-liu Thank you for your reply. This is the example of equations that I want to implement.

eq12 = [
    if i in bus_gen
        j = bus_gen.index(i)
        0 ~ (Id[j]*V[i]*(A[j]*y[i] - B[j]*x[i]) + Iq[j]*V[i]*(B[j]*y[i] + A[j]*x[i])) - Pd[i] - 
        sum(Y_matrix[i,k].im*V[i]*V[k]*(x[i]*y[k] - y[i]*x[k]) + Y_matrix[i,k].re*V[i]*V[k]*(y[i]*y[k] + x[i]*x[k]) for k in 1:n)
    else
        0 ~ -Pd[i] -
        sum(Y_matrix[i,k].im*V[i]*V[k]*(x[i]*y[k] - y[i]*x[k]) + Y_matrix[i,k].re*V[i]*V[k]*(y[i]*y[k] + x[i]*x[k]) for k in 1:n)
    for i in 1:n
]

Where Id, Iq, A, B, V, x, y are variables and Y_matrix and Pd are parameters (constants) I have a several set of equations like this and the total of equations can be 78 or more. So a symbolic format will be convenient when I change the system (for a larger system).