Skip to content

Add gravity pendulum example#2052

Open
vl-dud wants to merge 3 commits intolululxvi:masterfrom
vl-dud:pendulum-pideeponet-example
Open

Add gravity pendulum example#2052
vl-dud wants to merge 3 commits intolululxvi:masterfrom
vl-dud:pendulum-pideeponet-example

Conversation

@vl-dud
Copy link
Copy Markdown
Contributor

@vl-dud vl-dud commented Dec 17, 2025

Add a PI-DeepONet example for the gravity pendulum problem:

$\theta''(t) = -\sin(\theta(t)) + u(t), \qquad t \in [0, T]$

$\theta(0) = 0, \qquad \theta'(0) = 0$

  • $t$: time
  • $\theta(t)$: pendulum angle
  • $u(t)$: external forcing

@lululxvi
Copy link
Copy Markdown
Owner

@vl-dud
Copy link
Copy Markdown
Contributor Author

vl-dud commented Feb 23, 2026

Copy link
Copy Markdown
Contributor

@echen5503 echen5503 left a comment

Choose a reason for hiding this comment

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

Hi, I'm relatively new here so please take my comments with a grain of salt, but I found some potential issues with the code. Reviewing to learn more right now :)



def pde(x, y, v):
# theta''(t) = -sin(theta(t)) + u(t)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nitpick: Why not use theta unicode character?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is inconsistent with the other examples, since unicode isn’t used for Greek letters anywhere else.

Comment thread docs/demos/operator.rst
- `Diffusion reaction equation with aligned points <https://github.com/lululxvi/deepxde/tree/master/examples/operator/diff_rec_aligned_pideeponet.py>`_
- `Diffusion reaction equation with unaligned points <https://github.com/lululxvi/deepxde/tree/master/examples/operator/diff_rec_unaligned_pideeponet.py>`_
- `Stokes flow with aligned points <https://github.com/lululxvi/deepxde/tree/master/examples/operator/stokes_aligned_pideeponet.py>`_
- `Gravity pendulum with unaligned points <https://github.com/lululxvi/deepxde/tree/master/examples/operator/gravity_pendulum_unaligned_pideeponet.py>`_
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It may be a good idea to have some documentation for this code. See https://github.com/lululxvi/deepxde/pull/2056/changes.

It seems to be uniquely valuable here because operator learning has few examples with documentation.

"""
Solve the forced pendulum ODE using a 4th-order Runge–Kutta method

theta''(t) = -sin(theta(t)) + u(t),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PDE expression already duplicated above

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This doesn’t seem like a significant issue to me.

import matplotlib.pyplot as plt
import numpy as np

sin = dde.backend.sin
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This renamed sin function is only used twice. It may be better to just use dde.backend.sin for clarity.

return on_boundary and np.isclose(x[0], 0.0)


geom = dde.geometry.TimeDomain(0, 1)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This part is likely difficult to read for newcomers. Comments / Documentation would probably help.

v = u_sin(eval_pts)
solved_theta = solve_pendulum(u_sin, t)
predicted_theta = model.predict((np.tile(v.T, (t.size, 1)), t.reshape(-1, 1)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could be helpful to add error metrics here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I’m not sure it makes much sense to use metrics for just one example of u(t).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Right, it's already plotted. SG

@vl-dud
Copy link
Copy Markdown
Contributor Author

vl-dud commented Mar 22, 2026

@echen5503 Thank you for your careful review. I have updated the parts that seemed most important to address.

@echen5503
Copy link
Copy Markdown
Contributor

@vl-dud great, this looks good to me.
@lululxvi I recommend merge. Note that the paddlepaddle build failure is not the fault of this PR, seems like the origin of paddlepaddle might have been moved.

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

Successfully merging this pull request may close these issues.

3 participants