Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions cxx/include/scf/property_types/convergence_uncertainty.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2026 NWChemEx-Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once
#include <pluginplay/pluginplay.hpp>
#include <simde/types.hpp>

namespace scf::property_types {

/** @brief Attaches the uncertainty from incomplete convergence to an energy.
*
* Called by an iterative method once it has converged. The result is the
* energy with uncertainty attached, *e.g.*, from the change in the energy
* in the final iteration.
*/
DECLARE_PROPERTY_TYPE(ConvergenceUncertainty);

PROPERTY_TYPE_INPUTS(ConvergenceUncertainty) {
using tensor_type = const simde::type::tensor&;
auto rv = pluginplay::declare_input()
.add_field<tensor_type>("Energy")
.template add_field<tensor_type>("Energy change");
rv["Energy"].set_description("The converged energy");
rv["Energy change"].set_description(
"The change in the energy in the final iteration");
return rv;
}

PROPERTY_TYPE_RESULTS(ConvergenceUncertainty) {
auto rv =
pluginplay::declare_result().add_field<simde::type::tensor>("Energy");
rv["Energy"].set_description("The energy with uncertainty attached");
return rv;
}

} // namespace scf::property_types
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,10 @@
* limitations under the License.
*/

/** @file property_types.hpp
*
* The property types defined by SCF. They are candidates for SimDE once
* their APIs have settled.
*/
#pragma once
#include <pluginplay/pluginplay.hpp>
#include <simde/types.hpp>

/** @namespace scf::property_types
*
* @brief The namespace for property types defined by SCF
*/
namespace scf::property_types {

/** @brief Attaches uncertainty to converged molecular orbitals.
Expand Down Expand Up @@ -66,30 +57,4 @@ PROPERTY_TYPE_RESULTS(MOUncertainty) {
return rv;
}

/** @brief Attaches the uncertainty from incomplete convergence to an energy.
*
* Called by an iterative method once it has converged. The result is the
* energy with uncertainty attached, *e.g.*, from the change in the energy
* in the final iteration.
*/
DECLARE_PROPERTY_TYPE(ConvergenceUncertainty);

PROPERTY_TYPE_INPUTS(ConvergenceUncertainty) {
using tensor_type = const simde::type::tensor&;
auto rv = pluginplay::declare_input()
.add_field<tensor_type>("Energy")
.template add_field<tensor_type>("Energy change");
rv["Energy"].set_description("The converged energy");
rv["Energy change"].set_description(
"The change in the energy in the final iteration");
return rv;
}

PROPERTY_TYPE_RESULTS(ConvergenceUncertainty) {
auto rv =
pluginplay::declare_result().add_field<simde::type::tensor>("Energy");
rv["Energy"].set_description("The energy with uncertainty attached");
return rv;
}

} // namespace scf::property_types
31 changes: 31 additions & 0 deletions cxx/include/scf/property_types/property_types.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2026 NWChemEx-Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/** @file property_types.hpp
*
* Convenience header that includes all of the property types defined by SCF.
* They are candidates for SimDE once their APIs have settled.
*/
#pragma once
#include <scf/property_types/convergence_uncertainty.hpp>
#include <scf/property_types/mo_uncertainty.hpp>
#include <scf/property_types/quadrature.hpp>
#include <scf/property_types/xc_uncertain.hpp>

/** @namespace scf::property_types
*
* @brief The namespace for property types defined by SCF
*/
63 changes: 63 additions & 0 deletions cxx/include/scf/property_types/quadrature.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 2026 NWChemEx-Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once
#include <chemist/grid/grid_class.hpp>
#include <pluginplay/pluginplay.hpp>
#include <simde/evaluate_braket/evaluate_braket.hpp>
#include <simde/types.hpp>

namespace scf::property_types {

/** @brief Evaluates the quantity of another property type by quadrature.
*
* Modules satisfying this property type evaluate the quantity computed by
* @p BasePT by quadrature on a grid they are given, rather than on a grid
* they build themselves. This lets the caller choose the grid, *e.g.*, to
* evaluate the same quadrature on a finer grid to estimate the error of the
* grid. The inputs are those of @p BasePT plus the grid, and the results are
* those of @p BasePT.
*
* @tparam BasePT The property type whose quantity is evaluated by
* quadrature, *e.g.*, simde::aos_xc_e_aos for the XC
* potential.
*/
template<typename BasePT>
DECLARE_TEMPLATED_PROPERTY_TYPE(Quadrature, BasePT);

template<typename BasePT>
TEMPLATED_PROPERTY_TYPE_INPUTS(Quadrature, BasePT) {
using grid_type = const chemist::Grid&;
auto rv = BasePT::inputs();
auto rv0 = rv.template add_field<grid_type>("Grid");
rv0["Grid"].set_description("The grid the quadrature is evaluated on");
return rv0;
}

template<typename BasePT>
TEMPLATED_PROPERTY_TYPE_RESULTS(Quadrature, BasePT) {
return BasePT::results();
}

/// Property type for evaluating the XC energy by quadrature
using xc_energy_quadrature =
Quadrature<simde::eval_braket<simde::type::rscf_wf, simde::type::XC_e_type,
simde::type::rscf_wf>>;

/// Property type for evaluating the AO matrix of the XC potential by quadrature
using xc_potential_quadrature = Quadrature<simde::aos_xc_e_aos>;

} // namespace scf::property_types
63 changes: 63 additions & 0 deletions cxx/include/scf/property_types/xc_uncertain.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 2026 NWChemEx-Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once
#include <pluginplay/pluginplay.hpp>
#include <scf/property_types/quadrature.hpp>

namespace scf::property_types {

/** @brief Attaches uncertainty to the result of another property type.
*
* Modules satisfying this property type are error models for the XC energy
* and potential, *e.g.*, for the error from the incompleteness of the grid.
* They are given the inputs of @p BasePT and the results of calling a module
* satisfying @p BasePT with those inputs. The results are those of
* @p BasePT, but with uncertainty attached: each value is a UQ type whose
* nominal value is the corresponding value of the given results. The module
* satisfying this property type gets the UQ type from its own
* ``UQ Initializer`` submodule.
*
* This property type is a stop gap. It should eventually replace
* SimDE's ``Uncertainty`` property type.
*
* @tparam BasePT The property type of the module whose result is having
* uncertainty attached, *e.g.*, xc_potential_quadrature.
*/
template<typename BasePT>
DECLARE_TEMPLATED_PROPERTY_TYPE(XCUncertain, BasePT);

template<typename BasePT>
TEMPLATED_PROPERTY_TYPE_INPUTS(XCUncertain, BasePT) {
// Appends each result of BasePT, with the same key and type, as an input
auto rv = BasePT::inputs() + BasePT::results();
for(const auto& [key, value] : BasePT::results())
rv[key].set_description("The value to attach uncertainty to");
return rv;
}

template<typename BasePT>
TEMPLATED_PROPERTY_TYPE_RESULTS(XCUncertain, BasePT) {
return BasePT::results();
}

/// Property type for attaching uncertainty to the XC energy from quadrature
using xc_energy_uncertainty = XCUncertain<xc_energy_quadrature>;

/// Property type for attaching uncertainty to the XC potential from quadrature
using xc_potential_uncertainty = XCUncertain<xc_potential_quadrature>;

} // namespace scf::property_types
2 changes: 1 addition & 1 deletion cxx/include/scf/scf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#pragma once
#include <scf/driver/commutator.hpp>
#include <scf/property_types.hpp>
#include <scf/property_types/property_types.hpp>
#include <scf/scf_mm.hpp>
#include <simde/simde.hpp>
#ifdef BUILD_TAMM_SCF
Expand Down
2 changes: 1 addition & 1 deletion cxx/src/scf/driver/driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

#pragma once
#include <scf/property_types.hpp>
#include <scf/property_types/property_types.hpp>
#include <simde/simde.hpp>

namespace scf::driver {
Expand Down
4 changes: 4 additions & 0 deletions cxx/src/scf/export_scf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ EXPORT_PLUGIN(scf, SCF, m) {
using namespace scf::property_types;
EXPORT_PROPERTY_TYPE(MOUncertainty, m);
EXPORT_PROPERTY_TYPE(ConvergenceUncertainty, m);
EXPORT_PROPERTY_TYPE(xc_energy_quadrature, m);
EXPORT_PROPERTY_TYPE(xc_potential_quadrature, m);
EXPORT_PROPERTY_TYPE(xc_energy_uncertainty, m);
EXPORT_PROPERTY_TYPE(xc_potential_uncertainty, m);
}

} // namespace scf
5 changes: 5 additions & 0 deletions cxx/src/scf/scf_mm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ PLUGIN_CTOR(SCF) {
"Analytic Error");
default_submod_from("integrals", "QCUP SCF", "Benchmark ERIs",
"Analytic Benchmark ERI4");

default_submod_from("integrals", "Reference Grid XC Energy Error",
"UQ Initializer", "UQ Initializer");
default_submod_from("integrals", "Reference Grid XC Potential Error",
"UQ Initializer", "UQ Initializer");
}

} // namespace scf
2 changes: 1 addition & 1 deletion cxx/src/scf/uncertainty/uncertainty.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

#pragma once
#include <scf/property_types.hpp>
#include <scf/property_types/property_types.hpp>
#include <simde/simde.hpp>

namespace scf::uncertainty {
Expand Down
27 changes: 17 additions & 10 deletions cxx/src/scf/xc/libxc/libxc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

#include "../xc.hpp"
#include "libxc.hpp"
#ifdef BUILD_LIBXC
#include "xc.h"
Expand Down Expand Up @@ -41,19 +42,25 @@ const auto* get_const_pointer(const tensorwrapper::buffer::BufferBase& buffer) {
} // namespace

void load_modules(pluginplay::ModuleMap& modules) {
modules.add_module<LibXCEnergy>("LibXC Energy");
modules.add_module<LibXCPotential>("LibXC Potential");
modules.add_module<XCEnergyViaQuadrature>("LibXC Energy");
modules.add_module<XCPotentialViaQuadrature>("LibXC Potential");
modules.add_module<LibXCEnergyQuadrature>("LibXC Energy Quadrature");
modules.add_module<LibXCPotentialQuadrature>("LibXC Potential Quadrature");
}

void set_defaults(pluginplay::ModuleMap& modules) {
modules.change_submod("LibXC Energy", "Integration grid",
"Grid From IntegratorXX");
modules.change_submod("LibXC Potential", "Integration grid",
"Grid From IntegratorXX");
modules.change_submod("LibXC Energy", "Density on a grid", "Density2Grid");
modules.change_submod("LibXC Potential", "Density on a grid",
"Density2Grid");
modules.change_submod("LibXC Potential", "AOs on a grid", "AOs on a Grid");
const auto e_key = "LibXC Energy";
const auto v_key = "LibXC Potential";
const auto e_q_key = "LibXC Energy Quadrature";
const auto v_q_key = "LibXC Potential Quadrature";
const auto grid_key = "Grid From IntegratorXX";
modules.change_submod(e_key, "Integration grid", grid_key);
modules.change_submod(v_key, "Integration grid", grid_key);
modules.change_submod(e_key, "Quadrature", e_q_key);
modules.change_submod(v_key, "Quadrature", v_q_key);
modules.change_submod(e_q_key, "Density on a grid", "Density2Grid");
modules.change_submod(v_q_key, "Density on a grid", "Density2Grid");
modules.change_submod(v_q_key, "AOs on a grid", "AOs on a grid");
}

std::pair<int, int> to_libxc_codes(chemist::qm_operator::xc_functional func) {
Expand Down
4 changes: 2 additions & 2 deletions cxx/src/scf/xc/libxc/libxc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

namespace scf::xc::libxc {

DECLARE_MODULE(LibXCEnergy);
DECLARE_MODULE(LibXCPotential);
DECLARE_MODULE(LibXCEnergyQuadrature);
DECLARE_MODULE(LibXCPotentialQuadrature);

void set_defaults(pluginplay::ModuleMap& modules);
void load_modules(pluginplay::ModuleMap& modules);
Expand Down
Loading
Loading