Line data Source code
1 : // Copyright 2024, UChicago Argonne, LLC
2 : // All Rights Reserved
3 : // Software Name: NEML2 -- the New Engineering material Model Library, version 2
4 : // By: Argonne National Laboratory
5 : // OPEN SOURCE LICENSE (MIT)
6 : //
7 : // Permission is hereby granted, free of charge, to any person obtaining a copy
8 : // of this software and associated documentation files (the "Software"), to deal
9 : // in the Software without restriction, including without limitation the rights
10 : // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 : // copies of the Software, and to permit persons to whom the Software is
12 : // furnished to do so, subject to the following conditions:
13 : //
14 : // The above copyright notice and this permission notice shall be included in
15 : // all copies or substantial portions of the Software.
16 : //
17 : // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 : // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 : // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 : // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 : // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 : // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 : // THE SOFTWARE.
24 :
25 : #include "neml2/base/Settings.h"
26 : #include "neml2/base/OptionSet.h"
27 : #include "neml2/base/Registry.h"
28 :
29 : namespace neml2
30 : {
31 : OptionSet
32 358 : Settings::expected_options()
33 : {
34 358 : OptionSet options;
35 358 : options.section() = "Settings";
36 358 : options.doc() = "Global settings for tensors, models, etc.";
37 :
38 716 : options.set<std::string>("type") = "Settings";
39 :
40 716 : options.set<std::string>("buffer_name_separator") = "_";
41 1074 : options.set("buffer_name_separator").doc() = "Nested buffer name separator. The default is '_'. "
42 : "For example, a sub-model 'foo' which declares "
43 358 : "a buffer 'bar' will have a buffer named 'foo_bar'.";
44 :
45 716 : options.set<std::string>("parameter_name_separator") = "_";
46 1074 : options.set("parameter_name_separator").doc() =
47 : "Parameter name separator. The default is '_'. For example, a sub-model 'foo' which declares "
48 358 : "a parameter 'bar' will have a parameter named 'foo_bar'.";
49 :
50 716 : options.set<bool>("require_double_precision") = true;
51 1074 : options.set("require_double_precision").doc() =
52 : "Require double precision for all computations. An error will be thrown when Model forward "
53 : "operators are called if the default dtype is not Float64. Set this option to false to allow "
54 358 : "other precisions.";
55 :
56 716 : options.set<std::vector<std::string>>("additional_libraries");
57 716 : options.set("additional_libraries").doc() =
58 : "Additional dynamic libraries to load at runtime. The Registry from these libraries are "
59 : "merged into the current Registry singleton. This is required for using custom models "
60 : "defined in dynamic libraries not directly linked to libneml2. The paths are either absolute "
61 358 : "or relative to the current working directory.";
62 :
63 358 : return options;
64 0 : }
65 :
66 358 : Settings::Settings(const OptionSet & options)
67 716 : : _buffer_name_separator(options.get<std::string>("buffer_name_separator")),
68 716 : _parameter_name_separator(options.get<std::string>("parameter_name_separator")),
69 716 : _require_double_precision(options.get<bool>("require_double_precision")),
70 358 : _additional_libraries(options.get<std::vector<std::string>>("additional_libraries"))
71 : {
72 : // Load additional libraries which may contain custom objects
73 359 : for (const auto & lib : _additional_libraries)
74 1 : Registry::load(lib);
75 358 : }
76 : } // namespace neml2
|