Skip to content

Commit 704b43a

Browse files
authored
reduce warnings from adjoint tests (#4645)
1 parent ae809f3 commit 704b43a

File tree

8 files changed

+44
-44
lines changed

8 files changed

+44
-44
lines changed

firedrake/utility_meshes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3000,7 +3000,7 @@ def CylinderMesh(
30003000
# 0-----1
30013001

30023002
offset = np.arange(nl, dtype=np.int32) * nr
3003-
origquads = np.row_stack(tuple(ring_cells + i for i in offset))
3003+
origquads = np.vstack(tuple(ring_cells + i for i in offset))
30043004
cells = np.zeros((origquads.shape[0] * 4, 3), dtype=np.int32)
30053005
cellidx = 0
30063006
newvertices = range(len(origvertices), len(origvertices) + len(extras))
@@ -3013,7 +3013,7 @@ def CylinderMesh(
30133013

30143014
else:
30153015
offset = np.arange(nl, dtype=np.int32) * nr
3016-
cells = np.row_stack(tuple(ring_cells + i for i in offset))
3016+
cells = np.vstack(tuple(ring_cells + i for i in offset))
30173017
if not quadrilateral:
30183018
if diagonal == "left":
30193019
idx = [0, 1, 3, 1, 2, 3]

tests/firedrake/adjoint/test_assemble.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def test_assemble_1_forms_tlm(rg):
8989
mesh = IntervalMesh(10, 0, 1)
9090
V = FunctionSpace(mesh, "Lagrange", 1)
9191
v = TestFunction(V)
92-
f = Function(V).assign(1)
92+
f = Function(V).assign(1.)
9393

9494
w1 = assemble(inner(f, v) * dx)
9595
w2 = assemble(inner(f**2, v) * dx)

tests/firedrake/adjoint/test_assignment.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_assign_vector_valued():
6464
J = assemble(inner(f, g)*u**2*dx)
6565
rf = ReducedFunctional(J, Control(f))
6666

67-
h = Function(V).assign(1)
67+
h = Function(V).assign(1.)
6868
assert taylor_test(rf, f, h) > 1.9
6969

7070

@@ -84,7 +84,7 @@ def test_assign_tlm():
8484
J = assemble(inner(f, g)*u**2*dx)
8585
rf = ReducedFunctional(J, Control(f))
8686

87-
h = Function(V).assign(1)
87+
h = Function(V).assign(1.)
8888
f.block_variable.tlm_value = h
8989

9090
tape = get_working_tape()
@@ -138,7 +138,7 @@ def test_assign_hessian():
138138

139139
dJdm = rf.derivative()
140140

141-
h = Function(V).assign(1)
141+
h = Function(V).assign(1.)
142142
Hm = rf.hessian(h)
143143
assert taylor_test(rf, f, h, dJdm=h._ad_dot(dJdm), Hm=h._ad_dot(Hm)) > 2.9
144144

tests/firedrake/adjoint/test_hessian.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_simple_solve(rg):
3737
mesh = IntervalMesh(10, 0, 1)
3838
V = FunctionSpace(mesh, "Lagrange", 1)
3939

40-
f = Function(V).assign(2)
40+
f = Function(V).assign(2.)
4141

4242
u = TrialFunction(V)
4343
v = TestFunction(V)
@@ -76,10 +76,10 @@ def test_mixed_derivatives(rg):
7676
mesh = IntervalMesh(10, 0, 1)
7777
V = FunctionSpace(mesh, "Lagrange", 1)
7878

79-
f = Function(V).assign(2)
79+
f = Function(V).assign(2.)
8080
control_f = Control(f)
8181

82-
g = Function(V).assign(3)
82+
g = Function(V).assign(3.)
8383
control_g = Control(g)
8484

8585
u = TrialFunction(V)
@@ -126,7 +126,7 @@ def test_function(rg):
126126
R = FunctionSpace(mesh, "R", 0)
127127
c = Function(R, val=4)
128128
control_c = Control(c)
129-
f = Function(V).assign(3)
129+
f = Function(V).assign(3.)
130130
control_f = Control(f)
131131

132132
u = Function(V)
@@ -139,14 +139,14 @@ def test_function(rg):
139139
J = assemble(c ** 2 * u ** 2 * dx)
140140

141141
Jhat = ReducedFunctional(J, [control_c, control_f])
142-
dJdc, dJdf = compute_gradient(J, [control_c, control_f], apply_riesz=True)
142+
dJdc, dJdf = compute_derivative(J, [control_c, control_f], apply_riesz=True)
143143

144144
# Step direction for derivatives and convergence test
145145
h_c = Function(R, val=1.0)
146146
h_f = rg.uniform(V, 0, 10)
147147

148148
# Total derivative
149-
dJdc, dJdf = compute_gradient(J, [control_c, control_f], apply_riesz=True)
149+
dJdc, dJdf = compute_derivative(J, [control_c, control_f], apply_riesz=True)
150150
dJdm = assemble(dJdc * h_c * dx + dJdf * h_f * dx)
151151

152152
# Hessian
@@ -163,7 +163,7 @@ def test_nonlinear(rg):
163163
mesh = UnitSquareMesh(10, 10)
164164
V = FunctionSpace(mesh, "Lagrange", 1)
165165
R = FunctionSpace(mesh, "R", 0)
166-
f = Function(V).assign(5)
166+
f = Function(V).assign(5.)
167167

168168
u = Function(V)
169169
v = TestFunction(V)
@@ -201,11 +201,11 @@ def test_dirichlet(rg):
201201
mesh = UnitSquareMesh(10, 10)
202202
V = FunctionSpace(mesh, "Lagrange", 1)
203203

204-
f = Function(V).assign(30)
204+
f = Function(V).assign(30.)
205205

206206
u = Function(V)
207207
v = TestFunction(V)
208-
c = Function(V).assign(1)
208+
c = Function(V).assign(1.)
209209
bc = DirichletBC(V, c, "on_boundary")
210210

211211
F = inner(grad(u), grad(v)) * dx + u**4*v*dx - f**2 * v * dx

tests/firedrake/adjoint/test_projection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_project_vector_valued():
4242
J = assemble(inner(f, g)*u**2*dx)
4343
rf = ReducedFunctional(J, Control(f))
4444

45-
h = Function(V).assign(1)
45+
h = Function(V).assign(1.)
4646
assert taylor_test(rf, f, h) > 1.9
4747

4848

@@ -62,7 +62,7 @@ def test_project_tlm():
6262
J = assemble(inner(f, g)*u**2*dx)
6363
rf = ReducedFunctional(J, Control(f))
6464

65-
h = Function(V).assign(1)
65+
h = Function(V).assign(1.)
6666
f.tlm_value = h
6767

6868
tape = get_working_tape()
@@ -89,7 +89,7 @@ def test_project_hessian():
8989

9090
dJdm = rf.derivative()
9191

92-
h = Function(V).assign(1)
92+
h = Function(V).assign(1.)
9393
Hm = rf.hessian(h)
9494
assert taylor_test(rf, f, h, dJdm=h._ad_dot(dJdm), Hm=h._ad_dot(Hm)) > 2.9
9595

tests/firedrake/adjoint/test_reduced_functional.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_constant():
3131

3232
c = Function(R, val=1)
3333
f = Function(V)
34-
f.assign(1)
34+
f.assign(1.)
3535

3636
u = Function(V)
3737
v = TestFunction(V)
@@ -52,7 +52,7 @@ def test_function():
5252

5353
c = Constant(1)
5454
f = Function(V)
55-
f.assign(1)
55+
f.assign(1.)
5656

5757
u = Function(V)
5858
v = TestFunction(V)
@@ -88,7 +88,7 @@ def test_wrt_function_dirichlet_boundary(control):
8888
g1 = Function(R, val=2)
8989
g2 = Function(R, val=1)
9090
f = Function(V)
91-
f.assign(10)
91+
f.assign(10.)
9292

9393
a = inner(grad(u), grad(v))*dx + u**2*v*dx
9494
L = inner(f, v)*dx + inner(g1, v)*ds(4) + inner(g2, v)*ds(3)
@@ -102,7 +102,7 @@ def test_wrt_function_dirichlet_boundary(control):
102102
Jhat = ReducedFunctional(J, Control(bc_func))
103103
g = bc_func
104104
h = Function(V)
105-
h.assign(1)
105+
h.assign(1.)
106106
else:
107107
Jhat = ReducedFunctional(J, Control(g1))
108108
g = g1
@@ -131,10 +131,10 @@ def test_time_dependent():
131131
T = 0.5
132132
dt = 0.1
133133
f = Function(V)
134-
f.assign(1)
134+
f.assign(1.)
135135

136136
u_1 = Function(V)
137-
u_1.assign(1)
137+
u_1.assign(1.)
138138
control = Control(u_1)
139139

140140
a = u_1*u*v*dx + dt*f*inner(grad(u), grad(v))*dx
@@ -152,7 +152,7 @@ def test_time_dependent():
152152
Jhat = ReducedFunctional(J, control)
153153

154154
h = Function(V)
155-
h.assign(1)
155+
h.assign(1.)
156156
assert taylor_test(Jhat, control.tape_value(), h) > 1.9
157157

158158

@@ -172,7 +172,7 @@ def test_mixed_boundary():
172172
g1 = Constant(2)
173173
g2 = Constant(1)
174174
f = Function(V)
175-
f.assign(10)
175+
f.assign(10.)
176176

177177
a = f*inner(grad(u), grad(v))*dx
178178
L = inner(f, v)*dx + inner(g1, v)*ds(4) + inner(g2, v)*ds(3)
@@ -183,7 +183,7 @@ def test_mixed_boundary():
183183

184184
Jhat = ReducedFunctional(J, Control(f))
185185
h = Function(V)
186-
h.assign(1)
186+
h.assign(1.)
187187
assert taylor_test(Jhat, f, h) > 1.9
188188

189189

@@ -194,13 +194,13 @@ def test_assemble_recompute():
194194
R = FunctionSpace(mesh, "R", 0)
195195

196196
f = Function(V)
197-
f.assign(2)
197+
f.assign(2.)
198198
expr = Function(R).assign(assemble(f**2*dx))
199199
J = assemble(expr**2*dx(domain=mesh))
200200
Jhat = ReducedFunctional(J, Control(f))
201201

202202
h = Function(V)
203-
h.assign(1)
203+
h.assign(1.)
204204
assert taylor_test(Jhat, f, h) > 1.9
205205

206206

tests/firedrake/adjoint/test_solving.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_linear_problem(rg):
3333
mesh = IntervalMesh(10, 0, 1)
3434
V = FunctionSpace(mesh, "Lagrange", 1)
3535
R = FunctionSpace(mesh, "R", 0)
36-
f = Function(V).assign(1)
36+
f = Function(V).assign(1.)
3737

3838
u = TrialFunction(V)
3939
u_ = Function(V)
@@ -60,7 +60,7 @@ def test_singular_linear_problem(rg):
6060
mesh = UnitSquareMesh(10, 10)
6161
V = FunctionSpace(mesh, "CG", 1)
6262

63-
f = Function(V).assign(1)
63+
f = Function(V).assign(1.)
6464

6565
u = TrialFunction(V)
6666
u_ = Function(V)
@@ -85,7 +85,7 @@ def test_nonlinear_problem(pre_apply_bcs, rg):
8585
mesh = IntervalMesh(10, 0, 1)
8686
V = FunctionSpace(mesh, "Lagrange", 1)
8787
R = FunctionSpace(mesh, "R", 0)
88-
f = Function(V).assign(1)
88+
f = Function(V).assign(1.)
8989

9090
u = Function(V)
9191
v = TestFunction(V)
@@ -116,7 +116,7 @@ def test_mixed_boundary(rg):
116116

117117
g1 = Constant(2)
118118
g2 = Constant(1)
119-
f = Function(V).assign(10)
119+
f = Function(V).assign(10.)
120120

121121
def J(f):
122122
a = f*inner(grad(u), grad(v))*dx
@@ -165,7 +165,7 @@ def xtest_wrt_function_dirichlet_boundary():
165165

166166
g1 = Constant(2)
167167
g2 = Constant(1)
168-
f = Function(V).assign(10)
168+
f = Function(V).assign(10.)
169169

170170
def J(bc):
171171
a = inner(grad(u), grad(v))*dx
@@ -195,7 +195,7 @@ def test_wrt_function_neumann_boundary():
195195

196196
g1 = Function(R, val=2)
197197
g2 = Function(R, val=1)
198-
f = Function(V).assign(10)
198+
f = Function(V).assign(10.)
199199

200200
def J(g1):
201201
a = inner(grad(u), grad(v))*dx
@@ -247,7 +247,7 @@ def test_wrt_constant_neumann_boundary():
247247

248248
g1 = Function(R, val=2)
249249
g2 = Function(R, val=1)
250-
f = Function(V).assign(10)
250+
f = Function(V).assign(10.)
251251

252252
def J(g1):
253253
a = inner(grad(u), grad(v))*dx
@@ -283,7 +283,7 @@ def test_time_dependent():
283283
f = Function(R, val=1)
284284

285285
def J(f):
286-
u_1 = Function(V).assign(1)
286+
u_1 = Function(V).assign(1.)
287287

288288
a = u_1*u*v*dx + dt*f*inner(grad(u), grad(v))*dx
289289
L = u_1*v*dx
@@ -340,7 +340,7 @@ def _test_adjoint_function_boundary(J, bc, f):
340340
set_working_tape(tape)
341341

342342
V = f.function_space()
343-
h = Function(V).assign(1)
343+
h = Function(V).assign(1.)
344344
g = Function(V)
345345
eps_ = [0.4/2.0**i for i in range(4)]
346346
residuals = []

tests/firedrake/adjoint/test_tlm.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_tlm_assemble(rg):
3636
set_working_tape(tape)
3737
mesh = IntervalMesh(10, 0, 1)
3838
V = FunctionSpace(mesh, "Lagrange", 1)
39-
f = Function(V).assign(5)
39+
f = Function(V).assign(5.)
4040

4141
u = TrialFunction(V)
4242
v = TestFunction(V)
@@ -66,7 +66,7 @@ def test_tlm_bc():
6666
V = FunctionSpace(mesh, "Lagrange", 1)
6767
R = FunctionSpace(mesh, "R", 0)
6868
c = Function(R, val=1)
69-
f = Function(V).assign(1)
69+
f = Function(V).assign(1.)
7070

7171
u = Function(V)
7272
v = TestFunction(V)
@@ -88,8 +88,8 @@ def test_tlm_func(rg):
8888
mesh = IntervalMesh(10, 0, 1)
8989
V = FunctionSpace(mesh, "Lagrange", 1)
9090

91-
c = Function(V).assign(1)
92-
f = Function(V).assign(1)
91+
c = Function(V).assign(1.)
92+
f = Function(V).assign(1.)
9393

9494
u = Function(V)
9595
v = TestFunction(V)
@@ -130,9 +130,9 @@ def test_time_dependent(solve_type, rg):
130130
# Some variables
131131
T = 0.5
132132
dt = 0.1
133-
f = Function(V).assign(1)
133+
f = Function(V).assign(1.)
134134

135-
u_1 = Function(V).assign(1)
135+
u_1 = Function(V).assign(1.)
136136
control = Control(u_1)
137137

138138
a = u_1 * u * v * dx + dt * f * inner(grad(u), grad(v)) * dx

0 commit comments

Comments
 (0)