25#include "neml2/base/HITParser.h"
26#include "neml2/base/Factory.h"
27#include "neml2/base/CrossRef.h"
28#include "neml2/tensors/LabeledAxis.h"
29#include "neml2/tensors/tensors.h"
30#include "neml2/tensors/macros.h"
52 hit::explode(
root.get());
90 std::string type =
object->param<std::string>(
"type");
93 extract_options(
object, options);
96 options.name() =
object->path();
97 options.type() = type;
98 options.path() = section->fullpath();
104HITParser::extract_options(hit::Node *
object,
OptionSet & options)
const
107 if (
node->path() !=
"type")
108 extract_option(
node, options);
112HITParser::extract_option(hit::Node * n, OptionSet & options)
const
114#define extract_option_base(ptype, method) \
115 else if (option->type() == \
117 typeid(ptype).name())) dynamic_cast<OptionSet::Option<ptype> *>(option.get()) \
118 ->set() = method(n->strVal())
120#define extract_option_t(ptype) \
121 extract_option_base(ptype, utils::parse<ptype>); \
122 extract_option_base(std::vector<ptype>, utils::parse_vector<ptype>); \
123 extract_option_base(std::vector<std::vector<ptype>>, utils::parse_vector_vector<ptype>)
125#define extract_option_t_cr(ptype) extract_option_t(CrossRef<ptype>)
127 if (n->type() == hit::NodeType::Field)
130 for (
auto & [name, option] : options)
131 if (name == n->path())
136 "' is suppressed, and its value cannot be modified.");
143 extract_option_t(
bool);
144 extract_option_t(
int);
145 extract_option_t(
unsigned int);
147 extract_option_t(
Real);
148 extract_option_t(std::string);
150 extract_option_t(CrossRef<torch::Tensor>);
151 FOR_ALL_BATCHTENSORBASE(extract_option_t_cr);
153 else neml_assert(
false,
"Unsupported option type for option ", n->fullpath());
158 neml_assert(found,
"Unused option ", n->fullpath());
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:52
static std::vector< std::string > pipeline
The sequence which we use to manufacture objects.
Definition Factory.h:42
virtual OptionCollection parse(const std::filesystem::path &filename, const std::string &additional_input="") const override
Deserialize a file.
Definition HITParser.cxx:36
virtual OptionSet extract_object_options(hit::Node *object, hit::Node *section) const
Extract options for a specific object.
Definition HITParser.cxx:87
A data structure that holds options of multiple objects.
Definition OptionCollection.h:38
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
Definition OptionSet.h:59
static std::map< std::string, OptionSet > expected_options()
Return the expected options of all registered classs.
Definition Registry.cxx:38
Definition CrossRef.cxx:32
int64_t TorchSize
Definition types.h:35
std::vector< TorchSize > TorchShape
Definition types.h:36
double Real
Definition types.h:33
LabeledAxisAccessor VariableName
Definition Variable.h:35
void neml_assert(bool assertion, Args &&... args)
Definition error.h:73