Coder Social home page Coder Social logo

Comments (9)

IvanYashchuk avatar IvanYashchuk commented on August 29, 2024 1

Maybe there should be a warning or an error about this when someone tries to access Constant.block_variable.adj_value?

from firedrake.

connorjward avatar connorjward commented on August 29, 2024

We know of an issue with Constant derivative calculations. This may be related.

from firedrake.

JDBetteridge avatar JDBetteridge commented on August 29, 2024

#3261 should fix the issue Connor mentioned, do you still see the same issue on the fix branch?

from firedrake.

IvanYashchuk avatar IvanYashchuk commented on August 29, 2024

Hi Jack, I tried your branch, and unfortunately, I still see the same issue. adj_value is not computed for Constants.

from firedrake.

connorjward avatar connorjward commented on August 29, 2024

This is clearly an issue that needs further investigation, but do things work if you use a real space function instead of a Constant?

from firedrake.

connorjward avatar connorjward commented on August 29, 2024

I think I know what's going on. When we add dependencies for the assemble block we loop over form.coefficients() (source). We changed Constant to no longer inherit from a UFL Coefficient so it is getting missed as a dependency.

from firedrake.

connorjward avatar connorjward commented on August 29, 2024

Actually, I've just attempted a fix and discovered that this is probably a feature and not a bug. In particular if I add the Constants as dependencies of the assemble block I get the following error (raised here):

Traceback (most recent call last):
  File "/home/connor/Code/firedrake-dev1/src/firedrake/mfe.py", line 28, in <module>
    tape.evaluate_adj(markings=True)
  File "/home/connor/Code/firedrake-dev1/src/pyadjoint/pyadjoint/tape.py", line 232, in evaluate_adj
    self._blocks[i].evaluate_adj(markings=markings)
  File "/home/connor/Code/firedrake-dev1/src/pyadjoint/pyadjoint/tape.py", line 109, in wrapper
    return function(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/connor/Code/firedrake-dev1/src/pyadjoint/pyadjoint/block.py", line 131, in evaluate_ad
j
    adj_output = self.evaluate_adj_component(inputs,
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/connor/Code/firedrake-dev1/src/firedrake/firedrake/adjoint_utils/blocks/assembly.py", 
line 121, in evaluate_adj_component
    if self.compat.isconstant(c):
       ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/connor/Code/firedrake-dev1/src/firedrake/firedrake/adjoint_utils/blocks/compat.py", li
ne 159, in isconstant
    raise ValueError("Firedrake Constant requires a domain to work with pyadjoint")
ValueError: Firedrake Constant requires a domain to work with pyadjoint

The solution is therefore probably to use a Function in the Real space in place of Constant.

@dham is certainly the person most knowledgeable about this.

from firedrake.

dham avatar dham commented on August 29, 2024

This reflects a change in Constant, which is a feature rather than a bug. As you can see from your output, FEniCS are actually creating variables in the R space when you instantiate a Constant. Firedrake has also moved to this position but for reasons of parallel safety, we require functions over R to be defined on a mesh. This means we now have two kinds of constant. Constants without domains are really just a performance feature to enable parameters to be passed into the assembly kernel without recompilation. You can't differentiate with respect to them and hence they don't work as adjoint variables. Constants with domains get mapped to functions over R. That's what you want in this case, so you should pass the mesh in after the value in the definitions of k0 and k1

from firedrake.

IvanYashchuk avatar IvanYashchuk commented on August 29, 2024

Thanks a lot for the investigation and explaining everything! It all makes sense. I've tried using R FunctionSpace instead and it works as expected.

from firedrake.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.