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

Timer interface improvement #3328

Merged
merged 10 commits into from
Sep 11, 2024
Merged

Timer interface improvement #3328

merged 10 commits into from
Sep 11, 2024

Conversation

schnellerhase
Copy link
Contributor

@schnellerhase schnellerhase commented Jul 31, 2024

Timer interface simplified in both cpp and python part, making use of std::optional.

@schnellerhase
Copy link
Contributor Author

If the optional handling is the path of choice, reconsider #3283

cpp/dolfinx/common/Timer.cpp Outdated Show resolved Hide resolved
cpp/dolfinx/common/Timer.cpp Outdated Show resolved Hide resolved
cpp/dolfinx/common/Timer.cpp Outdated Show resolved Hide resolved
cpp/dolfinx/common/Timer.cpp Outdated Show resolved Hide resolved
cpp/dolfinx/common/Timer.h Outdated Show resolved Hide resolved
@schnellerhase
Copy link
Contributor Author

This means that the optional interface is the path of choice?

@schnellerhase
Copy link
Contributor Author

List of further optionals to change:

  • set_bc: make $x_0$ optional
  • refine
  • (not strictly optional) locate_dofs_topological

Copy link
Member

@garth-wells garth-wells left a comment

Choose a reason for hiding this comment

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

Looking good, almost there.

cpp/dolfinx/common/Timer.cpp Outdated Show resolved Hide resolved
@@ -152,8 +153,7 @@ void common(nb::module_& m)
nb::arg("global"));
// dolfinx::common::Timer
nb::class_<dolfinx::common::Timer>(m, "Timer", "Timer class")
.def(nb::init<>())
.def(nb::init<std::string>(), nb::arg("task"))
.def(nb::init<std::string>(), nb::arg("task") = nb::none())
Copy link
Member

Choose a reason for hiding this comment

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

Let's remove the default arg in the wrapper layer. Since we wrap the interface in the Python layer, best to handle the default arg there. Defaults in too many places can lead to bugs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This does not work, faced the same problem within #3322 - I'm not sure what causes this or how it may be fixed, but somehow only when the nb::none() is provided it properly picks up on the python None to cpp std::nullopt conversion.

Copy link
Member

Choose a reason for hiding this comment

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

@garth-wells
Copy link
Member

This means that the optional interface is the path of choice?

Yes, when it makes logical sense, i.e. when none is appropriate. We shouldn't use it when a default value makes sense, e.g. a solver tolerance.

@schnellerhase schnellerhase changed the title Optional arguments Timer interface improvement Sep 10, 2024
@schnellerhase schnellerhase marked this pull request as ready for review September 10, 2024 18:25
@schnellerhase
Copy link
Contributor Author

I'll file an issue for the remaining cases, then we can merge this one already.

@garth-wells garth-wells added this pull request to the merge queue Sep 11, 2024
Merged via the queue into FEniCS:main with commit ad40e35 Sep 11, 2024
14 of 15 checks passed
schnellerhase added a commit to schnellerhase/dolfinx that referenced this pull request Sep 11, 2024
* Adapt Timer

* Remove space

* Switch to member variable being optional

* clang-format

* Fix python export

* Remove move

* Remove none from python export

* Re add nb::none

* Update python/dolfinx/wrappers/common.cpp

---------

Co-authored-by: Garth N. Wells <gnw20@cam.ac.uk>
@schnellerhase schnellerhase deleted the optional branch September 19, 2024 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants