-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_arbitrary_operator.cpp
More file actions
183 lines (154 loc) · 6.26 KB
/
test_arbitrary_operator.cpp
File metadata and controls
183 lines (154 loc) · 6.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
* Copyright 2022 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.
*/
#include "../testing.hpp"
#include "integrals/uncertain_types.hpp"
using udouble = integrals::type::uncertain_double;
constexpr bool has_sigma = integrals::type::has_sigma();
template<typename InputType>
auto unwrap_mean(InputType&& uq) {
if constexpr(has_sigma) {
return uq.mean();
} else {
return uq;
}
}
template<typename InputType>
auto unwrap_sd(InputType&& uq) {
if constexpr(has_sigma) {
return uq.sd();
} else {
return 0.0;
}
}
TEST_CASE("OperatorBase") {
using aos_t = simde::type::aos;
using aos_squared_t = simde::type::aos_squared;
using op_t = simde::type::v_ee_type;
using op_base_t = simde::type::op_base_type;
pluginplay::ModuleManager mm;
integrals::load_modules(mm);
REQUIRE(mm.count("Evaluate 2-Index BraKet"));
REQUIRE(mm.count("Evaluate 3-Index BraKet"));
REQUIRE(mm.count("Evaluate 4-Index BraKet"));
// Get basis set
auto mol = test::water_molecule();
auto aobs = test::water_sto3g_basis_set();
// Make AOS object
aos_t aos(aobs);
aos_squared_t aos_squared(aos, aos);
// Make Operator
op_t op{};
op_base_t& op_base = op;
SECTION("2-Index") {
using braket_t = simde::type::braket<aos_t, op_base_t, aos_t>;
using test_pt = simde::EvaluateBraKet<braket_t>;
// Make BraKet Input
braket_t braket(aos, op_base, aos);
// Call module
auto& mod = mm.at("Evaluate 2-Index BraKet");
SECTION("No UQ") {
auto T = mod.run_as<test_pt>(braket);
// Check output
REQUIRE(test::trace<2>(T.buffer()) ==
Catch::Approx(124.7011973877891364).margin(1.0e-16));
REQUIRE(test::norm<2>(T.buffer()) ==
Catch::Approx(90.2562579028763707).margin(1.0e-16));
}
SECTION("With UQ") {
if constexpr(has_sigma) {
mod.change_input("With UQ?", true);
auto T = mod.run_as<test_pt>(braket);
// Check output
REQUIRE(unwrap_mean(test::trace<2, udouble>(T.buffer())) ==
Catch::Approx(124.7011973877891364).margin(1.0e-16));
REQUIRE(unwrap_sd(test::trace<2, udouble>(T.buffer())) ==
Catch::Approx(7e-16).margin(1.0e-16));
REQUIRE(unwrap_mean(test::norm<2, udouble>(T.buffer())) ==
Catch::Approx(90.2562579028763707).margin(1.0e-16));
REQUIRE(unwrap_sd(test::norm<2, udouble>(T.buffer())) ==
Catch::Approx(3e-16).margin(1.0e-16));
}
}
}
SECTION("3-Index") {
using braket_t = simde::type::braket<aos_t, op_base_t, aos_squared_t>;
using test_pt = simde::EvaluateBraKet<braket_t>;
// Make BraKet Input
braket_t braket(aos, op_base, aos_squared);
auto& mod = mm.at("Evaluate 3-Index BraKet");
SECTION("No UQ") {
// Call module
auto T = mod.run_as<test_pt>(braket);
// Check output
REQUIRE(test::trace<3>(T.buffer()) ==
Catch::Approx(16.8245948391706577).margin(1.0e-16));
REQUIRE(test::norm<3>(T.buffer()) ==
Catch::Approx(20.6560572032543597).margin(1.0e-16));
}
SECTION("With UQ") {
if constexpr(has_sigma) {
mod.change_input("With UQ?", true);
// Call module
auto T = mod.run_as<test_pt>(braket);
// Check output
auto& t = T.buffer();
REQUIRE(unwrap_mean(test::trace<3, udouble>(t)) ==
Catch::Approx(16.8245948391706577).margin(1.0e-16));
REQUIRE(unwrap_sd(test::trace<3, udouble>(t)) ==
Catch::Approx(7e-16).margin(1.0e-16));
REQUIRE(unwrap_mean(test::norm<3, udouble>(t)) ==
Catch::Approx(20.6560572032543597).margin(1.0e-16));
REQUIRE(unwrap_sd(test::norm<3, udouble>(t)) ==
Catch::Approx(7e-16).margin(1.0e-16));
}
}
}
SECTION("4-Index") {
using braket_t =
simde::type::braket<aos_squared_t, op_base_t, aos_squared_t>;
using test_pt = simde::EvaluateBraKet<braket_t>;
// Make BraKet Input
braket_t braket(aos_squared, op_base, aos_squared);
auto& mod = mm.at("Evaluate 4-Index BraKet");
SECTION("No UQ") {
// Call module
auto T = mod.run_as<test_pt>(braket);
// Check output
auto& t = T.buffer();
REQUIRE(test::trace<4>(t) ==
Catch::Approx(9.7919608941952063).margin(1.0e-16));
REQUIRE(test::norm<4>(t) ==
Catch::Approx(7.7796143419802553).margin(1.0e-16));
}
SECTION("With UQ") {
if constexpr(has_sigma) {
// Call module
mod.change_input("With UQ?", true);
auto T = mod.run_as<test_pt>(braket);
// Check output
auto& t = T.buffer();
REQUIRE(unwrap_mean(test::trace<4, udouble>(t)) ==
Catch::Approx(9.7919608941952063).margin(1.0e-16));
REQUIRE(unwrap_sd(test::trace<4, udouble>(t)) ==
Catch::Approx(7e-16).margin(1.0e-16));
REQUIRE(unwrap_mean(test::norm<4, udouble>(t)) ==
Catch::Approx(7.7796143419802553).margin(1.0e-16));
REQUIRE(unwrap_sd(test::norm<4, udouble>(t)) ==
Catch::Approx(11e-16).margin(1.0e-16));
}
}
}
}