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

Batched driver move abstraction #3762

Merged
merged 40 commits into from
Feb 17, 2022

Conversation

camelto2
Copy link
Contributor

@camelto2 camelto2 commented Jan 25, 2022

Please review the developer documentation
on the wiki of this project that contains help and requirements.

Proposed changes

This PR adds an abstraction layer to the batched drivers for the particle moves. It is intended to keep the VMC/DMC advanceWalkers agnostic about the actual moves that are being done (just particle positions, positions and spins, etc). Right now advanceWalkers is templated on a move type, and uses the templated class MoveAbstraction to handle the specifics of the moves. I am happy to change any names for classes/functions/etc here to make things more clear, I was more concerned with getting something working.

note: Eventually this should be able to handle the work needed for the L2potentials as well

part of #3712, and would allow me to delete #3742

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

Delete the items that do not apply

  • New feature

Does this introduce a breaking change?

  • No

What systems has this change been tested on?

macOSX

Checklist

Update the following with a yes 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.

  • Yes. This PR is up to date with current the current state of 'develop'
  • Yes. Code added or changed in the PR has been clang-formatted
  • No. This PR adds tests to cover any new code, or to catch a bug that is being fixed
  • Yes. Documentation has been added (if appropriate)

@camelto2 camelto2 requested a review from ye-luo January 25, 2022 01:02
@PDoakORNL PDoakORNL self-requested a review January 25, 2022 01:23
@camelto2
Copy link
Contributor Author

Need to follow up and add comments to everything

@camelto2
Copy link
Contributor Author

Need to follow up and add comments to everything

I added documentation detailing the intention of each method in the MoveAbstraction class and describing each member variable. Also updated the docs to include the spin mass in the batched driver sections

@ye-luo
Copy link
Contributor

ye-luo commented Jan 25, 2022

Here is my thoughts

  1. MoveAbstraction constructor should capture ps_dispatcher and walker_elecs. Leave twf_dispatcher out.
  2. Pass twf_dispatcher explicitly in APIs need it.
  3. There should no trace of Crowd object in MoveAbstraction
  4. acceptMove should be wrapped symmetrically to makeMove.

Replace mw_makeMoveWithSpin with mw_makeSpinMove which only deal with spin part. Call flex_makeMove and mw_makeSpinMove in the abstraction.
Add mw_accept_rejectSpinMove. Move the touch of spins from mw_accept_rejectMove to this new function and call it from the wrapper.

still thinking about a better name for MoveAbstraction. MoveManipulator? The object name should be a noun, not "move". Will can do the change once we settle the class name.

#ifndef QMCPLUSPLUS_MOVEABSTRACTION_H
#define QMCPLUSPLUS_MOVEABSTRACTION_H

#include "QMCDriverNew.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Move the ENUM in this class. This class doesn't need to depend on QMCDriverNew

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

@PDoakORNL PDoakORNL left a comment

Choose a reason for hiding this comment

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

This PR sets up a new state machine and mixed data and operations class.
Due to the large upfront capture of variables and state members it hides the actual data dependence of many steps of the qmc section which I consider to be undesirable.
The methods are almost all state transformations of the object and not clean functions.

While I feel that breaking up advance walkers into pure functions would be worth while I think templating or giving them if constexpr sections based the Monte Carlo Coordinate type is a much cleaner way to add this functionality.

I would propose working from a different start such as in #3767

@ye-luo
Copy link
Contributor

ye-luo commented Jan 25, 2022

@PDoakORNL can we first complete this one and then work on refactoring? #3767 is a prototype and only partially address what is abstracted in this PR. So it takes a bit more time to work out a fully satisfactory design.

@camelto2
Copy link
Contributor Author

Here is my thoughts

1. MoveAbstraction constructor should capture ps_dispatcher and walker_elecs. Leave twf_dispatcher out.

2. Pass twf_dispatcher explicitly in APIs need it.

3. There should no trace of Crowd object in MoveAbstraction

This is taken care of with the recent push. Looking at the changes to particleset now.

@@ -233,7 +213,13 @@ void VMCBatched::runVMCStep(int crowd_id,
const bool recompute_this_step = (sft.is_recomputing_block && (step + 1) == max_steps);
// For VMC we don't call this method for warmup steps.
const bool accumulate_this_step = true;
advanceWalkers(sft, crowd, timers, *context_for_steps[crowd_id], recompute_this_step, accumulate_this_step);
const bool spin_move = crowd.get_walker_elecs()[0].get().isSpinor();
Copy link
Contributor

Choose a reason for hiding this comment

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

This line can be dangerous if there is no element.
Pass the state via the sft object.
Also use population_.get_golden_electrons()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -80,68 +78,37 @@ void VMCBatched::advanceWalkers(const StateForThread& sft,
std::vector<std::reference_wrapper<TrialWaveFunction>> twf_accept_list, twf_reject_list;
isAccepted.reserve(num_walkers);

MoveAbstraction<COORDS> move(ps_dispatcher, walker_elecs, step_context.get_random_gen(), sft.drift_modifier,
Copy link
Contributor

Choose a reason for hiding this comment

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

Let us change this to 'mover' a noun.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

ye-luo
ye-luo previously approved these changes Jan 26, 2022
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.

LGTM. I'm inclined to merge this for fast turnaround and avoid working on forks although I consider MoveAbstraction should go away as we get #3767 ready.

@camelto2
Copy link
Contributor Author

camelto2 commented Feb 9, 2022

Made a significant change to this PR. This should be more in line with what @PDoakORNL was thinking.

I completely removed the MoveAbstraction class which this PR introduced.
Instead, I have introduced a new struct TWFGrads, similar to how MCCoords was introduced in #3774, which gets templated on the CoordsType. This allows me to carry around TWFGrads grads_now, grads_new in the advanceWalkers which will carry spatial gradients and spin gradients depending on the CoordsType. This also allowed me to template the TWFdispatcher on CoordsType, so that I can use a templated flex_ API to decide if it is including spin or not for the gradients.
I also templated DriftModifierBase which removes a lot of the divergent code for normal vs. spin calculations in advanceWalkers.

With a little more work, the advanceWalkers will be further simplified so it doesn't have to have any "if constexpr (CT==CoordsType::POS_SPIN)" code

@PDoakORNL
Copy link
Contributor

Will start rereview this afternoon.

@PDoakORNL PDoakORNL dismissed their stale review February 15, 2022 15:11

Seems stale.

PDoakORNL
PDoakORNL previously approved these changes Feb 16, 2022
Copy link
Contributor

@PDoakORNL PDoakORNL left a comment

Choose a reason for hiding this comment

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

This looks like a good step. If there is time fix the attribution for TauParams.

@@ -386,6 +385,16 @@ class ParticleSet : public QMCTraits, public OhmmsElementBase, public PtclOnLatt
const std::vector<bool>& isAccepted,
bool forward_mode = true);

/** batched version of acceptMove and reject Move fused, but only for spins
*
* note: should be called BEFORE mw_accept_rejectMove since the active_ptcl_ gets reset to -1
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for documenting the state requirement.

//
// Copyright (c) 2022 QMCPACK developers.
//
// File developed by: Ye Luo, [email protected], Argonne National Laboratory
Copy link
Contributor

Choose a reason for hiding this comment

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

@ye-luo didn't write this.
Put my name, yours and we have been writing
// Refactored from MCCoords.hpp
instead of File created by.

I think that is more meaningful when you're tearing up or porting a well known file.
The name is better.

Copy link
Contributor

@ye-luo ye-luo Feb 16, 2022

Choose a reason for hiding this comment

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

I did the rewriting. So I will take care of this.

move switch from TWFdispatcher into TrialWaveFunction
elec_.mw_makeMove(p_list, iat, displs);
elec_.mw_makeSpinMove(p_list, iat, sdispls);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could update this test to call the new APIs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea, I was just working on this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@camelto2
Copy link
Contributor Author

ok, added a unit test for the TWFGrads class I added. With the current changes, there are only a few spots left in VMCBatched and DMCBatched that need to be abstracted, but those will be handled by a subsequent PR. This one is large enough as it is

@ye-luo
Copy link
Contributor

ye-luo commented Feb 16, 2022

Test this please

ye-luo
ye-luo previously approved these changes Feb 16, 2022
@ye-luo ye-luo enabled auto-merge February 16, 2022 23:14
@ye-luo
Copy link
Contributor

ye-luo commented Feb 16, 2022

Test this please

@ye-luo ye-luo merged commit 3f5955e into QMCPACK:develop Feb 17, 2022
@camelto2 camelto2 deleted the batched_driver_move_abstraction branch February 17, 2022 16:24
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