Skip to content

WalkerLogXXX should provide move constructors#5567

Merged
ye-luo merged 7 commits intoQMCPACK:developfrom
PDoakORNL:fix_constructors_walker_log
Jul 2, 2025
Merged

WalkerLogXXX should provide move constructors#5567
ye-luo merged 7 commits intoQMCPACK:developfrom
PDoakORNL:fix_constructors_walker_log

Conversation

@PDoakORNL
Copy link
Contributor

@PDoakORNL PDoakORNL commented Jul 1, 2025

Proposed changes

I see no documented reason for why move constructors or the rule of five in general should be broken for WalkerLog* classes. And it became a subtle use after return asan issue when refactoring batched drivers. I have addressed this sufficiently to address work needed for testing of variable estimator measurements to be sound and testable. I have also added the the beginning of actual unit testing for WalkerLogManager and a testing data class for WalkerLogInput.

There was a nasty shared state reference which so far looks to have been unused. This will all get more coverage int he variable esimator measurement period PR.

What type(s) of changes does this code introduce?

Delete the items that do not apply

  • Bugfix
  • New feature
  • Documentation or build script changes
  • Other (please describe):

Does this introduce a breaking change?

  • No

What systems has this change been tested on?

Checklist

Update the following with an [x] where the items apply. If you're unsure about any of them, don't hesitate to ask. This is
simply a reminder of what we are going to look for before merging your code.

    • I have read the pull request guidance and develop docs
    • This PR is up to date with the current state of 'develop'
    • Code added or changed in the PR has been clang-formatted
    • This PR adds tests to cover any new code, or to catch a bug that is being fixed
    • Documentation has been added (if appropriate)

@PDoakORNL PDoakORNL changed the title [WIP] WalkerLogXXX should provide move constructors WalkerLogXXX should provide move constructors Jul 2, 2025
@PDoakORNL PDoakORNL force-pushed the fix_constructors_walker_log branch from f774e86 to fd410a9 Compare July 2, 2025 17:17
@PDoakORNL
Copy link
Contributor Author

For me this is useless without #5566 but it seems that for the CI machines that PR is not needed to use asan.

Copy link
Contributor

@ye-luo ye-luo left a comment

Choose a reason for hiding this comment

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

Does adding default copy, move constructors and assign operator change any code behavior? I though they are already there implicitly. Is there any functional change?

* If you want to do a state transform write a function, document
* it, call it from a sensible and obvious scope.
*/
WalkerLogState state_;
Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC. WalkerLogManager owns and manipulates the state_ and WalkerLogState only reads it. In this way, per crowd WalkerLogState won't go out of sync. For that reason, keeping it a const ref seems fine to me. What is your motivation to make it a copy especially a non-const copy?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sent out review before my laptop died. Continue reading the added test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You cannot move a ref.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you make it at least a const?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So multiple threads spectate on a single memory location to stay "synchronized"? examining the source shows no evidence this anti feature is used and no crowd level resources state should be getting controlled in this manner. If this needs to be updated then a call can be made to change the behavior of the per crowd loggers.

CollectorHolder ch;
ch.setWalkerLogCollector(wlm.makeCollector());
return {std::move(wlm), std::move(ch)};
};
Copy link
Contributor

Choose a reason for hiding this comment

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

This factory function shows the tight connection between the manager and collectors as it returns them as a whole structure.

We can write the code as

   auto make_stuff = [comm](WalkerLogInput& walker_log_input) -> LogAndStuff {
-    WalkerLogManager wlm{walker_log_input, true, "root_name", comm};
-    CollectorHolder ch;
-    ch.setWalkerLogCollector(wlm.makeCollector());
-    return {std::move(wlm), std::move(ch)};
+    LogAndStuff logger{{walker_log_input, true, "root_name", comm}, {}};
+    logger.ch.setWalkerLogCollector(logger.wlm.makeCollector());
+    return logger;
   };

In this way, the hassle of move constructors can be avoided and also reduce the number copy operations.

The intention of introducing move constructor and operator is to bring real benefit. It is not worth maintaining move constructor and operators rigorously in every class but only places we benefit. Hopefully everyone agrees with that.

Copy link
Contributor

Choose a reason for hiding this comment

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

The above was my opinion. This is not a request for change.
We can keep the code as you changed for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a point in blocking this other than making the refactoring I need to do to implement effective testing for a requested feature harder? I think ease of testing refactoring trumps weasling out of providing sane threaded design and basic constructors.

I'm correcting a design issue that should have never gotten through review the reference used as a back door state update and fixing the lack of clear declaration of constructors.

Copy link
Contributor

@ye-luo ye-luo Jul 2, 2025

Choose a reason for hiding this comment

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

Probably you missed my other comment, I'm not making a request for change in this area of code. The blocking reason is missing CMake changes in this PR. Your added code is not compiled and tested.

To be honest, the name state made me feel it may carry variable like step counters. If that was the case, I wanted it to be a const ref in collectors and let the manager to operate it.
But the source code WalkerLogState really shows it is just parsed input. So copy is fine.

Copy link
Contributor

@ye-luo ye-luo left a comment

Choose a reason for hiding this comment

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

Please connect test_WalkerLogManager.cpp in CMake.

@PDoakORNL PDoakORNL requested a review from prckent July 2, 2025 20:14
@PDoakORNL
Copy link
Contributor Author

Working on too many things at once, somehow I lost the cmake changes in the shuffle.

@ye-luo
Copy link
Contributor

ye-luo commented Jul 2, 2025

Test this please

@ye-luo ye-luo enabled auto-merge July 2, 2025 22:17
@ye-luo ye-luo merged commit af6914a into QMCPACK:develop Jul 2, 2025
42 checks passed
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