Skip to content

Commit

Permalink
Add missing implementation to SPOSetBuilderT
Browse files Browse the repository at this point in the history
Signed-off-by: Steven Hahn <[email protected]>
  • Loading branch information
quantumsteve authored and williamfgc committed Sep 6, 2023
1 parent 47bc03b commit f78c3b0
Showing 1 changed file with 288 additions and 0 deletions.
288 changes: 288 additions & 0 deletions src/QMCWaveFunctions/SPOSetBuilderT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,294 @@ void SPOSetBuilderT<T>::reserve_states(int nsets)
states.push_back(std::make_unique<SPOSetInfo>());
}

template<>
std::unique_ptr<SPOSetT<float>> SPOSetBuilderT<float>::createSPOSet(xmlNodePtr cur)
{
std::string spo_object_name;
std::string optimize("no");

OhmmsAttributeSet attrib;
attrib.add(spo_object_name, "id");
attrib.add(spo_object_name, "name");
attrib.add(optimize, "optimize");
attrib.put(cur);

app_summary() << std::endl;
app_summary() << " Single particle orbitals (SPO)" << std::endl;
app_summary() << " ------------------------------" << std::endl;
app_summary() << " Name: " << spo_object_name << " Type: " << type_name_
<< " Builder class name: " << ClassName << std::endl;
app_summary() << std::endl;

if (spo_object_name.empty())
myComm->barrier_and_abort("SPOSet object \"name\" attribute not given in the input!");

// read specialized sposet construction requests
// and translate them into a set of orbital indices
SPOSetInputInfo input_info(cur);

// process general sposet construction requests
// and preserve legacy interface
std::unique_ptr<SPOSetT<float>> sposet;

try
{
if (legacy && input_info.legacy_request)
sposet = createSPOSetFromXML(cur);
else
sposet = createSPOSet(cur, input_info);
}
catch (const UniformCommunicateError& ue)
{
myComm->barrier_and_abort(ue.what());
}

if (!sposet)
myComm->barrier_and_abort("SPOSetBuilder::createSPOSet sposet creation failed");

if (optimize == "rotation" || optimize == "yes")
{
app_warning() << "Specifying orbital rotation via optimize tag is deprecated. Use the rotated_spo element instead"
<< std::endl;

sposet->storeParamsBeforeRotation();
// create sposet with rotation
auto& sposet_ref = *sposet;
app_log() << " SPOSet " << sposet_ref.getName() << " is optimizable\n";
if (!sposet_ref.isRotationSupported())
myComm->barrier_and_abort("Orbital rotation not supported with '" + sposet_ref.getName() + "' of type '" +
sposet_ref.getClassName() + "'.");
auto rot_spo = std::make_unique<RotatedSPOsT<float>>(sposet_ref.getName(), std::move(sposet));
xmlNodePtr tcur = cur->xmlChildrenNode;
while (tcur != NULL)
{
std::string cname((const char*)(tcur->name));
if (cname == "opt_vars")
{
std::vector<RealType> params;
putContent(params, tcur);
rot_spo->setRotationParameters(params);
}
tcur = tcur->next;
}
sposet = std::move(rot_spo);
}

if (sposet->getName().empty())
app_warning() << "SPOSet object doesn't have a name." << std::endl;
if (!spo_object_name.empty() && sposet->getName() != spo_object_name)
app_warning() << "SPOSet object name mismatched! input name: " << spo_object_name
<< " object name: " << sposet->getName() << std::endl;

sposet->checkObject();
return sposet;
}

template<>
std::unique_ptr<SPOSetT<double>> SPOSetBuilderT<double>::createSPOSet(xmlNodePtr cur)
{
std::string spo_object_name;
std::string optimize("no");

OhmmsAttributeSet attrib;
attrib.add(spo_object_name, "id");
attrib.add(spo_object_name, "name");
attrib.add(optimize, "optimize");
attrib.put(cur);

app_summary() << std::endl;
app_summary() << " Single particle orbitals (SPO)" << std::endl;
app_summary() << " ------------------------------" << std::endl;
app_summary() << " Name: " << spo_object_name << " Type: " << type_name_
<< " Builder class name: " << ClassName << std::endl;
app_summary() << std::endl;

if (spo_object_name.empty())
myComm->barrier_and_abort("SPOSet object \"name\" attribute not given in the input!");

// read specialized sposet construction requests
// and translate them into a set of orbital indices
SPOSetInputInfo input_info(cur);

// process general sposet construction requests
// and preserve legacy interface
std::unique_ptr<SPOSetT<double>> sposet;

try
{
if (legacy && input_info.legacy_request)
sposet = createSPOSetFromXML(cur);
else
sposet = createSPOSet(cur, input_info);
}
catch (const UniformCommunicateError& ue)
{
myComm->barrier_and_abort(ue.what());
}

if (!sposet)
myComm->barrier_and_abort("SPOSetBuilder::createSPOSet sposet creation failed");

if (optimize == "rotation" || optimize == "yes")
{
app_warning() << "Specifying orbital rotation via optimize tag is deprecated. Use the rotated_spo element instead"
<< std::endl;

sposet->storeParamsBeforeRotation();
// create sposet with rotation
auto& sposet_ref = *sposet;
app_log() << " SPOSet " << sposet_ref.getName() << " is optimizable\n";
if (!sposet_ref.isRotationSupported())
myComm->barrier_and_abort("Orbital rotation not supported with '" + sposet_ref.getName() + "' of type '" +
sposet_ref.getClassName() + "'.");
auto rot_spo = std::make_unique<RotatedSPOsT<double>>(sposet_ref.getName(), std::move(sposet));
xmlNodePtr tcur = cur->xmlChildrenNode;
while (tcur != NULL)
{
std::string cname((const char*)(tcur->name));
if (cname == "opt_vars")
{
std::vector<RealType> params;
putContent(params, tcur);
rot_spo->setRotationParameters(params);
}
tcur = tcur->next;
}
sposet = std::move(rot_spo);
}

if (sposet->getName().empty())
app_warning() << "SPOSet object doesn't have a name." << std::endl;
if (!spo_object_name.empty() && sposet->getName() != spo_object_name)
app_warning() << "SPOSet object name mismatched! input name: " << spo_object_name
<< " object name: " << sposet->getName() << std::endl;

sposet->checkObject();
return sposet;
}

template<>
std::unique_ptr<SPOSetT<std::complex<float>>> SPOSetBuilderT<std::complex<float>>::createSPOSet(xmlNodePtr cur)
{
std::string spo_object_name;
std::string optimize("no");

OhmmsAttributeSet attrib;
attrib.add(spo_object_name, "id");
attrib.add(spo_object_name, "name");
attrib.add(optimize, "optimize");
attrib.put(cur);

app_summary() << std::endl;
app_summary() << " Single particle orbitals (SPO)" << std::endl;
app_summary() << " ------------------------------" << std::endl;
app_summary() << " Name: " << spo_object_name << " Type: " << type_name_
<< " Builder class name: " << ClassName << std::endl;
app_summary() << std::endl;

if (spo_object_name.empty())
myComm->barrier_and_abort("SPOSet object \"name\" attribute not given in the input!");

// read specialized sposet construction requests
// and translate them into a set of orbital indices
SPOSetInputInfo input_info(cur);

// process general sposet construction requests
// and preserve legacy interface
std::unique_ptr<SPOSetT<std::complex<float>>> sposet;

try
{
if (legacy && input_info.legacy_request)
sposet = createSPOSetFromXML(cur);
else
sposet = createSPOSet(cur, input_info);
}
catch (const UniformCommunicateError& ue)
{
myComm->barrier_and_abort(ue.what());
}

if (!sposet)
myComm->barrier_and_abort("SPOSetBuilder::createSPOSet sposet creation failed");

if (optimize == "rotation" || optimize == "yes")
{
app_error() << "Orbital optimization via rotation doesn't support complex wavefunction yet.\n";
abort();
}

if (sposet->getName().empty())
app_warning() << "SPOSet object doesn't have a name." << std::endl;
if (!spo_object_name.empty() && sposet->getName() != spo_object_name)
app_warning() << "SPOSet object name mismatched! input name: " << spo_object_name
<< " object name: " << sposet->getName() << std::endl;

sposet->checkObject();
return sposet;
}

template<>
std::unique_ptr<SPOSetT<std::complex<double>>> SPOSetBuilderT<std::complex<double>>::createSPOSet(xmlNodePtr cur)
{
std::string spo_object_name;
std::string optimize("no");

OhmmsAttributeSet attrib;
attrib.add(spo_object_name, "id");
attrib.add(spo_object_name, "name");
attrib.add(optimize, "optimize");
attrib.put(cur);

app_summary() << std::endl;
app_summary() << " Single particle orbitals (SPO)" << std::endl;
app_summary() << " ------------------------------" << std::endl;
app_summary() << " Name: " << spo_object_name << " Type: " << type_name_
<< " Builder class name: " << ClassName << std::endl;
app_summary() << std::endl;

if (spo_object_name.empty())
myComm->barrier_and_abort("SPOSet object \"name\" attribute not given in the input!");

// read specialized sposet construction requests
// and translate them into a set of orbital indices
SPOSetInputInfo input_info(cur);

// process general sposet construction requests
// and preserve legacy interface
std::unique_ptr<SPOSetT<std::complex<double>>> sposet;

try
{
if (legacy && input_info.legacy_request)
sposet = createSPOSetFromXML(cur);
else
sposet = createSPOSet(cur, input_info);
}
catch (const UniformCommunicateError& ue)
{
myComm->barrier_and_abort(ue.what());
}

if (!sposet)
myComm->barrier_and_abort("SPOSetBuilder::createSPOSet sposet creation failed");

if (optimize == "rotation" || optimize == "yes")
{
app_error() << "Orbital optimization via rotation doesn't support complex wavefunction yet.\n";
abort();
}

if (sposet->getName().empty())
app_warning() << "SPOSet object doesn't have a name." << std::endl;
if (!spo_object_name.empty() && sposet->getName() != spo_object_name)
app_warning() << "SPOSet object name mismatched! input name: " << spo_object_name
<< " object name: " << sposet->getName() << std::endl;

sposet->checkObject();
return sposet;
}

template<typename T>
std::unique_ptr<SPOSetT<T>> SPOSetBuilderT<T>::createSPOSet(xmlNodePtr cur, SPOSetInputInfo& input_info)
{
Expand Down

0 comments on commit f78c3b0

Please sign in to comment.