Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] response function interface #6594

Merged
merged 9 commits into from
Apr 6, 2020

Conversation

armingeiser
Copy link
Member

This adds a top level interface for any kind of response functions. This allows to use them easily on python level e.g. for Optimization.

This interface was previously used in individual applications e.g. StructMech and ShapeOpt and would also be added to ConvectionDiffusion in #6584.

Suggested here: #6584 (comment)


class ResponseFunctionBase(object):
"""The base class for response functions. Each response function
class ResponseFunctionInterface(object):
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the new file in the core - Github shows it as moved...

Copy link
Member

Choose a reason for hiding this comment

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

Just out of curiosity: Is there a reason, why you called it "Interface" rather than "Base" or just "ResponseFunction"?

Copy link
Member

Choose a reason for hiding this comment

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

could you explain the relation btw this class and the AdjointResponseFunction?
This should help with the naming

Copy link
Member Author

Choose a reason for hiding this comment

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

The AdjointResponseFunction provides some of the necessary components for an adjoint sensitivity analysis:

  • gradient w.r.t to the primal variables (and their derivatives)
  • partial gradient w.r.t to the design variable

However it does not calculate the total gradient of the response function w.r.t the design variables.
This can only be obtained using the whole framework of adjoint_solver, adjoint_response_function and sensitivity_builder.

Besides the adjoint approach to calculate the gradient, there are several other ways - fore some e.g. geometrical response functions, the adjoint approach does not even make sense.

This response function interface provides a unique interface for all possible ways to calculate the value and gradients of a response.
This is necessary because e.g. in optimization i do not care about the implementation details (e.g. how the adjoint sensitivity analysis uses the adjoint_response_function.h ...) but i am just interested in the value and gradient of the response.

Copy link
Member

Choose a reason for hiding this comment

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

cool thx for the explanation

Could you please add sth like this to the docstring of the class?

Copy link
Member

@MFusseder MFusseder left a comment

Choose a reason for hiding this comment

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

I am fine with the suggested modifications. Especially I appreciate the more general get gradient functions. As written I would also add something like GetConditionalGradient.

dbaumgaertner
dbaumgaertner previously approved these changes Mar 25, 2020
Copy link
Member

@dbaumgaertner dbaumgaertner left a comment

Choose a reason for hiding this comment

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

I would approve it as it looks good to me. Just some minor comments. It's good to see a unified interface of the response functions in the core. Thanks for the effort. Before merging though, it would be good to have somebody from the core guys to quickly double-check the PR @philbucher .


class ResponseFunctionBase(object):
"""The base class for response functions. Each response function
class ResponseFunctionInterface(object):
Copy link
Member

Choose a reason for hiding this comment

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

Just out of curiosity: Is there a reason, why you called it "Interface" rather than "Base" or just "ResponseFunction"?

@dbaumgaertner
Copy link
Member

You might also remove the trailing whitespace as suggested by codacy

@philbucher
Copy link
Member

I would like to review this but I need a few days, I would appreciate if you wait :)

@armingeiser
Copy link
Member Author

I would like to review this but I need a few days, I would appreciate if you wait :)

No worries =)

@philbucher philbucher added this to To Do in TODO philbucher via automation Mar 26, 2020
@philbucher philbucher moved this from To Do to To be reviewed in TODO philbucher Mar 26, 2020
Copy link
Member

@philbucher philbucher left a comment

Choose a reason for hiding this comment

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

some comments

Just to be clear, this should also be used in Fluids?

kratos_utilities.DeleteFileIfExisting("perturbed_part.post.bin")
Copy link
Member

Choose a reason for hiding this comment

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

I would disable writing this in a test
It only takes time and is not used in 99% of times this test is run
and if you want to look at the output then you wouldn't delete it ;)


class ResponseFunctionBase(object):
"""The base class for response functions. Each response function
class ResponseFunctionInterface(object):
Copy link
Member

Choose a reason for hiding this comment

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

could you explain the relation btw this class and the AdjointResponseFunction?
This should help with the naming

kratos_utilities.DeleteFileIfExisting("structure.post.bin")
Copy link
Member

Choose a reason for hiding this comment

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

idem

Copy link
Member Author

Choose a reason for hiding this comment

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

I see the point, however this would be something for a new MR, as this is just a whitespace change here and not related.

@philbucher
Copy link
Member

Idk why but my comments are inline with the comments of @dbaumgaertner
=> go to Files changed then it is more readable

@armingeiser
Copy link
Member Author

Just to be clear, this should also be used in Fluids?
@philbucher

It can, but i have no plans currently. The Fluid/Structural/ConvDiff use the same workflow and base classes for their adjoint sensitivity analysis - so it should be possible.

One point that is worth mentioning is that in for structures there is sensitivity analysis only for steady state sensitivities, while for fluid it is only (?) available for transient cases.

@armingeiser armingeiser marked this pull request as ready for review April 2, 2020 13:57
@armingeiser armingeiser requested a review from a team as a code owner April 2, 2020 13:57
@armingeiser
Copy link
Member Author

@marcnunezc This is essentially the interface i gave you some time ago to test optimization with the CompressiblePotentialFlowApplication.

Copy link
Contributor

@marcnunezc marcnunezc left a comment

Choose a reason for hiding this comment

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

@marcnunezc This is essentially the interface i gave you some time ago to test optimization with the CompressiblePotentialFlowApplication.

Yes! I have been using that as a custom script ever since, thanks for the effort!

I am OK with the general response interface, I only have a question regarding the reporting of the gradient.

@philbucher
Copy link
Member

so from my side this is ready to go in if the involved ppl are ok with it
@KratosMultiphysics/technical-committee I think we don't need to review this in detail for the same reason (we have enough more important things to do)
@marcnunezc I suggest to approve if you are ok with it

thanks for the efforts!

@philbucher
Copy link
Member

philbucher commented Apr 3, 2020

@armingeiser I think you didn't set your editor to auto-delete trailing whitespaces

This happens when editing files using the github online file editor =)

Copy link
Contributor

@marcnunezc marcnunezc left a comment

Choose a reason for hiding this comment

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

Ok!

@armingeiser armingeiser merged commit 349c02b into master Apr 6, 2020
TODO philbucher automation moved this from To be reviewed to Done Apr 6, 2020
@armingeiser armingeiser deleted the Core/response-function-interface branch April 6, 2020 13:40
armingeiser added a commit that referenced this pull request Apr 8, 2020
armingeiser added a commit that referenced this pull request Apr 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

5 participants