Skip to content

Commit 63343e1

Browse files
committed
Merge branch 'main' into pbrubeck/test/gem
2 parents d67e7d0 + 1b677f2 commit 63343e1

File tree

97 files changed

+3213
-1464
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+3213
-1464
lines changed

.github/workflows/core.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ jobs:
121121
- name: Install system dependencies (1)
122122
run: apt-get -y install git python3
123123

124-
- uses: actions/checkout@v4
124+
- uses: actions/checkout@v5
125125
with:
126126
path: firedrake-repo
127127
ref: ${{ inputs.source_ref }}
@@ -207,10 +207,7 @@ jobs:
207207
pip install --verbose $EXTRA_PIP_FLAGS \
208208
--no-binary h5py \
209209
--extra-index-url https://download.pytorch.org/whl/cpu \
210-
"$(echo ./firedrake-repo/dist/firedrake-*.tar.gz)"
211-
212-
pip install -U pip
213-
pip install --group ./firedrake-repo/pyproject.toml:ci
210+
"$(echo ./firedrake-repo/dist/firedrake-*.tar.gz)[ci,docs]"
214211
215212
pip install -I "firedrake-fiat @ git+https://github.com/firedrakeproject/fiat.git@pbrubeck/simplify-indexed"
216213
firedrake-clean
@@ -455,7 +452,7 @@ jobs:
455452
# Make sure the current directory is empty
456453
run: find . -delete
457454

458-
- uses: actions/checkout@v4
455+
- uses: actions/checkout@v5
459456
with:
460457
path: firedrake-repo
461458
ref: ${{ inputs.source_ref }}
@@ -534,7 +531,7 @@ jobs:
534531
name: Lint codebase
535532
runs-on: ubuntu-latest
536533
steps:
537-
- uses: actions/checkout@v4
534+
- uses: actions/checkout@v5
538535
with:
539536
ref: ${{ inputs.source_ref }}
540537
- uses: actions/setup-python@v5

.github/workflows/docker_build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
echo "/opt/homebrew/bin" >> "$GITHUB_PATH"
5959
6060
- name: Check out the repo
61-
uses: actions/checkout@v4
61+
uses: actions/checkout@v5
6262

6363
- name: Log in to Docker Hub
6464
uses: docker/login-action@v3

.github/workflows/pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
test:
99
uses: ./.github/workflows/core.yml
1010
with:
11-
source_ref: ${{ github.head_ref }}
11+
source_ref: ${{ github.ref }}
1212
target_branch: ${{ github.base_ref }}
1313
# Only run macOS tests if the PR is labelled 'macOS'
1414
test_macos: ${{ contains(github.event.pull_request.labels.*.name, 'macOS') }}

demos/full_waveform_inversion/full_waveform_inversion.py.rst

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,12 @@ built over the ``my_ensemble.comm`` (spatial) communicator.
109109
dt = 0.03 # time step in seconds
110110
final_time = 0.6 # final time in seconds
111111
nx, ny = 15, 15
112+
ftol = 0.9 # optimisation tolerance
112113
else:
113114
dt = 0.002 # time step in seconds
114115
final_time = 1.0 # final time in seconds
115116
nx, ny = 80, 80
117+
ftol = 1e-2 # optimisation tolerance
116118

117119
mesh = UnitSquareMesh(nx, ny, comm=my_ensemble.comm)
118120

@@ -278,21 +280,28 @@ To have the step 4, we need first to tape the forward problem. That is done by c
278280

279281
We now instantiate :class:`~.EnsembleReducedFunctional`::
280282

281-
J_hat = EnsembleReducedFunctional(J_val, Control(c_guess), my_ensemble)
283+
J_hat = EnsembleReducedFunctional(J_val,
284+
Control(c_guess, riesz_map="l2"),
285+
my_ensemble)
282286

283287
which enables us to recompute :math:`J` and its gradient :math:`\nabla_{\mathtt{c\_guess}} J`,
284288
where the :math:`J_s` and its gradients :math:`\nabla_{\mathtt{c\_guess}} J_s` are computed in parallel
285289
based on the ``my_ensemble`` configuration.
286290

287291

288292
**Steps 4-6**: The instance of the :class:`~.EnsembleReducedFunctional`, named ``J_hat``,
289-
is then passed as an argument to the ``minimize`` function::
293+
is then passed as an argument to the ``minimize`` function. The default ``minimize`` function
294+
uses ``scipy.minimize``, and wraps the ``ReducedFunctional`` in a ``ReducedFunctionalNumPy``
295+
that handles transferring data between Firedrake and numpy data structures. However, because
296+
we have a custom ``ReducedFunctional``, we need to do this ourselves::
290297

291-
c_optimised = minimize(J_hat, method="L-BFGS-B", options={"disp": True, "maxiter": 1},
292-
bounds=(1.5, 2.0), derivative_options={"riesz_representation": 'l2'}
293-
)
298+
from pyadjoint.reduced_functional_numpy import ReducedFunctionalNumPy
299+
Jnumpy = ReducedFunctionalNumPy(J_hat)
294300

295-
The ``minimize`` function executes the optimisation algorithm until the stopping criterion (``maxiter``) is met.
301+
c_optimised = minimize(Jnumpy, method="L-BFGS-B", options={"disp": True, "ftol": ftol},
302+
bounds=(1.5, 2.0))
303+
304+
The ``minimize`` function executes the optimisation algorithm until the stopping criterion (``ftol``) is met.
296305
For 20 iterations, the predicted velocity model is shown in the following figure.
297306

298307
.. image:: c_predicted.png
@@ -303,9 +312,7 @@ For 20 iterations, the predicted velocity model is shown in the following figure
303312
.. warning::
304313

305314
The ``minimize`` function uses the SciPy library for optimisation. However, for scenarios that require higher
306-
levels of spatial parallelism, you should assess whether SciPy is the most suitable option for your problem.
307-
SciPy's optimisation algorithm is not inner-product-aware. Therefore, we configure the options with
308-
``derivative_options={"riesz_representation": 'l2'}`` to account for this requirement.
315+
levels of spatial parallelism, you should assess whether SciPy is the most suitable option for your problem such as the pyadjoint's TAOSolver.
309316

310317
.. note::
311318

demos/linear_fluid_structure_interaction/linear_fluid_structure_interaction.py.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,11 @@ To save data for visualization, we change the position of the nodes in the mesh,
287287
output_data.counter += 1
288288
if output_data.counter % output_data_every_x_time_steps != 0:
289289
return
290-
mesh_static = mesh.coordinates.vector().get_local()
291-
mesh.coordinates.vector().set_local(mesh_static + X.vector().get_local())
292-
mesh.coordinates.dat.data[:, 1] += eta.dat.data_ro
290+
mesh_static = mesh.coordinates.copy(deepcopy=True)
291+
mesh.coordinates += X
292+
mesh.coordinates.dat.data_rw[:, 1] += eta.dat.data_ro
293293
outfile_phi.write(phi)
294-
mesh.coordinates.vector().set_local(mesh_static)
294+
mesh.coordinates.assign(mesh_static)
295295

296296

297297
output_data.counter = -1 # -1 to exclude counting print of initial state

demos/ma-demo/ma-demo.py.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ one, we must explicitly specify the domain we wish to integrate over. ::
9797
x, y = SpatialCoordinate(mesh)
9898
fexpr = exp(-(cos(x)**2 + cos(y)**2))
9999
f = Function(V).interpolate(fexpr)
100-
scaling = assemble(Constant(1, domain=mesh)*dx)/assemble(f*dx)
100+
scaling = assemble(Constant(1)*dx(domain=mesh))/assemble(f*dx)
101101
f *= scaling
102-
assert abs(assemble(f*dx)-assemble(Constant(1, domain=mesh)*dx)) < 1.0e-8
102+
assert abs(assemble(f*dx)-assemble(Constant(1)*dx(domain=mesh))) < 1.0e-8
103103

104104
Now we build the UFL expression for the variational form. We will use
105105
the nonlinear solve, so the form needs to be a 1-form that depends on

demos/saddle_point_pc/saddle_point_systems.py.rst

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,12 @@ problem. We will need some trial and test functions for the spaces::
8787
sigma, u = TrialFunctions(W)
8888
tau, v = TestFunctions(W)
8989

90-
along with a function to hold the forcing term, living in the
90+
along with a random function to hold the forcing term, living in the
9191
discontinuous space. ::
9292

9393
#
94-
f = Function(V)
95-
96-
To initialise this function to a random value we access its :class:`~.Vector`
97-
form and use numpy_ to set the values::
98-
99-
#
100-
import numpy as np
101-
fvector = f.vector()
102-
fvector.set_local(np.random.uniform(size=fvector.local_size()))
94+
rg = RandomGenerator()
95+
f = rg.uniform(V)
10396

10497
Note that the homogeneous Dirichlet conditions in the primal
10598
formulation turn into homogeneous Neumann conditions on the dual

demos/shape_optimization/shape_optimization.py.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ and evaluate the objective function::
7070

7171
We now turn the objective function into a reduced function so that pyadjoint
7272
(and UFL shape differentiation capability) can automatically compute shape
73-
gradients, that is, directions of steepest ascent::
73+
gradients, that is, directions of steepest ascent. We also set the relevant
74+
Riesz map for this problem::
7475

75-
Jred = ReducedFunctional(J, Control(dT))
76+
Jred = ReducedFunctional(J, Control(dT, riesz_map="H1"))
7677
stop_annotating()
7778

7879
We now have all the ingredients to implement a basic steepest descent shape
@@ -84,8 +85,7 @@ optimization algorithm with fixed step size.::
8485
File.write(mesh.coordinates)
8586

8687
# compute the gradient (steepest ascent)
87-
opts = {"riesz_representation": "H1"}
88-
gradJ = Jred.derivative(options=opts)
88+
gradJ = Jred.derivative(apply_riesz=True)
8989

9090
# update domain
9191
dT -= 0.2*gradJ

docker/Dockerfile.vanilla

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,5 @@ ENV CFLAGS="-mtune=generic" CPPFLAGS="-mtune=generic"
6161
ENV MPICC=$CC
6262

6363
# Install Firedrake
64-
RUN pip install -U pip \
65-
&& git clone https://github.com/firedrakeproject/firedrake.git /opt/firedrake --branch release \
66-
&& pip install --verbose --no-binary h5py --editable /opt/firedrake --group /opt/firedrake/pyproject.toml:docker
64+
RUN pip install --verbose --no-binary h5py --src /opt \
65+
--editable git+https://github.com/firedrakeproject/firedrake.git@release#egg=firedrake[docker]

docs/source/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@
257257
258258
.. warning::
259259
You are reading a version of the website built against the unstable ``main`` branch. This content is liable to change without notice and may be inappropriate for your use case.
260+
You can find the documentation for the current stable release `here <https://firedrakeproject.org/>`__.
260261
"""
261262

262263
# -- Options for LaTeX output --------------------------------------------

0 commit comments

Comments
 (0)