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

Implement SPOSetT<T> template class hierarchy #4684

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

williamfgc
Copy link
Contributor

@williamfgc williamfgc commented Jul 24, 2023

Proposed changes

Introduce a shim template class to asses the effort to change SPOSet to SPOSet<T>.
SPOSetT<T> currently does not have consumers nor tests.
Testing compilation in CI and define concrete types for the template classes.
The challenge is to adapt SPOSetT<T> to SPOSet current consumers.
Related to #4099

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

Delete the items that do not apply

  • Refactoring (no functional changes, no api changes)

Does this introduce a breaking change?

  • No

What systems has this change been tested on?

sulfur

Checklist

  • 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
  • No. Documentation has been added (if appropriate)

@williamfgc
Copy link
Contributor Author

Changed to the option suggested by @ye-luo to only concretize class type.

@ye-luo
Copy link
Contributor

ye-luo commented Aug 24, 2023

Thinking of how to avoid adding new files. Can we make SPOSetT<T> as an actual shim layer derived from SPOSet. Once a derived class is ported. It changes base from SPOSet to SPOSetT<T>. In this way, we don't add new files except SPOSetT<T>.

@williamfgc
Copy link
Contributor Author

@ye-luo thanks for chiming in. We just thought having a separate SPOSetT hierarchy would help us with CI (at least build errors we introduce are caught) and for us to work in parallel. Once we have that we can start integrating with current SPOSet consumers without rewriting those and once done remove SPOSet and rename SPOSetT->SPOSet. Thoughts?

@ye-luo
Copy link
Contributor

ye-luo commented Aug 24, 2023

@ye-luo thanks for chiming in. We just thought having a separate SPOSetT hierarchy would help us with CI (at least build errors we introduce are caught) and for us to work in parallel. Once we have that we can start integrating with current SPOSet consumers without rewriting those and once done remove SPOSet and rename SPOSetT->SPOSet. Thoughts?

probably I didn't fully understand the current status of this PR. I saw multiple files (SPOSetT and derived classes) got added and was thinking of how to make the change mergeable without the need of porting every SPOSet derived classes before merging. By making SPOSet a base of SPOSetT probably allows us to keep ported and not yet ported classes to co-exist without any duplication. All the high level classes still just see SPOSet.

@@ -178,6 +177,7 @@ class RealSpacePositionsTOMPTarget : public DynamicCoordinatesT<T>
const size_t mw_pos_stride = mw_new_pos.capacity();

PRAGMA_OFFLOAD("omp target teams distribute parallel for \
is_device_ptr(mw_pos_ptr, mw_rosa_ptr) \
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ye-luo @correaa FYI this passes the right values

//
// Copyright (c) 2022 QMCPACK developers.
//
// File developed by: Joshua Townsend, [email protected], Sandia National
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like someone is running clang-format with a column limit of 80 (vs the qmcpack default of 120). (Or is using an editor that does auto-wrapping). While technically within the guidelines (line length is < 120), it is creating extra differences between files.

@markdewing
Copy link
Contributor

It looks like the "new" files have been run through clang-format that is more restrictive than the default one, or been modified in an editor that does some formatting.
What I've noticed so far:

  • Copyright header gets wrapped to 80 columns
  • Comments in general get wrapped to 80 columns
  • Space gets added between comment and text

I think it would be better if the copyright headers had a consistent format in every file.

Unfortunately, these aren't new files - they're renamed and changed versions of existing files.
The other changes wouldn't be a problem in a small PR, but for one this large, every change is making it harder for git to detect moved files (It uses some threshold for the number of pairs of changes to check, or a percentage of file similarity).

@quantumsteve
Copy link
Contributor

cmake -G Ninja -DQMC_MPI=OFF ../

develop

$ time ninja
[646/646] Linking CXX executable bin/ppconvert

real	1m55.924s
user	64m36.053s
sys	5m4.636s

ref-add-SPOSetT

$ time ninja
[652/652] Linking CXX executable bin/ppconvert

real	2m5.956s
user	70m52.674s
sys	5m15.397s

Comment on lines +37 to +47
template<typename T>
struct ValueApproxHelper
{
using Type = Catch::Detail::Approx;
};
template<typename T>
struct ValueApproxHelper<std::complex<T>>
{
using Type = Catch::Detail::ComplexApprox;
};

template<typename T>
using ValueApprox = typename ValueApproxHelper<T>::Type;
Copy link
Contributor

Choose a reason for hiding this comment

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

This code might be useful elsewhere, and could get moved to src/external_codes/complex_approx.hpp or src/Configuration.h
(Not necessary for this PR, though)

@williamfgc williamfgc force-pushed the ref-add-SPOSetT branch 3 times, most recently from f147c17 to 4712b2f Compare October 26, 2023 23:26
@williamfgc
Copy link
Contributor Author

williamfgc commented Oct 26, 2023

@markdewing thanks for the catch. The latest commit should have addressed clang-format related issues. I will double-check. I used clang-format-16. Thanks!

@williamfgc
Copy link
Contributor Author

Test this please

@williamfgc
Copy link
Contributor Author

The changes in the Numerics and Particle directories clearly can't depend on SPOSet. And a lot of the changes in QMCDrivers are just minor changes like include files.

A lot of these changes are at the SPOSet<T> consumer level (e.g. builders) and likely 'cause GitHub Actions CI was breaking as at some point we ran it in every commit the current branch has. It's probably the smallest PR we can get with such refactoring.

@williamfgc
Copy link
Contributor Author

Test this please

@PDoakORNL
Copy link
Contributor

What's going on with the MCWalkerConfiguration further bleeding into the batched drivers and mw is undesirable. I've gone out of my way to keep this from happening. We want to drop that class when the legacy drivers and estimators go away. It should never be a source for type information for non legacy code.

The explicit definition of MCPWalker from Walker instead of pulling in Walker_t from elsewhere was intended to decouple classes that were tightly bound via Walker type aliases. Then they can be built and tested without creating cascading rebuilds. There seems to be a clash now between QMCTraits and ParticleTraits which is making a bit of a mess that is just getting fixed by adding includes that shouldn't really be included.

Similar issues seem behind the many forward declarations that were successfully decoupling headers that have been reverted by this PR.

I'm not sure if we should put this in and then work to refactor away the new includes and MCPWalker type aliases or just stage this in such a way we don't add all these design regressions.

Copy link
Contributor

@prckent prckent left a comment

Choose a reason for hiding this comment

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

I assent to merge this subject to the conflicts being fixed and there not being any new issues there.

If we are concerned about possible offload errors, we could check this code is OK on Frontier and Aurora, so that we don't risk breaking develop for FOM runs. Our CI coverage of offload is not great (only NV, limited coverage).

Our earlier decision was that this would be a large PR instead of a lot of small ones since the large PR route was much more practical. As Peter said, we can work to refactor away some of the new design dependencies. Breaking this PR up would not be consistent with what we agreed on, and from a project perspective there simply is not time to rework this PR. There are very few weeks remaining in the year to get unified complex-real builds completed.

Next step: William & co to fix the conflicts.

.github/workflows/ci-github-actions.yaml Outdated Show resolved Hide resolved
.github/workflows/ci-github-actions.yaml Outdated Show resolved Hide resolved
@williamfgc williamfgc force-pushed the ref-add-SPOSetT branch 3 times, most recently from dae4c3f to cc14aae Compare November 8, 2023 01:05
@williamfgc
Copy link
Contributor Author

Test this please

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.

First, I appreciated the effort. It is a very heavy workload.
After looking through the change. I feel two aspects are mixed when rushing to make the code compile and run.

  1. real/complex. This is what we would like to explore.
  2. full/mixed precision. This is what I would like to leave aside.
    by looking at all the changes. I'm surprised to see ParticleSet being template as ValueType. When making such massive changes. Certain choices may not be made optimal. Merging this PR as it is will be a challenge for post-ECP develops as there is very limited understanding of this PR and some modifications are not necessary and needs undo. So I still would like to explore a way to make piece wise changing possible.

I have additional thoughts about how to handle mixed precision and also simplify the code. It will be a separate discussion.

};
using DistanceTable = DistanceTableT<QMCTraits::ValueType>;
using DistanceTableAA = DistanceTableAAT<QMCTraits::ValueType>;
using DistanceTableAB = DistanceTableABT<QMCTraits::ValueType>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Distance tables are real only. Should not be in ValueType.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. This needs to be fixed.

Copy link
Contributor

@quantumsteve quantumsteve Nov 8, 2023

Choose a reason for hiding this comment

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

That can't be fixed without removing the member variable const ParticleSetT<T>& origin_; or making ParticleSetT<T> real-only.

const ParticleSet& origin_;

Copy link
Contributor Author

@williamfgc williamfgc Nov 10, 2023

Choose a reason for hiding this comment

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

Given that in the current state of develop DistanceTable depends tightly on ParticleSet and ValueType, I think it falls outside the scope of this PR.

coordinates_->resize(numPtcl);
}
};
using ParticleSet = ParticleSetT<QMCTraits::ValueType>;
Copy link
Contributor

Choose a reason for hiding this comment

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

ParticleSet should be real-only.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is MCWalkerConfiguration, which inherits from ParticleSet, real-only?

Copy link
Contributor

Choose a reason for hiding this comment

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

it should.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since ParticleSet contains GradType and QMCTraits::GradType depends on ValueType. I don't see a straightforward way to make ParticleSet real-only.

using GradType = TinyVector<ValueType, DIM>;

Copy link
Contributor Author

@williamfgc williamfgc Nov 10, 2023

Choose a reason for hiding this comment

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

Given that in the current state of develop ParticleSet depends on ValueType, I think it falls outside the scope of this PR.

@williamfgc
Copy link
Contributor Author

williamfgc commented Nov 8, 2023

full/mixed precision. This is what I would like to leave aside. by looking at all the changes. I'm surprised to see ParticleSet being template as ValueType.

This was done to satisfy the requirement to not specialize on a single function basis, but rather class level since ParticleSet is directly consumed by SPOSet and derived classes. If we start specializing it will look like lots of trailing #ifdef for handling mixed precision, and templates for real/complex. We think this is a good-enough compromise to move forward and not complicate current tasks given timelines. We didn't want to make complicated design changes (other than what we were asked) as we are relying on the current CI and many parts are not necessarily tested.

Merging this PR as it is will be a challenge for post-ECP develops as there is very limited understanding of this PR and some modifications are not necessary and needs undo. So I still would like to explore a way to make piece wise changing possible.

The PR itself is about undoing things, and there is plenty of pending things (e.g. we are still depending of #ifdef for template class definitions). I'm afraid any other attempt to make this piece wise won't add value and we we will end up with something very similar to what we have (or worse, combining current non-generic #ifdef patterns with template generic patterns). This is a good opportunity to identify pieces towards major re-architecture redesign, refactoring and add more testing. This PR can be summarized as SPOSet -> SPOSet <T> + the most straight-forward/shortest-path way to satisfy CI requirements. My concern is on trying to spend time to maximize impact given that resources are limited.

@williamfgc
Copy link
Contributor Author

Test this please

williamfgc and others added 4 commits November 8, 2023 20:49
Asses the effort to change this.
Currently without consumers or tests.

Concretize friend class declaration

Define testing::getMyVars for SPOSetT

Add FakeSPOT class

Move SpinorSet to a templated class

Refactor FreeOrbital class

Base typed aliases on SPOSet<T> on OrbitalSetTraits<T>

Add FullRealType in SPOSet and RotatedSPOs

Add this in templated meta class

Add explicit function instantions for FreeOrbital

Add templated class SHOSetT

Signed-off-by: Steven Hahn <[email protected]>

Add PWRealOrbitalSetT template class

Revert test_RotatedSPOs.cpp

Revert test_RotatedSPOs.cpp

Reorder specialized function definitions to appease OMP target compilation

Add ConstantSPOSetT

Refactor BsplineSet and SplineC2C

Follow existing pattern for SplineC2C allowing for std::complex<T>

PWOribitalSetT and PWBasisT

Add FullRealType in SPOSet and RotatedSPOs

Move generic definition after specialization

add implicit implementations

Fix some errors

initial commit of templated PWOribitSetT that compiles

cleanup

templateitze PWBasis as well, as is dependancy

remove inaccurate comment

remove polluted commit

Add LCAOrbitalSetT

Add templated class LCAOrbitalSetWithCorrectionT

Signed-off-by: Steven Hahn <[email protected]>

Add SPOSetBuilderT, SHOSetBuilderT and SoaCuspCorrectionT

Fix PWOrbitalSet alias types
Fix LCAOrbitalSetWithCorrectionT
Reuse SPOSet types

Signed-off-by: Steven Hahn <[email protected]>

Implement CompositeSPOSetT class

Specialize functions in RotatedSPOsT

Fix function signature
Change order of definition

Implement SPOSetBuilderFactoryT and most required builders

Add missing implementation to SPOSetBuilderT

Signed-off-by: Steven Hahn <[email protected]>

Add CI to WIP refactoring branch

add SplineR2RT

Empty-Commit

Further template propagation to fix offload build

Implement SplineC2RTOMPTarget template class

add missing particlesetT

Refactored everything needed for test_RotatedSPOsT

Add new bits to RotatedSPOsT

Bugfix: removed QMC_COMPLEX conditions where no longer needed

Accomodate new refactored headers

simd::dot and Spline classes

Move memory reference inside PRAGMA

Causes a memory corruption when defining internal pos

Fix pragma typo with is_device_ptr

Implement SPOSetT template class

Asses the initial effort to refactor SPOSet into templates
without consumers or tests.
Concretize friend class declaration
Define testing::getMyVars for SPOSetT
Add FakeSPOT class
Move SpinorSet to a templated class
Refactor FreeOrbital class
Base typed aliases on SPOSet<T> on OrbitalSetTraits<T>
Add FullRealType in SPOSet and RotatedSPOs
Add this in templated meta class
Add explicit function instantions for FreeOrbital
Add templated class SHOSetT
Add PWRealOrbitalSetT template class
Revert test_RotatedSPOs.cpp

Signed-off-by: Steven Hahn <[email protected]>

Revert test_RotatedSPOs.cpp

PWOribitalSetT and PWBasisT

Add FullRealType in SPOSet and RotatedSPOs

Move generic definition after specialization

add implicit implementations

Fix some errors

initial commit of templated PWOribitSetT that compiles

cleanup

templateitze PWBasis as well, as is dependancy

remove inaccurate comment

remove polluted commit

Start replacing legacy code with templated classes

Fix ornl CI tests

sulfur: Add missing SPOSet header in NiO tests
nitrogen: Add missing memory header for std::unique_ptr

clang-format-16 on new files

Fix license file headers

Fix typo with T1->T
@williamfgc
Copy link
Contributor Author

Test this please

@williamfgc
Copy link
Contributor Author

@prckent @ye-luo @quantumsteve this is a new checkpoint that CI tests are passing and conflicts are resolved.

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.

6 participants