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 383 : Settings::expected_options()
33 : {
34 383 : OptionSet options;
35 383 : options.section() = "Settings";
36 383 : options.doc() = "Global settings for tensors, models, etc.";
37 :
38 766 : options.set<std::string>("type") = "Settings";
39 :
40 766 : options.set<std::string>("buffer_name_separator") = "_";
41 1149 : options.set("buffer_name_separator").doc() = "Nested buffer name separator. The default is '_'. "
42 : "For example, a sub-model 'foo' which declares "
43 383 : "a buffer 'bar' will have a buffer named 'foo_bar'.";
44 :
45 766 : options.set<std::string>("parameter_name_separator") = "_";
46 1149 : options.set("parameter_name_separator").doc() =
47 : "Parameter name separator. The default is '_'. For example, a sub-model 'foo' which declares "
48 383 : "a parameter 'bar' will have a parameter named 'foo_bar'.";
49 :
50 766 : options.set<bool>("require_double_precision") = true;
51 1149 : 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 383 : "other precisions.";
55 :
56 766 : options.set<std::vector<std::string>>("additional_libraries");
57 1149 : 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 383 : "or relative to the current working directory.";
62 :
63 766 : options.set<bool>("disable_jit") = false;
64 766 : options.set("disable_jit").doc() =
65 : "Disable JIT compilation of models. This is useful for debugging or when the JIT compiler is "
66 : "not available. When set to false, each individual model can still selectively "
67 : "enable/disable JIT. When set to true, JIT is disabled globally, and it is an error to "
68 383 : "explicitly set jit to true for any model.";
69 :
70 383 : return options;
71 0 : }
72 :
73 383 : Settings::Settings(const OptionSet & options)
74 766 : : _buffer_name_separator(options.get<std::string>("buffer_name_separator")),
75 766 : _parameter_name_separator(options.get<std::string>("parameter_name_separator")),
76 766 : _require_double_precision(options.get<bool>("require_double_precision")),
77 766 : _additional_libraries(options.get<std::vector<std::string>>("additional_libraries")),
78 383 : _disable_jit(options.get<bool>("disable_jit"))
79 : {
80 : // Load additional libraries which may contain custom objects
81 384 : for (const auto & lib : _additional_libraries)
82 1 : Registry::load(lib);
83 383 : }
84 : } // namespace neml2
|