Skip to content

Improve caching of equivalent variables in analyser model.#1389

Open
hsorby wants to merge 13 commits into
cellml:mainfrom
hsorby:cache-equiv-vars
Open

Improve caching of equivalent variables in analyser model.#1389
hsorby wants to merge 13 commits into
cellml:mainfrom
hsorby:cache-equiv-vars

Conversation

@hsorby

@hsorby hsorby commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

@hsorby hsorby requested review from agarny and nickerso April 27, 2026 22:57

@agarny agarny left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Before reviewing further, I am going to wait for PR #1390 (for issue #1379) to be reviewed and merged in since it affects the caching code.

Comment thread src/api/libcellml/analysermodel.h Outdated

@agarny agarny left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good and definitely faster! Nice!

AnalyserModel::AnalyserModelImpl::buildEquivalentVariablesCache() should probably be called in AnalyserModel::areEquivalentVariables() (if the cache hasn't already been built), but having said that we know that the analyser is going to call AnalyserModel::areEquivalentVariables() many times, so I guess it's fine to call AnalyserModel::AnalyserModelImpl::buildEquivalentVariablesCache() upon retrieving the analyser model?

Comment thread src/analyser.cpp Outdated
Comment thread src/analysermodel.cpp Outdated
Comment thread src/analysermodel.cpp
Comment thread src/analysermodel.cpp
Comment thread src/analysermodel_p.h
Comment thread src/analysermodel.cpp Outdated
Comment thread src/analysermodel_p.h
Comment thread src/analysermodel_p.h Outdated
Comment thread src/analysermodel_p.h Outdated
Comment thread src/analysermodel.cpp Outdated
Comment thread src/analysermodel_p.h Outdated
Comment thread src/analysermodel_p.h Outdated
@hsorby hsorby requested a review from agarny May 21, 2026 06:57

@agarny agarny left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks. "Just" some nitpicking.

Comment thread src/api/libcellml/analysermodel.h Outdated
Comment thread src/api/libcellml/analysermodel.h Outdated
Comment thread src/analysermodel_p.h
Comment thread src/analysermodel.cpp
Comment thread src/analysermodel_p.h
Comment thread src/analysermodel_p.h Outdated
Comment thread src/analysermodel_p.h Outdated
Comment thread .actrc Outdated
@hsorby hsorby force-pushed the cache-equiv-vars branch from 5744d8a to 1221fcd Compare May 21, 2026 09:16
@hsorby hsorby requested a review from agarny May 21, 2026 20:11

@agarny agarny left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good! Thanks!

*
* @note This function is primarily designed for use during model analysis
* by the @ref Analyser. While external usage is not programmatically
* restricted, it is not the primary intended use case.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is there a reason to "restrict" this? variable equivalence is a common aspect of CellML and many uses outside of libCellML could take advantage of a convenient and fast equivalence cache if it was pulled out of the analyser and made available as a first class part of the libCellML API. Similar to the CellML API's CeVAS service to manage connected variables...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It isn’t “restricted”, the note is trying to explain that the function may find uses by the user that the developers have not considered, and that its primary function is to facilitate fast equivalent variable lookups for the analyser. The user needs to understand the limitations of this function if they do use if for their own purposes.

If this note doesn’t convey that message in a shorter form then maybe it needs re-writing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

restricted in that its part of the analyser. I'm wondering how hard it would be to pull the equivalence cache out into its own class or maybe part of a model or something... Analysing models can only be done on complete models, whereas variable equivalence can be done any time.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don’t think that would be hard at all. Either option model based cache or first class object EquivalentVariableCache would work.

My initial thought would be to have it as a first class object to keep the model as a plain model (arguments here could be made for some of the action API that currently exist on the model). I think I would prefer to see the model become plainer over time and have actioners do work on the model. The equivalent variable cache could be one of those. I expect this would become clearer once some exploratory tests were written.

I do see this query as being a separate issue to what this pull request is addressing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants