51template <
typename,
typename,
typename =
void>
class IgABase;
55class IgABase<
std::tuple<Inputs...>, std::tuple<Outputs...>,
56 std::tuple<CollPts...>> {
59 using value_type = std::common_type_t<
typename Inputs::value_type...,
60 typename Outputs::value_type...>;
85 template <
typename... Objs, std::size_t... NumCoeffs, std::size_t... Is>
87 const std::tuple<std::array<int64_t, NumCoeffs>...> &numCoeffs,
89 std::index_sequence<Is...>) {
90 static_assert(
sizeof...(Objs) ==
sizeof...(NumCoeffs));
91 return std::make_tuple(std::apply(
92 [&]<
typename... Args>(Args &&...args) {
93 return Objs(std::forward<Args>(args)...,
init, options);
95 std::get<Is>(numCoeffs))...);
98 template <
typename... Objs, std::size_t... NumCoeffs>
100 const std::tuple<std::array<int64_t, NumCoeffs>...> &numCoeffs,
102 return construct_tuple_from_arrays_impl<Objs...>(
103 numCoeffs,
init, options, std::index_sequence_for<Objs...>{});
110 template <
typename... Objs,
typename... NumCoeffsTuples, std::size_t... Is>
112 const std::tuple<NumCoeffsTuples...> &numCoeffs,
enum init init,
114 static_assert(
sizeof...(Objs) ==
sizeof...(NumCoeffsTuples));
115 return std::make_tuple(std::apply(
116 [&]<
typename... Args>(Args &&...args) {
117 return Objs(std::forward<Args>(args)...,
init, options);
119 std::get<Is>(numCoeffs))...);
122 template <
typename... Objs,
typename... NumCoeffsTuples>
127 return construct_tuple_from_tuples_impl<Objs...>(
128 numCoeffs,
init, options, std::index_sequence_for<Objs...>{});
137 : inputs_(), outputs_(), collPts_() {}
147 template <std::
size_t NumCoeffs>
149 const std::array<int64_t, NumCoeffs> &ncoeffs,
164 template <std::size_t NumCoeffsInputs, std::size_t NumCoeffsOutputs,
165 std::size_t NumCoeffsCollPts>
166 IgABase(
const std::array<int64_t, NumCoeffsInputs> &ncoeffsInputs,
167 const std::array<int64_t, NumCoeffsOutputs> &ncoeffsOutputs,
168 const std::array<int64_t, NumCoeffsCollPts> &ncoeffsCollPts,
171 :
IgABase(
std::tuple{ncoeffsInputs},
std::tuple{ncoeffsOutputs},
172 std::tuple{ncoeffsCollPts},
init, options) {}
183 template <std::size_t... NumCoeffs>
185 const std::tuple<std::array<int64_t, NumCoeffs>...> &ncoeffs,
188 :
IgABase(ncoeffs, ncoeffs, ncoeffs,
init, options) {}
199 template <std::size_t... NumCoeffsInputs, std::size_t... NumCoeffsOutputs,
200 std::size_t... NumCoeffsCollPts>
202 const std::tuple<std::array<int64_t, NumCoeffsInputs>...> &ncoeffsInputs,
203 const std::tuple<std::array<int64_t, NumCoeffsOutputs>...>
205 const std::tuple<std::array<int64_t, NumCoeffsCollPts>...>
209 : inputs_(construct_tuple_from_arrays<Inputs...>(ncoeffsInputs,
init,
211 outputs_(construct_tuple_from_arrays<Outputs...>(ncoeffsOutputs,
init,
213 collPts_(construct_tuple_from_arrays<Outputs...>(ncoeffsCollPts,
init,
226 template <
typename... CoeffsInputs,
typename... CoeffsOutputs,
227 typename... CoeffsCollPts>
228 IgABase(
const std::tuple<CoeffsInputs...> &coeffsInputs,
229 const std::tuple<CoeffsOutputs...> &coeffsOutputs,
230 const std::tuple<CoeffsCollPts...> &coeffsCollPts,
233 : inputs_(construct_tuple_from_tuples<Inputs...>(coeffsInputs,
init,
235 outputs_(construct_tuple_from_tuples<Outputs...>(coeffsOutputs,
init,
237 collPts_(construct_tuple_from_tuples<CollPts...>(coeffsCollPts,
init,
242 inline static constexpr std::size_t
ninputs() noexcept {
243 return sizeof...(Inputs);
248 inline constexpr const auto &
inputs()
const {
return inputs_; }
252 inline constexpr auto &
inputs() {
return inputs_; }
257 template <std::
size_t index>
inline constexpr const auto &
input()
const {
258 static_assert(index <
sizeof...(Inputs));
259 return std::get<index>(inputs_);
265 template <std::
size_t index>
inline constexpr auto &
input() {
266 static_assert(index <
sizeof...(Inputs));
267 return std::get<index>(inputs_);
272 inline static constexpr std::size_t
noutputs() noexcept {
273 return sizeof...(Outputs);
278 inline constexpr const auto &
outputs()
const {
return outputs_; }
282 inline constexpr auto &
outputs() {
return outputs_; }
287 template <std::
size_t index>
inline constexpr const auto &
output()
const {
288 static_assert(index <
sizeof...(Outputs));
289 return std::get<index>(outputs_);
295 template <std::
size_t index>
inline constexpr auto &
output() {
296 static_assert(index <
sizeof...(Outputs));
297 return std::get<index>(outputs_);
303 inline static constexpr std::size_t
ncollPts() noexcept {
304 return sizeof...(CollPts);
310 inline constexpr const auto &
collPts()
const {
return collPts_; }
315 inline constexpr auto &
collPts() {
return collPts_; }
326 template <std::
size_t index>
327 std::tuple_element_t<index, collPts_type>
333template <detail::HasAsTensor... Inputs, detail::HasAsTensor... Outputs>
334class IgABase<
std::tuple<Inputs...>, std::tuple<Outputs...>, void> {
337 using value_type = std::common_type_t<
typename Inputs::value_type...,
338 typename Outputs::value_type...>;
344 template <std::
size_t index>
345 using input_t = std::tuple_element_t<index, inputs_type>;
351 template <std::
size_t index>
352 using output_t = std::tuple_element_t<index, outputs_type>;
358 template <std::
size_t index>
359 using collPts_t = std::tuple_element_t<index, collPts_type>;
372 template <
typename... Objs, std::size_t... NumCoeffs, std::size_t... Is>
374 const std::tuple<std::array<int64_t, NumCoeffs>...> &numCoeffs,
376 std::index_sequence<Is...>) {
377 static_assert(
sizeof...(Objs) ==
sizeof...(NumCoeffs));
378 return std::make_tuple(Objs(std::get<Is>(numCoeffs),
init, options)...);
381 template <
typename... Objs, std::size_t... NumCoeffs>
383 const std::tuple<std::array<int64_t, NumCoeffs>...> &numCoeffs,
385 return construct_tuple_from_arrays_impl<Objs...>(
386 numCoeffs,
init, options, std::index_sequence_for<Objs...>{});
393 template <
typename... Objs,
typename... NumCoeffs, std::size_t... Is>
395 const std::tuple<NumCoeffs...> &numCoeffs,
enum init init,
397 static_assert(
sizeof...(Objs) ==
sizeof...(NumCoeffs));
398 return std::make_tuple(std::apply(
399 [&]<
typename... Args>(Args &&...args) {
400 return Objs(std::forward<Args>(args)...,
init, options);
402 std::get<Is>(numCoeffs))...);
405 template <
typename... Objs,
typename... NumCoeffsTuples>
410 return construct_tuple_from_tuples_impl<Objs...>(
411 numCoeffs,
init, options, std::index_sequence_for<Objs...>{});
420 : inputs_(), outputs_() {}
430 template <std::
size_t NumCoeffs>
432 const std::array<int64_t, NumCoeffs> &ncoeffs,
447 template <std::
size_t NumCoeffsInputs, std::
size_t NumCoeffsOutputs>
448 IgABase(
const std::array<int64_t, NumCoeffsInputs> &ncoeffsInputs,
449 const std::array<int64_t, NumCoeffsOutputs> &ncoeffsOutputs,
464 template <std::size_t... NumCoeffs>
466 const std::tuple<std::array<int64_t, NumCoeffs>...> &ncoeffs,
481 template <std::size_t... NumCoeffsInputs, std::size_t... NumCoeffsOutputs>
483 const std::tuple<std::array<int64_t, NumCoeffsInputs>...> &ncoeffsInputs,
484 const std::tuple<std::array<int64_t, NumCoeffsOutputs>...>
488 : inputs_(construct_tuple_from_arrays<Inputs...>(ncoeffsInputs,
init,
490 outputs_(construct_tuple_from_arrays<Outputs...>(ncoeffsOutputs,
init,
503 template <
typename... CoeffsInputs,
typename... CoeffsOutputs>
504 IgABase(
const std::tuple<CoeffsInputs...> &coeffsInputs,
505 const std::tuple<CoeffsOutputs...> &coeffsOutputs,
508 : inputs_(construct_tuple_from_tuples<Inputs...>(coeffsInputs,
init,
510 outputs_(construct_tuple_from_tuples<Outputs...>(coeffsOutputs,
init,
515 inline static constexpr std::size_t
ninputs() noexcept {
516 return sizeof...(Inputs);
521 inline constexpr const auto &
inputs()
const {
return inputs_; }
525 inline constexpr auto &
inputs() {
return inputs_; }
530 template <std::
size_t index>
inline constexpr const auto &
input()
const {
531 static_assert(index <
sizeof...(Inputs));
532 return std::get<index>(inputs_);
538 template <std::
size_t index>
inline constexpr auto &
input() {
539 static_assert(index <
sizeof...(Inputs));
540 return std::get<index>(inputs_);
545 inline static constexpr std::size_t
noutputs() noexcept {
546 return sizeof...(Outputs);
551 inline constexpr const auto &
outputs()
const {
return outputs_; }
555 inline constexpr auto &
outputs() {
return outputs_; }
560 template <std::
size_t index>
inline constexpr const auto &
output()
const {
561 static_assert(index <
sizeof...(Outputs));
562 return std::get<index>(outputs_);
568 template <std::
size_t index>
inline constexpr auto &
output() {
569 static_assert(index <
sizeof...(Outputs));
570 return std::get<index>(outputs_);
576 inline static constexpr std::size_t
ncollPts() noexcept {
577 return sizeof...(Outputs);
583 inline constexpr const auto &
collPts()
const {
return outputs_; }
588 inline constexpr auto &
collPts() {
return outputs_; }
599 template <std::
size_t index>
600 std::tuple_element_t<index, collPts_type>
610template <
typename Optimizer,
typename Inputs,
typename Outputs,
611 typename CollPts =
void>
612 requires OptimizerType<Optimizer>
634 std::unique_ptr<optimizer_type>
opt_;
662 template <
typename NumCoeffs>
663 IgANet(
const std::vector<int64_t> &layers,
664 const std::vector<std::vector<std::any>> &activations,
669 :
IgANet(layers, activations, numCoeffs, numCoeffs,
init, defaults,
683 template <
typename NumCoeffsInputs,
typename NumCoeffsOutputs>
684 IgANet(
const std::vector<int64_t> &layers,
685 const std::vector<std::vector<std::any>> &activations,
686 const NumCoeffsInputs &numCoeffsInputs,
687 const NumCoeffsOutputs &numCoeffsOutputs,
695 std::vector<int64_t>{
inputs( 0).size(0)}, layers,
696 std::vector<int64_t>{
outputs( 0).size(0)}),
700 opt_(std::make_unique<optimizer_type>(
net_->parameters())),
729 opt_ = std::make_unique<optimizer_type>(
net_->parameters());
731 std::vector<optimizer_options_type>
options;
732 for (
auto &group :
opt_->param_groups())
735 opt_ = std::make_unique<optimizer_type>(
net_->parameters());
752 if (param_group < opt_->param_groups().size())
754 opt_->param_groups()[param_group].options());
756 throw std::runtime_error(
"Index exceeds number of parameter groups");
764 if (param_group < opt_->param_groups().size())
766 opt_->param_groups()[param_group].options());
768 throw std::runtime_error(
"Index exceeds number of parameter groups");
774 for (
auto &group :
opt_->param_groups())
781 for (
auto &group :
opt_->param_groups())
789 std::size_t param_group) {
790 if (param_group < opt_->param_groups().size())
794 throw std::runtime_error(
"Index exceeds number of parameter groups");
801 std::size_t param_group) {
802 if (param_group < opt_->param_groups().size())
806 throw std::runtime_error(
"Index exceeds number of parameter groups");
819 inline constexpr const auto &
inputs()
const {
return Base::inputs(); }
823 inline constexpr auto &
inputs() {
return Base::inputs(); }
827 inline constexpr const auto &
outputs()
const {
return Base::outputs(); }
831 inline constexpr auto &
outputs() {
return Base::outputs(); }
838 Base::inputs_, [](
const auto &obj) {
return obj.as_tensor(); });
846 Base::outputs_, [](
const auto &obj) {
return obj.as_tensor(); });
851 virtual void inputs(
const torch::Tensor &tensor) {
853 Base::inputs_, tensor,
854 [](
const auto &obj) {
return obj.as_tensor_size(); },
855 [](
auto &obj,
const auto &tensor) {
return obj.from_tensor(tensor); });
860 virtual void outputs(
const torch::Tensor &tensor) {
862 Base::outputs_, tensor,
863 [](
const auto &obj) {
return obj.as_tensor_size(); },
864 [](
auto &obj,
const auto &tensor) {
return obj.from_tensor(tensor); });
873 virtual torch::Tensor
loss(
const torch::Tensor &, int64_t) = 0;
877#ifdef IGANET_WITH_MPI
878 c10::intrusive_ptr<c10d::ProcessGroupMPI> pg =
879 c10d::ProcessGroupMPI::createProcessGroupMPI()
883 typename Base::value_type previous_loss(-1.0);
892 auto closure = [&]() {
903 loss.backward({},
true,
false);
908#ifdef IGANET_WITH_MPI
914 std::vector<c10::intrusive_ptr<::c10d::Work>> works;
915 for (
auto ¶m :
net_->named_parameters()) {
916 std::vector<torch::Tensor> tmp = {param.value().grad()};
917 works.emplace_back(pg->allreduce(tmp));
922 for (
auto ¶m :
net_->named_parameters()) {
923 param.value().grad().data() =
924 param.value().grad().data() / pg->getSize();
931 typename Base::value_type current_loss =
932 loss.item<
typename Base::value_type>();
934 << current_loss << std::endl;
936 if (current_loss <
options_.min_loss() ||
937 std::abs(current_loss - previous_loss) <
options_.min_loss_change() ||
938 std::abs(current_loss - previous_loss) / current_loss <
940 loss.isnan().item<
bool>()) {
942 <<
", loss: " << current_loss << std::endl;
945 previous_loss = current_loss;
948 <<
", loss: " << previous_loss << std::endl;
954#ifdef IGANET_WITH_MPI
957 template <
typename DataLoader>
959#ifdef IGANET_WITH_MPI
961 c10::intrusive_ptr<c10d::ProcessGroupMPI> pg =
962 c10d::ProcessGroupMPI::createProcessGroupMPI()
966 typename Base::value_type previous_loss(-1.0);
971 typename Base::value_type current_loss(0);
973 for (
auto &batch : loader) {
1011 auto closure = [&]() {
1022 loss.backward({},
true,
false);
1028 opt_->step(closure);
1030 current_loss +=
loss.item<
typename Base::value_type>();
1033 << current_loss << std::endl;
1035 if (current_loss <
options_.min_loss() ||
1036 std::abs(current_loss - previous_loss) <
options_.min_loss_change() ||
1037 std::abs(current_loss - previous_loss) / current_loss <
1039 loss.isnan().item<
bool>()) {
1041 <<
", loss: " << current_loss << std::endl;
1044 previous_loss = current_loss;
1047 <<
", loss: " << previous_loss << std::endl;
1060 return "Not implemented yet";
1066 return net_->parameters();
1072 inline torch::OrderedDict<std::string, torch::Tensor>
1074 return net_->named_parameters();
1080 std::size_t result = 0;
1081 for (
const auto ¶m : this->
parameters()) {
1082 result += param.numel();
1093 return net_->register_parameter(
name, tensor, requires_grad);
1099 os <<
name() <<
"(\n"
1100 <<
"net = " <<
net_ <<
"\n";
1102 os <<
"inputs[" << Base::ninputs() <<
"] = (";
1103 std::apply([&os](
const auto &...elems) { ((os << elems <<
"\n"), ...); },
1107 os <<
"outputs [" << Base::noutputs() <<
"]= (";
1108 std::apply([&os](
const auto &...elems) { ((os << elems <<
"\n"), ...); },
1112 os <<
"collPts [" << Base::ncollPts() <<
"]= (";
1113 std::apply([&os](
const auto &...elems) { ((os << elems <<
"\n"), ...); },
1121 inline void save(
const std::string &filename,
1122 const std::string &key =
"iganet")
const {
1123 torch::serialize::OutputArchive archive;
1124 write(archive, key).save_to(filename);
1130 inline void load(
const std::string &filename,
1131 const std::string &key =
"iganet") {
1132 torch::serialize::InputArchive archive;
1133 archive.load_from(filename);
1141 inline torch::serialize::OutputArchive &
1142 write(torch::serialize::OutputArchive &archive,
1143 const std::string &key =
"iganet")
const {
1146 [&](
auto &&...elems) {
1147 std::size_t counter = 0;
1148 (elems.write(archive,
1149 key +
".input[" + std::to_string(counter++) +
"]"),
1155 [&](
auto &&...elems) {
1156 std::size_t counter = 0;
1157 (elems.write(archive,
1158 key +
".output[" + std::to_string(counter++) +
"]"),
1163 if constexpr (!std::is_void_v<CollPts>) {
1165 [&](
auto &&...elems) {
1166 std::size_t counter = 0;
1167 (elems.write(archive,
1168 key +
".collpts[" + std::to_string(counter++) +
"]"),
1174 net_->write(archive, key +
".net");
1175 torch::serialize::OutputArchive archive_net;
1176 net_->save(archive_net);
1177 archive.write(key +
".net.data", archive_net);
1179 torch::serialize::OutputArchive archive_opt;
1180 opt_->save(archive_opt);
1181 archive.write(key +
".opt", archive_opt);
1190 inline torch::serialize::InputArchive &
1191 read(torch::serialize::InputArchive &archive,
1192 const std::string &key =
"iganet") {
1195 [&](
auto &&...elems) {
1196 std::size_t counter = 0;
1197 (elems.read(archive,
1198 key +
".input[" + std::to_string(counter++) +
"]"),
1204 [&](
auto &&...elems) {
1205 std::size_t counter = 0;
1206 (elems.read(archive,
1207 key +
".output[" + std::to_string(counter++) +
"]"),
1212 if constexpr (!std::is_void_v<CollPts>) {
1214 [&](
auto &&...elems) {
1215 std::size_t counter = 0;
1216 (elems.read(archive,
1217 key +
".collpts[" + std::to_string(counter++) +
"]"),
1223 net_->read(archive, key +
".net");
1224 torch::serialize::InputArchive archive_net;
1225 archive.read(key +
".net.data", archive_net);
1226 net_->load(archive_net);
1228 opt_->add_parameters(
net_->parameters());
1229 torch::serialize::InputArchive archive_opt;
1230 archive.read(key +
".opt", archive_opt);
1231 opt_->load(archive_opt);
1242 result *= std::apply(
1243 [&](
auto &&...elemsThis) {
1245 [&](
auto &&...elemsOther) {
1246 return ((elemsThis == elemsOther) && ...);
1260#ifdef IGANET_WITH_MPI
1263 static void waitWork(c10::intrusive_ptr<c10d::ProcessGroupMPI> pg,
1264 std::vector<c10::intrusive_ptr<c10d::Work>> works) {
1265 for (
auto &work : works) {
1268 }
catch (
const std::exception &ex) {
1269 Log(
log::error) <<
"Exception received during waitWork: " << ex.what()
1282template <
typename Optimizer,
typename Inputs,
typename Outputs,
1284 requires OptimizerType<Optimizer>
1285inline std::ostream &
1307 []<
typename... Elems>(Elems &&...elems) {
1308 return std::make_tuple(([&] {
1309 using T = std::decay_t<Elems>;
1311 return elems.template find_knot_indices<functionspace::interior>(
1312 typename T::eval_type{});
1315 return elems.find_knot_indices(
typename T::eval_type{});
1324 []<
typename... Elems>(Elems &&...elems) {
1325 return std::make_tuple(([&] {
1326 using T = std::decay_t<Elems>;
1328 return elems.template find_knot_indices<functionspace::boundary>(
1329 typename T::boundary_eval_type{});
1332 return elems.find_knot_indices(
typename T::eval_type{});
1341 []<
typename... Elems>(Elems &&...elems) {
1342 return std::make_tuple(([&] {
1343 using T = std::decay_t<Elems>;
1345 return elems.template find_coeff_indices<functionspace::interior>(
1346 typename T::eval_type{});
1349 return elems.find_coeff_indices(
typename T::eval_type{});
1358 []<
typename... Elems>(Elems &&...elems) {
1359 return std::make_tuple(([&] {
1360 using T = std::decay_t<Elems>;
1362 return elems.template find_coeff_indices<functionspace::boundary>(
1363 typename T::boundary_eval_type{});
1366 return elems.find_coeff_indices(
typename T::eval_type{});
1375 std::declval<std::tuple<Inputs...>>()));
1379 template <std::
size_t index>
1381 std::tuple_element_t<index, inputs_interior_knot_indices_type>;
1385 std::declval<std::tuple<Inputs...>>()));
1389 template <std::
size_t index>
1391 std::tuple_element_t<index, inputs_boundary_knot_indices_type>;
1395 decltype(find_interior_knot_indices(
1396 std::declval<std::tuple<Outputs...>>()));
1400 template <std::
size_t index>
1402 std::tuple_element_t<index, outputs_interior_knot_indices_type>;
1406 decltype(find_boundary_knot_indices(
1407 std::declval<std::tuple<Outputs...>>()));
1411 template <std::
size_t index>
1413 std::tuple_element_t<index, outputs_boundary_knot_indices_type>;
1417 decltype(find_interior_coeff_indices(
1418 std::declval<std::tuple<Inputs...>>()));
1422 template <std::
size_t index>
1424 std::tuple_element_t<index, inputs_interior_coeff_indices_type>;
1428 decltype(find_boundary_coeff_indices(
1429 std::declval<std::tuple<Inputs...>>()));
1433 template <std::
size_t index>
1435 std::tuple_element_t<index, inputs_boundary_coeff_indices_type>;
1439 decltype(find_interior_coeff_indices(
1440 std::declval<std::tuple<Outputs...>>()));
1444 template <std::
size_t index>
1446 std::tuple_element_t<index, outputs_interior_coeff_indices_type>;
1450 decltype(find_boundary_coeff_indices(
1451 std::declval<std::tuple<Outputs...>>()));
1455 template <std::
size_t index>
1457 std::tuple_element_t<index, outputs_boundary_coeff_indices_type>;
1463 std::tuple<CollPts...>>
1470 decltype(std::declval<CollPts>()
1471 .template find_knot_indices<functionspace::interior>(
1472 std::declval<typename CollPts::eval_type>()))...>;
1477 decltype(std::declval<CollPts>()
1478 .template find_knot_indices<functionspace::boundary>(
1480 typename CollPts::boundary_eval_type>()))...>;
1485 decltype(std::declval<CollPts>()
1486 .template find_coeff_indices<functionspace::interior>(
1487 std::declval<typename CollPts::eval_type>()))...>;
1492 decltype(std::declval<CollPts>()
1493 .template find_coeff_indices<functionspace::boundary>(
1495 typename CollPts::boundary_eval_type>()))...>;
Definition unittest_iganet.cxx:22
IgA base class.
Definition iganet.hpp:51
IgANetGenerator.
Definition generator.hpp:940
IgANet.
Definition iganet.hpp:615
void optimizerReset(bool resetOptions=true)
Resets the optimizer.
Definition iganet.hpp:727
void optimizerReset(const optimizer_options_type &optimizerOptions)
Resets the optimizer.
Definition iganet.hpp:743
void load(const std::string &filename, const std::string &key="iganet")
Loads the IgANet from file.
Definition iganet.hpp:1130
constexpr auto & inputs()
Returns a non-constant reference to the tuple of input objects.
Definition iganet.hpp:823
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="iganet") const
Writes the IgANet into a torch::serialize::OutputArchive object.
Definition iganet.hpp:1142
virtual void outputs(const torch::Tensor &tensor)
Attaches the given tensor to the outputs.
Definition iganet.hpp:860
void train(DataLoader &loader)
Trains the IgANet.
Definition iganet.hpp:958
const optimizer_type & optimizer() const
Returns a constant reference to the optimizer.
Definition iganet.hpp:717
void optimizerOptionsReset(optimizer_options_type &&options, std::size_t param_group)
Resets the optimizer options.
Definition iganet.hpp:800
torch::OrderedDict< std::string, torch::Tensor > named_parameters() const noexcept
Returns a constant reference to the named parameters of the IgANet object.
Definition iganet.hpp:1073
Base::value_type value_type
Value type.
Definition iganet.hpp:621
std::vector< torch::Tensor > parameters() const noexcept
Returns a constant reference to the parameters of the IgANet object.
Definition iganet.hpp:1065
torch::Tensor & register_parameter(std::string name, torch::Tensor tensor, bool requires_grad=true)
Registers a parameter.
Definition iganet.hpp:1092
void save(const std::string &filename, const std::string &key="iganet") const
Saves the IgANet to file.
Definition iganet.hpp:1121
void optimizerOptionsReset(const optimizer_options_type &options)
Resets the optimizer options.
Definition iganet.hpp:773
IgANet(const IgANetOptions &defaults={}, iganet::Options< typename Base::value_type > options=iganet::Options< typename Base::value_type >{})
Default constructor.
Definition iganet.hpp:643
optimizer_type & optimizer()
Returns a non-constant reference to the optimizer.
Definition iganet.hpp:721
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="iganet")
Loads the IgANet from a torch::serialize::InputArchive object.
Definition iganet.hpp:1191
IgANet(const std::vector< int64_t > &layers, const std::vector< std::vector< std::any > > &activations, const NumCoeffsInputs &numCoeffsInputs, const NumCoeffsOutputs &numCoeffsOutputs, enum init init=init::greville, IgANetOptions defaults={}, iganet::Options< typename Base::value_type > options=iganet::Options< typename Base::value_type >{})
Constructor: number of layers, activation functions, and number of spline coefficients (same for all ...
Definition iganet.hpp:684
virtual bool epoch(int64_t)=0
Initializes epoch.
const IgANetGenerator< typename Base::value_type > & net() const
Returns a constant reference to the IgANet generator.
Definition iganet.hpp:707
auto & options()
Returns a non-constant reference to the options structure.
Definition iganet.hpp:815
IgANetGenerator< typename Base::value_type > net_
IgANet generator.
Definition iganet.hpp:631
IgABase< Inputs, Outputs, CollPts > Base
Base type.
Definition iganet.hpp:618
std::unique_ptr< optimizer_type > opt_
Optimizer.
Definition iganet.hpp:634
bool operator!=(const IgANet &other) const
Returns true if both IgANet objects are different.
Definition iganet.hpp:1258
IgANetOptions options_
Options.
Definition iganet.hpp:637
constexpr auto & outputs()
Returns a non-constant reference to the tuple of output objects.
Definition iganet.hpp:831
optimizer_options_type & optimizerOptions(std::size_t param_group=0)
Returns a non-constant reference to the optimizer options.
Definition iganet.hpp:751
virtual torch::Tensor outputs(int64_t epoch) const
Returns the network outputs as tensor.
Definition iganet.hpp:844
IgANet(const std::vector< int64_t > &layers, const std::vector< std::vector< std::any > > &activations, const NumCoeffs &numCoeffs, enum init init=init::greville, IgANetOptions defaults={}, iganet::Options< typename Base::value_type > options=iganet::Options< typename Base::value_type >{})
Constructor: number of layers, activation functions, and number of spline coefficients (same for all ...
Definition iganet.hpp:663
virtual void train()
Trains the IgANet.
Definition iganet.hpp:876
std::size_t nparameters() const noexcept
Returns the total number of parameters of the IgANet object.
Definition iganet.hpp:1079
Optimizer optimizer_type
Type of the optimizer.
Definition iganet.hpp:624
void optimizerOptionsReset(optimizer_options_type &&options)
Resets the optimizer options.
Definition iganet.hpp:780
optimizer_options_type< Optimizer >::type optimizer_options_type
Type of the optimizer options.
Definition iganet.hpp:627
virtual torch::Tensor inputs(int64_t epoch) const
Returns the network inputs as tensor.
Definition iganet.hpp:836
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the IgANet object.
Definition iganet.hpp:1098
virtual void inputs(const torch::Tensor &tensor)
Attaches the given tensor to the inputs.
Definition iganet.hpp:851
bool operator==(const IgANet &other) const
Returns true if both IgANet objects are the same.
Definition iganet.hpp:1239
nlohmann::json to_json() const override
Returns the IgANet object as JSON object.
Definition iganet.hpp:1059
void optimizerOptionsReset(const optimizer_options_type &options, std::size_t param_group)
Resets the optimizer options.
Definition iganet.hpp:788
constexpr const auto & inputs() const
Returns a constant reference to the tuple of input objects.
Definition iganet.hpp:819
constexpr const auto & outputs() const
Returns a constant reference to the tuple of output objects.
Definition iganet.hpp:827
void eval()
Evaluate IgANet.
Definition iganet.hpp:1051
const auto & options() const
Returns a constant reference to the options structure.
Definition iganet.hpp:811
IgANetGenerator< typename Base::value_type > & net()
Returns a non-constant reference to the IgANet generator.
Definition iganet.hpp:713
const optimizer_options_type & optimizerOptions(std::size_t param_group=0) const
Returns a constant reference to the optimizer options.
Definition iganet.hpp:763
virtual torch::Tensor loss(const torch::Tensor &, int64_t)=0
Computes the loss function.
The Options class handles the automated determination of dtype from the template argument and the sel...
Definition options.hpp:47
Full qualified name descriptor.
Definition fqn.hpp:22
virtual const std::string & name() const noexcept
Returns the full qualified name of the object.
Definition fqn.hpp:28
Isogeometric analysis base class.
Definition bspline.hpp:123
Definition bspline.hpp:116
Definition functionspace.hpp:54
Definition functionspace.hpp:47
Container utility functions.
Full qualified name utility functions.
auto zip(T &&...seqs)
Provides the zip operation.
Definition zip.hpp:135
void slice_tensor_into_tuple(std::tuple< Tensors... > &tuple, const torch::Tensor &tensor, FuncSize &&funcSize, FuncAssign &&funcAssign, int64_t &offset, int64_t dim=0)
Slices the given tensor into the objects of the std::tuple.
Definition tuple.hpp:140
torch::Tensor cat_tuple_into_tensor(const std::tuple< Tensors... > &tensors, int64_t dim=0)
Concatenates the entries of a std::tuple object into a single Torch tensor along the given dimension.
Definition tuple.hpp:87
collPts
Enumerator for the collocation point specifier.
Definition collocation.hpp:21
std::ostream & operator<<(std::ostream &os, const MemoryDebugger< id > &obj)
Prints a memory debugger object.
Definition memory.hpp:145
struct iganet::@0 Log
Logger.
init
Enumerator for specifying the initialization of B-spline coefficients.
Definition bspline.hpp:58
Collocation points helper
Definition collocation.hpp:35
IgANetCustomizable.
Definition iganet.hpp:1299
Type trait for the optimizer options type.
Definition optimizer.hpp:32
IgANetOptions.
Definition iganet.hpp:34
TORCH_ARG(double, min_loss_change)=0
Provides the TORCH_ARG operation.
TORCH_ARG(int64_t, batch_size)
Provides the TORCH_ARG operation.
TORCH_ARG(double, min_loss)
Provides the TORCH_ARG operation.
TORCH_ARG(double, min_loss_rel_change)
Provides the TORCH_ARG operation.
TORCH_ARG(int64_t, max_epoch)
Provides the TORCH_ARG operation.
Serialization prototype.
Definition serialize.hpp:29