-
Notifications
You must be signed in to change notification settings - Fork 11
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
Jmm/indexable types #470
base: main
Are you sure you want to change the base?
Jmm/indexable types #470
Conversation
I also revise the PTE solver to now actually access the lambda indexer, unless it is passed a |
One thing we may wish to consider down the line: should we be backwards compatible with integer indexing in lambdas? Or should we eventually remove that optionality? Currently, that's used in the xrage code |
(I'm reviewing right now) My opinion is that we should by default use a named approach within our code. I'd have to think more about what would be best for the vector interface though. |
Yeah agreed. This isn't something we need to change right now. But if we break backwards compatibility some of the template/sfinae complexity I implement here can go away. I'm reluctant to completely remove it right now though, as the backwards compatibility gives us time to transition and test how it feels and where it might break. |
Tests now passing on re-git. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's worth considering breaking out the square bracket invocable check from the base class. I think that would simplify some of this code significantly.
PORTABLE_FORCEINLINE_FUNCTION | ||
auto GetLambda(std::size_t m) const { | ||
if constexpr (needs_cache_) { | ||
return Cache[m]; | ||
} else { | ||
return lambda[m]; | ||
} | ||
} | ||
|
||
static constexpr const bool needs_cache_ = | ||
std::is_same<LambdaIndexer, NullIndexer>::value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic here confuses me a bit. I fee like if the NullIndexer
is provided, it should signal that no lambda
information is given. Whereas I feel like here you're trying to communicate that the lambda information is in the Cache
array.
What if instead you had a default template argument for LambdaIndexer
and set that to something other than the NullIndexer
? The basic idea I'm exploring is that I feel like there's a place to provide a NullIndexer
when either all EOS don't care about lambda
information or that information is optional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea here is that if the lambda indexer is passed in as a null indexer, we still need a cache---we can't pass in nullptr. That's because the PTE solver may be caching log density and log temperature for root finds for SpinerEOS. That's what this mechanism is for.
That said, maybe the code base has moved beyond needing this, as I think everywhere where we call the PTE solver, we manage the cache ourselves. If we are happy with always managing the cache ourselves, then this can be removed. We can just always call the lambda indexer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am going to remove this special logic and assume that the lambda is always manually managed externally. get_sg_*
and friends already do this, so long as the size of the scratch array is properly computed. I think it's actually long past time we remove this weird internal logic where the PTE solver manages its own cache. (Which we can blame on me... I added it in the first place as a hack.)
… free-floating function so it looks more like stl functionality. 2. remove the weird caching logic inside PTE solvers. Host code MUST provide cache or a nullindexer lambda.
Thanks for the review @jhp-lanl ! I think all your comments should be resolved now. |
if constexpr (is_indexable_v<Indexer_t, IndexableTypes::MeanIonizationState>) { | ||
return std::max(0.0, lambda[IndexableTypes::MeanIonizationState()]); | ||
} else { | ||
return std::max(0.0, lambda[t_.nlambda()]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work if I nest modifiers each of which requires lambdas?
PR Summary
While integrating 3T into riot, I began to encounter scenarios where the
lambda
machinery ofsingularity-eos
starts to become burdensome. In particular, the z-split modifier on top of (for example) aSpinerEOS
means that both the base/underlying EOS and the modifier requirelambda
arguments. This is fine in principle; modifier lambda arguments get "appended" on to the back of the lambda and the code traverses through it like a stack. However, given that type is erased, it can be difficult for a host code to keep track of what lambda argument goes where, or even if a lambda argument is needed.This MR resolves this issue by the introduction of
IndexableTypes
which may be used in indexers for lambdas. Put simply, anIndexableType
is an empty struct that can be used to name an index, like an enum, but more free-form. If you overload theoperator[]
function for a lambda indexer to accept anIndexableType
, most EOS classes that expectIndexableTypes
will be able to interact with it by name, rather than position in the lambda. For example, if you define:then you would be able to interact with it as
integer and named indexes are interchange-able and backwards compatible, and I provide the ability to create new named types for custom EOS's as well as a convenience struct that automatically builds an indexer form a variadic list of named types. This machinery is all in the
singularity-eos/base/indexable_types.hpp
header.I also introduce the function
NeedsLambda
, which is now exposed in the variant. This function takes an indexable type and returns true if that indexable type is needed by the class for a given lambda and false otherwise.PR Checklist
make format
command after configuring withcmake
.If preparing for a new release, in addition please check the following:
when='@main'
dependencies are updated to the release version in the package.py