35 using LogValue = std::complex<QMCTraits::QTFull::RealType>;
38 template<
typename T1,
typename T2>
42 for (
int i = 0; i < a.
rows(); i++)
44 for (
int j = 0; j < a.
cols(); j++)
46 CHECK(a(i, j) == ValueApprox(b(i, j)));
51 template<
typename DET>
54 auto spo_init = std::make_unique<FakeSPO>();
56 spo_init->setOrbitalSetSize(norb);
57 DET ddb(std::move(spo_init), 0, norb, 1, inverter_kind);
58 auto spo =
dynamic_cast<FakeSPO*
>(ddb.getPhi());
61 ddb.dpsiV.resize(norb);
62 ddb.d2psiV.resize(norb);
73 b(0, 0) = 0.6159749342;
74 b(0, 1) = -0.2408954682;
75 b(0, 2) = -0.1646081192;
76 b(1, 0) = 0.07923894288;
77 b(1, 1) = 0.1496231042;
78 b(1, 2) = -0.1428117337;
79 b(2, 0) = -0.2974298429;
80 b(2, 1) = -0.04586322768;
81 b(2, 2) = 0.3927890292;
86 PsiValue det_ratio = ddb.ratioGrad(elec, 0, grad);
87 PsiValue det_ratio1 = 0.178276269185;
88 CHECK(det_ratio1 == ValueApprox(det_ratio));
90 ddb.acceptMove(elec, 0);
92 b(0, 0) = 3.455170657;
93 b(0, 1) = -1.35124809;
94 b(0, 2) = -0.9233316353;
95 b(1, 0) = 0.05476311768;
96 b(1, 1) = 0.1591951095;
97 b(1, 2) = -0.1362710138;
98 b(2, 0) = -2.235099338;
99 b(2, 1) = 0.7119205298;
100 b(2, 2) = 0.9105960265;
109 ddb.evaluateRatiosAlltoOne(elec, ratios);
116 PsiValue ratio_0 = ddb.ratio(elec, 0);
122 std::vector<PosType> newpos2(2);
123 std::vector<ValueType> ratios2(2);
124 newpos2[0] = newpos - elec.
R[1];
125 newpos2[1] =
PosType(0.2, 0.5, 0.3) - elec.
R[1];
127 ddb.evaluateRatios(VP, ratios2);
134 PsiValue ratio_1 = ddb.ratio(elec, 1);
135 ddb.acceptMove(elec, 1);
142 TEST_CASE(
"DiracDeterminant_first",
"[wavefunction][fermion]")
146 #if defined(ENABLE_CUDA) 147 test_DiracDeterminant_first<DiracDeterminant<DelayedUpdateCUDA<ValueType, QMCTraits::QTFull::ValueType>>>(
149 test_DiracDeterminant_first<DiracDeterminant<DelayedUpdateCUDA<ValueType, QMCTraits::QTFull::ValueType>>>(
151 #elif defined(ENABLE_SYCL) 152 test_DiracDeterminant_first<DiracDeterminant<DelayedUpdateSYCL<ValueType, QMCTraits::QTFull::ValueType>>>(
159 template<
typename DET>
162 auto spo_init = std::make_unique<FakeSPO>();
164 spo_init->setOrbitalSetSize(norb);
165 DET ddb(std::move(spo_init), 0, norb, 1, inverter_kind);
166 auto spo =
dynamic_cast<FakeSPO*
>(ddb.getPhi());
169 ddb.dpsiV.resize(norb);
170 ddb.d2psiV.resize(norb);
182 for (
int i = 0; i < 3; i++)
184 for (
int j = 0; j < norb; j++)
186 orig_a(j, i) = spo->v2(i, j);
197 for (
int j = 0; j < norb; j++)
199 a_update1(j, 0) = spo->v2(0, j);
205 for (
int j = 0; j < norb; j++)
207 a_update2(j, 0) = spo->v2(0, j);
208 a_update2(j, 1) = spo->v2(1, j);
214 for (
int j = 0; j < norb; j++)
216 a_update3(j, 0) = spo->v2(0, j);
217 a_update3(j, 1) = spo->v2(1, j);
218 a_update3(j, 2) = spo->v2(2, j);
222 PsiValue det_ratio = ddb.ratioGrad(elec, 0, grad);
232 app_log() <<
"det ratio 1 = " << det_ratio1 << std::endl;
236 CHECK(det_ratio1 == ValueApprox(det_ratio));
238 ddb.acceptMove(elec, 0);
240 PsiValue det_ratio2 = ddb.ratioGrad(elec, 1, grad);
249 app_log() <<
"det ratio 2 = " << det_ratio2 << std::endl;
252 CHECK(det_ratio2 == ValueApprox(det_ratio2_val));
254 ddb.acceptMove(elec, 1);
256 PsiValue det_ratio3 = ddb.ratioGrad(elec, 2, grad);
265 app_log() <<
"det ratio 3 = " << det_ratio3 << std::endl;
267 CHECK(det_ratio3 == ValueApprox(det_ratio3_val));
270 ddb.acceptMove(elec, 2);
276 app_log() <<
"original " << std::endl;
277 app_log() << orig_a << std::endl;
278 app_log() <<
"block update " << std::endl;
279 app_log() << ddb.psiM << std::endl;
285 TEST_CASE(
"DiracDeterminant_second",
"[wavefunction][fermion]")
289 #if defined(ENABLE_CUDA) 290 test_DiracDeterminant_second<DiracDeterminant<DelayedUpdateCUDA<ValueType, QMCTraits::QTFull::ValueType>>>(
292 test_DiracDeterminant_second<DiracDeterminant<DelayedUpdateCUDA<ValueType, QMCTraits::QTFull::ValueType>>>(
294 #elif defined(ENABLE_SYCL) 295 test_DiracDeterminant_second<DiracDeterminant<DelayedUpdateSYCL<ValueType, QMCTraits::QTFull::ValueType>>>(
300 template<
typename DET>
303 auto spo_init = std::make_unique<FakeSPO>();
305 spo_init->setOrbitalSetSize(norb);
307 DET ddc(std::move(spo_init), 0, norb, 2, inverter_kind);
308 auto spo =
dynamic_cast<FakeSPO*
>(ddc.getPhi());
311 ddc.dpsiV.resize(norb);
312 ddc.d2psiV.resize(norb);
324 for (
int i = 0; i < 3; i++)
326 for (
int j = 0; j < norb; j++)
328 orig_a(j, i) = spo->v2(i, j);
339 for (
int j = 0; j < norb; j++)
341 a_update1(j, 0) = spo->v2(0, j);
347 for (
int j = 0; j < norb; j++)
349 a_update2(j, 0) = spo->v2(0, j);
350 a_update2(j, 1) = spo->v2(1, j);
356 for (
int j = 0; j < norb; j++)
358 a_update3(j, 0) = spo->v2(0, j);
359 a_update3(j, 1) = spo->v2(1, j);
360 a_update3(j, 2) = spo->v2(2, j);
365 PsiValue det_ratio = ddc.ratioGrad(elec, 0, grad);
375 app_log() <<
"det ratio 1 = " << det_ratio1 << std::endl;
379 CHECK(det_ratio1 == ValueApprox(det_ratio));
382 ddc.acceptMove(elec, 0,
true);
385 ddc.completeUpdates();
388 grad = ddc.evalGrad(elec, 1);
390 PsiValue det_ratio2 = ddc.ratioGrad(elec, 1, grad);
399 app_log() <<
"det ratio 2 = " << det_ratio2 << std::endl;
403 CHECK(det_ratio2 == ValueApprox(det_ratio2_val));
406 ddc.acceptMove(elec, 1,
true);
408 grad = ddc.evalGrad(elec, 2);
410 PsiValue det_ratio3 = ddc.ratioGrad(elec, 2, grad);
419 app_log() <<
"det ratio 3 = " << det_ratio3 << std::endl;
422 CHECK(det_ratio3 == ValueApprox(det_ratio3_val));
426 ddc.acceptMove(elec, 2,
true);
427 ddc.completeUpdates();
434 app_log() <<
"original " << std::endl;
435 app_log() << orig_a << std::endl;
436 app_log() <<
"delayed update " << std::endl;
437 app_log() << ddc.psiM << std::endl;
444 TEST_CASE(
"DiracDeterminant_delayed_update",
"[wavefunction][fermion]")
448 #if defined(ENABLE_CUDA) 449 test_DiracDeterminant_delayed_update<DiracDeterminant<DelayedUpdateCUDA<ValueType, QMCTraits::QTFull::ValueType>>>(
451 test_DiracDeterminant_delayed_update<DiracDeterminant<DelayedUpdateCUDA<ValueType, QMCTraits::QTFull::ValueType>>>(
453 #elif defined(ENABLE_SYCL) 454 test_DiracDeterminant_delayed_update<DiracDeterminant<DelayedUpdateSYCL<ValueType, QMCTraits::QTFull::ValueType>>>(
460 template<
typename DET>
461 void test_DiracDeterminant_spinor_update(
const DetMatInvertor inverter_kind)
473 lattice.R = {5.10509515, -3.23993545, 0.00000000, 5.10509515, 3.23993545,
474 0.00000000, -6.49690625, 0.00000000, 7.08268015};
477 const SimulationCell simulation_cell(
lattice);
478 ParticleSet ions_(simulation_cell);
479 ParticleSet elec_(simulation_cell);
480 ions_.setName(
"ion");
483 ions_.R[0] = {0.00000000, 0.00000000, 1.08659253};
484 ions_.R[1] = {0.00000000, 0.00000000, -1.08659253};
485 elec_.setName(
"elec");
487 elec_.R[0] = {0.1, -0.3, 1.0};
488 elec_.R[1] = {-0.1, 0.3, 1.0};
489 elec_.R[2] = {0.1, 0.2, 0.3};
490 elec_.spins[0] = 0.0;
491 elec_.spins[1] = 0.2;
492 elec_.spins[2] = 0.4;
493 elec_.setSpinor(
true);
495 SpeciesSet& tspecies = elec_.getSpeciesSet();
496 int upIdx = tspecies.addSpecies(
"u");
497 int chargeIdx = tspecies.addAttribute(
"charge");
498 tspecies(chargeIdx, upIdx) = -1;
500 elec_.addTable(ions_);
506 const auto nelec = elec_.R.size();
510 std::vector<PosType> kup, kdn;
511 std::vector<RealType> k2up, k2dn;
516 kup[1] =
PosType(0.1, 0.2, 0.3);
517 kup[2] =
PosType(0.4, 0.5, 0.6);
521 kdn[1] =
PosType(-0.1, 0.2, -0.3);
522 kdn[2] =
PosType(0.4, -0.5, 0.6);
524 auto spo_up = std::make_unique<FreeOrbital>(
"free_orb_up", kup);
525 auto spo_dn = std::make_unique<FreeOrbital>(
"free_orb_up", kdn);
527 auto spinor_set = std::make_unique<SpinorSet>(
"free_orb_spinor");
528 spinor_set->set_spos(std::move(spo_up), std::move(spo_dn));
530 DET dd(std::move(spinor_set), 0, nelec, 1, inverter_kind);
531 app_log() <<
" nelec=" << nelec << std::endl;
535 ParticleAttrib<ComplexType> SG;
549 app_log() <<
" R = " << elec_.R << std::endl;
550 app_log() <<
" s = " << elec_.spins << std::endl;
555 LogValue logref = dd.evaluateLog(elec_, G, L);
557 CHECK(logref == ComplexApprox(
ValueType(-1.1619939279564413, 0.8794794652468605)));
558 CHECK(G[0][0] == ComplexApprox(
ValueType(0.13416635, 0.2468612)));
559 CHECK(G[0][1] == ComplexApprox(
ValueType(-1.1165475, 0.71497753)));
560 CHECK(G[0][2] == ComplexApprox(
ValueType(0.0178403, 0.08212244)));
561 CHECK(G[1][0] == ComplexApprox(
ValueType(1.00240841, 0.12371593)));
562 CHECK(G[1][1] == ComplexApprox(
ValueType(1.62679698, -0.41080777)));
563 CHECK(G[1][2] == ComplexApprox(
ValueType(1.81324632, 0.78589013)));
564 CHECK(G[2][0] == ComplexApprox(
ValueType(-1.10994555, 0.15525902)));
565 CHECK(G[2][1] == ComplexApprox(
ValueType(-0.46335602, -0.50809713)));
566 CHECK(G[2][2] == ComplexApprox(
ValueType(-1.751199, 0.10949589)));
569 CHECK(L[2] == ComplexApprox(
ValueType(-4.82375261, -1.97943258)));
573 for (
int iat = 0; iat < nelec; iat++)
574 dd.evalGradWithSpin(elec_, iat, SG[iat]);
576 CHECK(SG[0] == ComplexApprox(
ValueType(-1.05686704, -2.01802154)));
578 CHECK(SG[2] == ComplexApprox(
ValueType(-0.62617675, -0.51093984)));
581 g_singleeval = dd.evalGrad(elec_, 1);
583 CHECK(g_singleeval[0] == ComplexApprox(G[1][0]));
584 CHECK(g_singleeval[1] == ComplexApprox(G[1][1]));
585 CHECK(g_singleeval[2] == ComplexApprox(G[1][2]));
591 elec_.makeMoveAndCheckWithSpin(1, dr, ds);
598 ratio_new = dd.ratio(elec_, 1);
599 CHECK(ratio_new == ComplexApprox(
ValueType(1.7472917722050971, 1.1900872950904169)));
601 ratio_new = dd.ratioGrad(elec_, 1, grad_new);
602 CHECK(ratio_new == ComplexApprox(
ValueType(1.7472917722050971, 1.1900872950904169)));
603 CHECK(grad_new[0] == ComplexApprox(
ValueType(0.5496675534224996, -0.07968022499097227)));
604 CHECK(grad_new[1] == ComplexApprox(
ValueType(0.4927399293808675, -0.29971549854643653)));
605 CHECK(grad_new[2] == ComplexApprox(
ValueType(1.2792642963632226, 0.12110307514989149)));
609 ratio_new = dd.ratioGradWithSpin(elec_, 1, grad_new, spingrad_new);
610 CHECK(ratio_new == ComplexApprox(
ValueType(1.7472917722050971, 1.1900872950904169)));
611 CHECK(grad_new[0] == ComplexApprox(
ValueType(0.5496675534224996, -0.07968022499097227)));
612 CHECK(grad_new[1] == ComplexApprox(
ValueType(0.4927399293808675, -0.29971549854643653)));
613 CHECK(grad_new[2] == ComplexApprox(
ValueType(1.2792642963632226, 0.12110307514989149)));
614 CHECK(spingrad_new == ComplexApprox(
ValueType(1.164708841479661, 0.9576425115390172)));
622 g_singleeval = dd.evalGrad(elec_, 1);
623 CHECK(g_singleeval[0] == ComplexApprox(G[1][0]));
624 CHECK(g_singleeval[1] == ComplexApprox(G[1][1]));
625 CHECK(g_singleeval[2] == ComplexApprox(G[1][2]));
628 g_singleeval = dd.evalGradWithSpin(elec_, 1, spingrad_old_test);
630 CHECK(spingrad_old_test == ComplexApprox(SG[1]));
631 CHECK(g_singleeval[0] == ComplexApprox(G[1][0]));
632 CHECK(g_singleeval[1] == ComplexApprox(G[1][1]));
633 CHECK(g_singleeval[2] == ComplexApprox(G[1][2]));
636 elec_.makeMoveAndCheckWithSpin(1, dr, ds);
643 lognew = dd.evaluateLog(elec_, G, L);
645 for (
int iat = 0; iat < nelec; iat++)
646 dd.evalGradWithSpin(elec_, iat, SG[iat]);
650 CHECK(lognew == ComplexApprox(
ValueType(-0.41337396772929913, 1.4774106123071726)));
651 CHECK(G[1][0] == ComplexApprox(grad_new[0]));
652 CHECK(G[1][1] == ComplexApprox(grad_new[1]));
653 CHECK(G[1][2] == ComplexApprox(grad_new[2]));
654 CHECK(SG[1] == ComplexApprox(spingrad_new));
657 TEST_CASE(
"DiracDeterminant_spinor_update",
"[wavefunction][fermion]")
662 test_DiracDeterminant_spinor_update<DiracDeterminant<DelayedUpdateCUDA<ValueType, QMCTraits::QTFull::ValueType>>>(
664 test_DiracDeterminant_spinor_update<DiracDeterminant<DelayedUpdateCUDA<ValueType, QMCTraits::QTFull::ValueType>>>(
WaveFunctionComponent::PsiValue PsiValue
static T convert(const std::complex< T1 > &logpsi)
helper functions for EinsplineSetBuilder
QTBase::GradType GradType
QTBase::RealType RealType
void test_DiracDeterminant_delayed_update(const DetMatInvertor inverter_kind)
size_t getTotalNum() const
CrystalLattice< OHMMS_PRECISION, OHMMS_DIM > ParticleLayout
TEST_CASE("complex_helper", "[type_traits]")
DetMatInvertor
determinant matrix inverter select
A ParticleSet that handles virtual moves of a selected particle of a given physical ParticleSet Virtu...
void makeMoves(const ParticleSet &refp, int jel, const std::vector< PosType > &deltaV, bool sphere=false, int iat=-1)
move virtual particles to new postions and update distance tables
ParticleAttrib< QTFull::ValueType > ParticleLaplacian
LatticeGaussianProduct::GradType GradType
void transpose(const T *restrict A, size_t m, size_t lda, TO *restrict B, size_t n, size_t ldb)
transpose of A(m,n) to B(n,m)
QTBase::ComplexType ComplexType
void resize(size_type n, size_type m)
Resize the container.
std::complex< QTFull::RealType > LogValue
QMCTraits::PosType PosType
void check_matrix(Matrix< T1 > &a, Matrix< T2 > &b)
CrystalLattice< OHMMS_PRECISION, OHMMS_DIM > lattice
void test_DiracDeterminant_first(const DetMatInvertor inverter_kind)
Specialized paritlce class for atomistic simulations.
QTBase::ValueType ValueType
REQUIRE(std::filesystem::exists(filename))
void rejectMove(Index_t iat)
reject a proposed move in regular mode
helper class to compute matrix inversion and the log value of determinant
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)
void create(const std::vector< int > &agroup)
create grouped particles
QMCTraits::RealType RealType
void makeMove(Index_t iat, const SingleParticlePos &displ, bool maybe_accept=true)
move the iat-th particle to active_pos_
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
ParticleAttrib< SingleParticlePos > ParticlePos
TinyVector< double, 3 > PosType
QMCTraits::ComplexType ComplexType
LatticeGaussianProduct::ValueType ValueType
ParticleAttrib< QTFull::GradType > ParticleGradient
Declaration of DiracDeterminant with a S(ingle)P(article)O(rbital)Set.
Declaration of WaveFunctionComponent.
std::complex< double > LogValue
void acceptMove(Index_t iat)
accept the move and update the particle attribute by the proposed move in regular mode ...
std::enable_if_t< std::is_same< T_FP, TMAT >::value > invert_transpose(const Matrix< TMAT, ALLOC1 > &amat, Matrix< TMAT, ALLOC2 > &invMat, std::complex< TREAL > &LogDet)
compute the inverse of the transpose of matrix A and its determinant value in log when T_FP and TMAT ...
void makeVirtualMoves(const SingleParticlePos &newpos)
Handles virtual moves for all the particles to a single newpos.
void test_DiracDeterminant_second(const DetMatInvertor inverter_kind)