firedrake.adjoint_utils.blocks package¶
Submodules¶
firedrake.adjoint_utils.blocks.assembly module¶
- class firedrake.adjoint_utils.blocks.assembly.AssembleBlock(form, ad_block_tag=None)[source]¶
Bases:
Block- adj_state¶
- block_helper¶
- compute_action_adjoint(adj_input, arity_form, form=None, c_rep=None, space=None, dform=None)[source]¶
This computes the action of the adjoint of the derivative of \(form\) wrt \(c_rep\) on \(adj_input\). In other words, it returns: \(<(dform/dc_rep)*, adj_input>\)
If \(form\) has arity 0 => \(dform/dc_rep\) is a 1-form and \(adj_input\) a float, we can simply use the \(*\) operator.
If \(form\) has arity 1 => \(dform/dc_rep\) is a 2-form and we can symbolically take its adjoint and then apply the action on \(adj_input\), to finally assemble the result.
- evaluate_hessian_component(inputs, hessian_inputs, adj_inputs, block_variable, idx, relevant_dependencies, prepared=None)[source]¶
- tag¶
firedrake.adjoint_utils.blocks.block_utils module¶
firedrake.adjoint_utils.blocks.constant module¶
- class firedrake.adjoint_utils.blocks.constant.ConstantAssignBlock(other, ad_block_tag=None)[source]¶
Bases:
Block- adj_state¶
- block_helper¶
- evaluate_hessian_component(inputs, hessian_inputs, adj_inputs, block_variable, idx, relevant_dependencies, prepared=None)[source]¶
- tag¶
- firedrake.adjoint_utils.blocks.constant.constant_from_values(constant, values=None)[source]¶
Returns a new Constant with \(constant.values()\).
If the optional argument \(values\) is provided, then \(values\) will be the values of the new Constant instead, while still preserving the ufl_shape of \(constant\).
- Parameters:
constant – A constant with the ufl_shape to preserve. values
(numpy.array) – An optional argument to use instead of
constant.values().
- Returns:
The created Constant of the same type as \(constant\).
- Return type:
firedrake.adjoint_utils.blocks.dirichlet_bc module¶
firedrake.adjoint_utils.blocks.function module¶
- class firedrake.adjoint_utils.blocks.function.CofunctionAssignBlock(lhs, rhs, ad_block_tag=None, rhs_from_assemble=False)[source]¶
Bases:
BlockClass specifically for the case b.assign(a).
All other cofunction assignment operations are annotated via Assemble. In effect this means that this is the annotation of an identity operation.
- Parameters:
lhs – The target of the assignment.
rhs – The cofunction being assigned.
- adj_state¶
- block_helper¶
- evaluate_hessian_component(inputs, hessian_inputs, adj_inputs, block_variable, idx, relevant_dependencies, prepared=None)[source]¶
- recompute_component(inputs, block_variable, idx, prepared=None)[source]¶
Recompute the assignment.
- Parameters:
inputs (list of Function or Constant) – The variable in the RHS of the assignment.
block_variable (pyadjoint.block_variable.BlockVariable) – The output block variable.
idx (int) – Index associated to the inputs list.
prepared – The precomputed RHS value.
Notes
Recomputes the block_variable only if the checkpoint was not delegated to another
Function.- Returns:
Return either the firedrake cofunction or \(BlockVariable\) checkpoint to which was delegated the checkpointing.
- Return type:
- tag¶
- class firedrake.adjoint_utils.blocks.function.FunctionAssignBlock(func, other, ad_block_tag=None)[source]¶
Bases:
Block- adj_state¶
- block_helper¶
- evaluate_hessian_component(inputs, hessian_inputs, adj_inputs, block_variable, idx, relevant_dependencies, prepared=None)[source]¶
- recompute_component(inputs, block_variable, idx, prepared=None)[source]¶
Recompute the assignment.
- Parameters:
inputs (list of Function or Constant) – The variables in the RHS of the assignment.
block_variable (pyadjoint.block_variable.BlockVariable) – The output block variable.
idx (int) – Index associated to the inputs list.
prepared – The precomputed RHS value.
Notes
Recomputes the block_variable only if the checkpoint was not delegated to another
Function.- Returns:
Return either the firedrake function or \(BlockVariable\) checkpoint to which was delegated the checkpointing.
- Return type:
- tag¶
- class firedrake.adjoint_utils.blocks.function.FunctionMergeBlock(func, idx, ad_block_tag=None)[source]¶
Bases:
Block- adj_state¶
- block_helper¶
- evaluate_hessian_component(inputs, hessian_inputs, adj_inputs, block_variable, idx, relevant_dependencies, prepared=None)[source]¶
- tag¶
firedrake.adjoint_utils.blocks.mesh module¶
- class firedrake.adjoint_utils.blocks.mesh.MeshInputBlock(mesh, ad_block_tag=None)[source]¶
Bases:
BlockBlock which links a MeshGeometry to its coordinates, which is a firedrake function.
- adj_state¶
- block_helper¶
- evaluate_hessian_component(inputs, hessian_inputs, adj_inputs, idx, block_variable, relevant_dependencies, prepared=None)[source]¶
- tag¶
- class firedrake.adjoint_utils.blocks.mesh.MeshOutputBlock(func, mesh, ad_block_tag=None)[source]¶
Bases:
BlockBlock which is called when the coordinates of a mesh are changed.
- adj_state¶
- block_helper¶
- evaluate_hessian_component(inputs, hessian_inputs, adj_inputs, idx, block_variable, relevant_dependencies, prepared=None)[source]¶
- tag¶
firedrake.adjoint_utils.blocks.solving module¶
- class firedrake.adjoint_utils.blocks.solving.GenericSolveBlock(lhs, rhs, func, bcs, *args, **kwargs)[source]¶
Bases:
Block- property adj_sol¶
- adj_state¶
- block_helper¶
- evaluate_hessian_component(inputs, hessian_inputs, adj_inputs, block_variable, idx, relevant_dependencies, prepared=None)[source]¶
- pop_kwargs_keys = ['adj_cb', 'adj_bdy_cb', 'adj2_cb', 'adj2_bdy_cb', 'forward_args', 'forward_kwargs', 'adj_args', 'adj_kwargs']¶
- tag¶
- class firedrake.adjoint_utils.blocks.solving.NonlinearVariationalSolveBlock(equation, func, bcs, adj_cache, problem_forms, solver_kwargs, **kwargs)[source]¶
Bases:
GenericSolveBlock- adj_state¶
- block_helper¶
- tag¶
- class firedrake.adjoint_utils.blocks.solving.ProjectBlock(v, V, output, bcs=[], *args, **kwargs)[source]¶
Bases:
SolveVarFormBlock- adj_state¶
- block_helper¶
- tag¶
- class firedrake.adjoint_utils.blocks.solving.SolveLinearSystemBlock(A, u, b, *args, **kwargs)[source]¶
Bases:
GenericSolveBlock- adj_state¶
- block_helper¶
- tag¶
- class firedrake.adjoint_utils.blocks.solving.SolveVarFormBlock(equation, func, bcs=[], *args, **kwargs)[source]¶
Bases:
GenericSolveBlock- adj_state¶
- block_helper¶
- tag¶
- class firedrake.adjoint_utils.blocks.solving.Solver(*values)[source]¶
Bases:
EnumEnum for solver types.
- ADJOINT = 1¶
- FORWARD = 0¶
- class firedrake.adjoint_utils.blocks.solving.SupermeshProjectBlock(source, target_space, target, bcs=[], **kwargs)[source]¶
Bases:
BlockAnnotates supermesh projection.
Suppose we have a source space, \(V_A\), and a target space, \(V_B\). Projecting a source from \(V_A\) to \(V_B\) amounts to solving the linear system
\[M_B * v_B = M_{AB} * v_A,\]- where
\(M_B\) is the mass matrix on \(V_B\),
\(M_{AB}\) is the mixed mass matrix for \(V_A\) and \(V_B\),
\(v_A\) and \(v_B\) are vector representations of the source and target
Functions.
- This can be broken into two steps:
Step 1. form RHS, multiplying the source with the mixed mass matrix;
Step 2. solve linear system.
- adj_state¶
- block_helper¶
- evaluate_adj_component(inputs, adj_inputs, block_variable, idx, prepared=None)[source]¶
Evaluate the adjoint to one output of the block
- Recall that the forward propagation can be broken down as:
Step 1. multiply \(w := M_{AB} * v_A\);
Step 2. solve \(M_B * v_B = w\).
For a seed vector \(v_B^{seed}\) from the target space, the adjoint is given by:
Adjoint of step 2. solve \(M_B^T * w = v_B^{seed}\) for \(w\);
Adjoint of step 1. multiply \(v_A^{adj} := M_{AB}^T * w\).
- evaluate_hessian_component(inputs, hessian_inputs, adj_inputs, block_variable, idx, relevant_dependencies, prepared=None)[source]¶
- evaluate_tlm_component(inputs, tlm_inputs, block_variable, idx, prepared=None)[source]¶
Given that the input is a \(Function\), we just have a linear operation. As such, the tlm is just the sum of each tlm input projected into the target space.
- tag¶
