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

Activate WELPI and WPIMULT for use in Pyaction #4136

Closed

Conversation

lisajulia
Copy link
Contributor

@lisajulia lisajulia commented Jul 3, 2024

To activate the WELPI keyword for the use in a PyAction, I had to add a way of communicating the old well production indices from the ActionHandler (i.e. the Well Model) back to the Schedule. For this, I have added the function setWellPIMap to the Schedule object, setting the attribute m_wellPIMap, a std::unordered_map<std::string, double>, of the Schedule . This map is set from the Action Handler before pending PyActions are executed.

Then, to further simplify the code, I have removed this map from the arguments of the handleKeyword, applyAction and iterateScheduleSection (there it was called target_wellpi), since these functions can now use the m_wellPIMap.
Then, I have removed a call that was done before for each ActionX: This call fetched such a map for the matching wells of each ActionX, but now, since we have the m_wellPIMap, these calls are not needed anymore.

It would be interesting to have a benchmark for this, possibly time and memory wise.

For the reference manual: With this PR and OPM/opm-simulators#5467, the keywords WELPI and WPIMULT can be used in the "insert keywords"-function in Pyaction.

@lisajulia
Copy link
Contributor Author

jenkins build this opm-simulators=5467 opm-tests=1193 please

1 similar comment
@lisajulia
Copy link
Contributor Author

jenkins build this opm-simulators=5467 opm-tests=1193 please

@lisajulia
Copy link
Contributor Author

lisajulia commented Jul 4, 2024

This PR contains the WELPI kw (#4133) and also WPIMULT, same for other two PRs OPM/opm-simulators#5467 and OPM/opm-tests#1193.

@lisajulia lisajulia force-pushed the feature/pyAction-insert-kw-WELPI-WPIMULT branch 2 times, most recently from 084a4e4 to b44105e Compare July 4, 2024 15:29
@lisajulia
Copy link
Contributor Author

jenkins build this opm-simulators=5467 opm-tests=1193 please

1 similar comment
@lisajulia
Copy link
Contributor Author

jenkins build this opm-simulators=5467 opm-tests=1193 please

Copy link
Member

@blattms blattms left a comment

Choose a reason for hiding this comment

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

What I am wondering is the lifetime of the member of wellPIMap. Please elaborate a bit.

It is a member, Yet it seems to be used only as a temporary.

@lisajulia lisajulia force-pushed the feature/pyAction-insert-kw-WELPI-WPIMULT branch 2 times, most recently from dce741f to f641a36 Compare July 9, 2024 16:15
@lisajulia
Copy link
Contributor Author

jenkins build this opm-simulators=5467 opm-tests=1193 please

@lisajulia lisajulia requested a review from blattms July 9, 2024 16:19
@lisajulia
Copy link
Contributor Author

@blattms: I've updated the description, also we can discuss if this really is the best approach before merging! Thanks!

@lisajulia
Copy link
Contributor Author

jenkins build this opm-simulators=5467 opm-tests=1193 please

@blattms
Copy link
Member

blattms commented Jul 10, 2024

benchmark please

@blattms
Copy link
Member

blattms commented Jul 10, 2024

No realize that this benchmark will not work as it needs the other branches. I'll try with the correct repos, but I don't know whether the cases tested even use ACTIONX/PYACTION.

@blattms
Copy link
Member

blattms commented Jul 10, 2024

benchmark opm-simulators=5467 opm-tests=1193 please

@ytelses
Copy link

ytelses commented Jul 10, 2024

Benchmark result overview:

Test Configuration Relative
opm-git OPM Benchmark: drogon - Threads: 1 0.997
opm-git OPM Benchmark: drogon - Threads: 8 1.23
opm-git OPM Benchmark: punqs3 - Threads: 1 1
opm-git OPM Benchmark: punqs3 - Threads: 8 1.027
opm-git OPM Benchmark: smeaheia - Threads: 1 0.994
opm-git OPM Benchmark: smeaheia - Threads: 8 1.135
opm-git OPM Benchmark: spe10_model_1 - Threads: 1 1.001
opm-git OPM Benchmark: spe10_model_1 - Threads: 8 1.003
opm-git OPM Benchmark: flow_mpi_extra - Threads: 1 0.971
opm-git OPM Benchmark: flow_mpi_extra - Threads: 8 1.145
opm-git OPM Benchmark: flow_mpi_norne - Threads: 1 0.988
opm-git OPM Benchmark: flow_mpi_norne - Threads: 8 1.062
opm-git OPM Benchmark: flow_mpi_norne_4c_msw - Threads: 1 0.984
opm-git OPM Benchmark: flow_mpi_norne_4c_msw - Threads: 8 1.067
  • Speed-up = Total time master / Total time pull request. Above 1.0 is an improvement. *

View result details @ https://www.ytelses.com/opm/?page=result&id=2545

@lisajulia
Copy link
Contributor Author

Benchmark result overview:
Test Configuration Relative
opm-git OPM Benchmark: drogon - Threads: 1 0.997
opm-git OPM Benchmark: drogon - Threads: 8 1.23
opm-git OPM Benchmark: punqs3 - Threads: 1 1
opm-git OPM Benchmark: punqs3 - Threads: 8 1.027
opm-git OPM Benchmark: smeaheia - Threads: 1 0.994
opm-git OPM Benchmark: smeaheia - Threads: 8 1.135
opm-git OPM Benchmark: spe10_model_1 - Threads: 1 1.001
opm-git OPM Benchmark: spe10_model_1 - Threads: 8 1.003
opm-git OPM Benchmark: flow_mpi_extra - Threads: 1 0.971
opm-git OPM Benchmark: flow_mpi_extra - Threads: 8 1.145
opm-git OPM Benchmark: flow_mpi_norne - Threads: 1 0.988
opm-git OPM Benchmark: flow_mpi_norne - Threads: 8 1.062
opm-git OPM Benchmark: flow_mpi_norne_4c_msw - Threads: 1 0.984
opm-git OPM Benchmark: flow_mpi_norne_4c_msw - Threads: 8 1.067

* Speed-up = Total time master / Total time pull request. Above 1.0 is an improvement. *

View result details @ https://www.ytelses.com/opm/?page=result&id=2545

Hm.. the main change performance-wise is that instead of fetching the well productions indices for each action per step, we fetch those now once per step (only if there are pending actions or pyactions, if there are no actions, we don't fetch anything at all).
Can this change really produce such high differences, like
OPM Benchmark: drogon - Threads: 8 : 1.23
OPM Benchmark: flow_mpi_extra - Threads: 1: 0.971 ?

@blattms
Copy link
Member

blattms commented Jul 11, 2024

Let's rerun. A serial run should not be affected by this.

@blattms
Copy link
Member

blattms commented Jul 11, 2024

benchmark opm-simulators=5467 opm-tests=1193 please

@lisajulia lisajulia force-pushed the feature/pyAction-insert-kw-WELPI-WPIMULT branch 2 times, most recently from 2851055 to 32bde2e Compare August 13, 2024 14:02
@lisajulia
Copy link
Contributor Author

jenkins build this opm-simulators=5467 opm-tests=1193 please

@lisajulia
Copy link
Contributor Author

@blattms: what is the further plan with this?

@lisajulia lisajulia force-pushed the feature/pyAction-insert-kw-WELPI-WPIMULT branch from 32bde2e to af89438 Compare December 17, 2024 17:17
@lisajulia
Copy link
Contributor Author

jenkins build this opm-simulators=5467 please

@lisajulia
Copy link
Contributor Author

benchmark opm-simulators=5467 please

@lisajulia lisajulia force-pushed the feature/pyAction-insert-kw-WELPI-WPIMULT branch from af89438 to 8494806 Compare December 18, 2024 10:45
@lisajulia
Copy link
Contributor Author

jenkins build this opm-simulators=5467 please

2 similar comments
@lisajulia
Copy link
Contributor Author

jenkins build this opm-simulators=5467 please

@lisajulia
Copy link
Contributor Author

jenkins build this opm-simulators=5467 please

@lisajulia lisajulia force-pushed the feature/pyAction-insert-kw-WELPI-WPIMULT branch from eea26f0 to 16de16f Compare December 24, 2024 07:05
@lisajulia
Copy link
Contributor Author

jenkins build this opm-simulators=5467 please

@bska
Copy link
Member

bska commented Jan 6, 2025

I haven't looked at the details here, I'll do that later, but I would really prefer that we not add the proposed data member since the Schedule is supposed to contain information that's inferred from the model input only. Of course the WELPI keyword is rather strongly coupled to the dynamic simulator state since we need the current PI (or II) values in order to interpret the input data, but I still think we should aim to keep the input and the dynamically calculated information distinct. Is there really no other way of supplying the PI values than through this side channel?

@lisajulia
Copy link
Contributor Author

I haven't looked at the details here, I'll do that later, but I would really prefer that we not add the proposed data member since the Schedule is supposed to contain information that's inferred from the model input only. Of course the WELPI keyword is rather strongly coupled to the dynamic simulator state since we need the current PI (or II) values in order to interpret the input data, but I still think we should aim to keep the input and the dynamically calculated information distinct. Is there really no other way of supplying the PI values than through this side channel?

Yes, I know this is not ideal, yet I need to communicate back the well production indices back to the Schedule.
For an ACTIONX, this is possible through passing such a map in the call applyAction (https://github.com/OPM/opm-simulators/pull/5467/files#diff-ebf1a517eb80b2cd88977997fa304cc0c6bd1750afdf14a8186ba2a763d1dedfR240), yet for a Pyaction there is no such call:

  • A Pyaction is invoked by
    SimulatorUpdate Schedule::runPyAction(std::size_t reportStep, const Action::PyAction& pyaction, Action::State& action_state, EclipseState& ecl_state, SummaryState& summary_state) {
  • The actual python code is executed by
    bool PyRunModule::run(EclipseState& ecl_state, Schedule& sched, std::size_t report_step, SummaryState& st, const std::function<void(const std::string&, const std::vector<std::string>&)>& actionx_callback) {
  • Without reintroducing something like the actionx_callback function it's not possible to access the simulator from the PyRunModule anymore.

Hence, my approach was to give a map containing all PI values to the Schedule before the Pyactions and ActionX's get executed, then also this map does not need to be passed around in all applyAction functions like before.

It might also be a (possibly wiser) option to move all the Pyaction/Python classes to opm-simulators and make them aware of the ActionHandler, yet I have not estimated other implications this would have, since it's a rather large change.

@lisajulia lisajulia force-pushed the feature/pyAction-insert-kw-WELPI-WPIMULT branch from 16de16f to efc8094 Compare January 8, 2025 11:55
@lisajulia
Copy link
Contributor Author

jenkins build this opm-simulators=5467 please

@lisajulia
Copy link
Contributor Author

@bska: How do you suggest to move on with this? Thanks!

…the WELPI keyword and not only for ActionX but also for Pyaction
This indicates that the 'handleWELPIRuntime' instead of 'handleWELPI' function should be used when inserting the keyword WELPI from a PyAction
…d function

This is not needed anymore, since welpi_action_mode is an attribute of the Schedule.
This is set in the ActionHandler.
Use the wellPIMap when calling handleKeyword in the applyKeywords function.
…ion function

Instead, use the wellPIMap of the Schedule Object
@lisajulia lisajulia force-pushed the feature/pyAction-insert-kw-WELPI-WPIMULT branch from efc8094 to 075feb8 Compare January 9, 2025 15:46
@lisajulia
Copy link
Contributor Author

jenkins build this opm-simulators=5467 please

@bska
Copy link
Member

bska commented Jan 10, 2025

Hence, my approach was to give a map containing all PI values to the Schedule before the Pyactions and ActionX's get executed

As a side effect, this makes every action more expensive since this means unconditionally computing information that's needed only if the action involves WELPI.

then also this map does not need to be passed around in all applyAction functions like before.

To be honest, I actually like the separate argument. It makes the separation between static and dynamic information more explicit. By putting the current PIs into the Schedule object, it becomes an implicit argument to every member function of Schedule, but it's only needed for one of them (Schedule::handleKeyword()–admittedly a rather important member function) and, moreover, whether or not it contains consistent information is completely controlled outside of Schedule.

How do you suggest to move on with this

How does the current PyAction system work? Most of the examples in opm-tests/pyaction appear to go through one of the insert_keywords() overloads which in turn end up in Schedule::applyKeywords(). Is that the expected mechanism? If so, is there anything that prevents adding a kind of dynamic state parameter to Schedule::applyKeywords() and passing the PI information through that? Every invocation of PyRunModule::run() maintains a set of attributes in the opm_embedded module, and the current_report_step is updated on every call. Could you not pass additional state through such an attribute?

@lisajulia
Copy link
Contributor Author

Closing as the alternative was merged

@lisajulia lisajulia closed this Jan 20, 2025
@lisajulia lisajulia deleted the feature/pyAction-insert-kw-WELPI-WPIMULT branch January 20, 2025 13:44
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.

4 participants