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

Deprecate VoronoiFVM.Physics callbacks without data argument #122

Merged
merged 2 commits into from
Sep 9, 2024

Conversation

pjaap
Copy link
Member

@pjaap pjaap commented Sep 5, 2024

This patch implements a warning that is triggered if the user constructs a VoronoiFVM.Physics object with a callback function that uses only three or two arguments, respectively.

All examples were overhauled to comply with the new interface. Hereby, the data=nothing default has to be set to allow calls with and without the data argument. This needs to be done to preserve the current checks for isdata() and hasdata().
The default can be removed once the deprecated code is removed.

@codecov-commenter
Copy link

codecov-commenter commented Sep 5, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 87.50000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 83.78%. Comparing base (b176ec7) to head (c8377f4).
Report is 99 commits behind head on master.

Files with missing lines Patch % Lines
src/vfvm_physics.jl 86.36% 3 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #122      +/-   ##
==========================================
- Coverage   85.33%   83.78%   -1.56%     
==========================================
  Files          24       24              
  Lines        2803     2911     +108     
==========================================
+ Hits         2392     2439      +47     
- Misses        411      472      +61     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pjaap pjaap force-pushed the deprecate_no_data branch from 3609644 to 46d076a Compare September 5, 2024 13:39
@j-fu
Copy link
Member

j-fu commented Sep 5, 2024

Was not aware of applicable...
I think data=nothing in all the examples will puzzle users. So may be we still can find another way how to trigger the deprecation warning.

@j-fu
Copy link
Member

j-fu commented Sep 5, 2024

BTW the failure on nightly is due to some problems with RecursiveFactorizations.jl.

Copy link
Member

@j-fu j-fu left a comment

Choose a reason for hiding this comment

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

May be instead of testing for !applicable(f,nn,nn,nn,nn) we can test for applicable(f,nn,nn,nn) ?

Also this works only if the callback functions are completely generic.
Im case a user has callbacks with some typed parameters, the proposed version would create false negatives which may be tolerable, while the implemented one would create false positives.

@pjaap
Copy link
Member Author

pjaap commented Sep 6, 2024

Was not aware of applicable... I think data=nothing in all the examples will puzzle users. So may be we still can find another way how to trigger the deprecation warning.

I second that. The nothing default is only there to have a working solution. Another possibility is to provide data = [] to the physics object such that the isdata cases are fulfilled and callbacks with explicit data are done. Would you prefer that?

@pjaap
Copy link
Member Author

pjaap commented Sep 6, 2024

May be instead of testing for !applicable(f,nn,nn,nn,nn) we can test for applicable(f,nn,nn,nn) ?

Also this works only if the callback functions are completely generic. Im case a user has callbacks with some typed parameters, the proposed version would create false negatives which may be tolerable, while the implemented one would create false positives.

Indeed, this is a better way. I will change that.

@pjaap
Copy link
Member Author

pjaap commented Sep 6, 2024

After some thinking I had another idea. Instead of testing the signature of the callback functions, we directly check with applicable whether call with a data argument are possible.

  • This simplifies the examples.
  • I don't know how much this affects the speed of the code. I imagine that this check is more or less static and should be of the same cost as the isdata call. However, investigation should be done here.
  • I am not sure where to put the deprecation warning. As it is now, it spams the warning very often in the assembly.
  • There are some failing checks that needs to be investigated

@j-fu
Copy link
Member

j-fu commented Sep 6, 2024

The simplified examples are good. However the test is not static, as the assembly code calls the fwrap, so the check is done all the time, and the warning is called as well.

I had the idea to use

@kwdef mutable struct NoData
  isdata=false
end

and define

isdata(d::NoData)=d.isdata
isdata(::Any)=true

After the test with applicable, the isdata flag in NoData could be overwritten.

@pjaap
Copy link
Member Author

pjaap commented Sep 6, 2024

Yes, the applicable call within the wrapped function is not optimal. Where do you want to put the call?

The name of the proposed helper struct NoData should be MaybeData since it can represent data or not.

@j-fu
Copy link
Member

j-fu commented Sep 6, 2024

MaybeData is good. I think the applicable call should remain in the constructor of Physics.

@j-fu
Copy link
Member

j-fu commented Sep 6, 2024

As for the failing tests:

  • on nightly, this is because of RecursiveFactorizations.jl. If this persists I would open an issue there
  • I never really fixed codecov. I am not sure if it "sees" all the example tests. Should be fixed in v2 though.

@pjaap pjaap force-pushed the deprecate_no_data branch 2 times, most recently from 0638d98 to f323857 Compare September 9, 2024 08:58
@pjaap
Copy link
Member Author

pjaap commented Sep 9, 2024

Ok, I think I have a working solution with MaybeData and the heuristic for the deprecation in the constructor.

  • For some tests, e.g., Example125, the warning is still triggered. I am not sure why.
  • With the changed code we cannot call boundary_dirichlet!(args...), since there is no method which accepts a data argument. Open an issue?

@j-fu
Copy link
Member

j-fu commented Sep 9, 2024

  • In Example125, the warning comes from the testfunction system.
  • boundary_dirichlet!(system, ...) is at the edge of deprecation. It is better to specify this in the bconditon aka breaction callback.

@pjaap
Copy link
Member Author

pjaap commented Sep 9, 2024

All warnings are now fixed, as far as I saw on my local machine. A changelog entry is also added.

@pjaap
Copy link
Member Author

pjaap commented Sep 9, 2024

From my side I am now happy with the PR. I will squash this into less commits once it is approved.

@j-fu
Copy link
Member

j-fu commented Sep 9, 2024

I am happy as well - good to go!

This patch implements a warning that is triggered if the user constructs
a VoronoiFVM.Physics object with a callback function that uses only three or
two arguments, respectively.

All examples were overhauled to comply with the new interface.

A MaybeData dummy struct was added.

This helper struct represents data or not.
The purpose is to control whether we call the Physics callbacks with or without data.
A heuristic check is performed to detect the signature of the callbacks.
This can safely be removed once the deprecation phase is over.

With MaybeData the dummies nofunc2, nosrc2 and default_storage2 can be removed.
@pjaap pjaap force-pushed the deprecate_no_data branch from a891754 to c8377f4 Compare September 9, 2024 11:55
@pjaap pjaap changed the title WIP: deprecate VoronoiFVM.Physics callbacks without data argument Deprecate VoronoiFVM.Physics callbacks without data argument Sep 9, 2024
@pjaap
Copy link
Member Author

pjaap commented Sep 9, 2024

Ok, squashed into 2 commits. There was a double entry in the changelog. I fixed that in the second commit.

@pjaap pjaap merged commit 5b9ebbe into WIAS-PDELib:master Sep 9, 2024
6 of 12 checks passed
@pjaap pjaap mentioned this pull request Sep 9, 2024
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.

3 participants