https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Namespaces | Functions
LibtorchArtificialNeuralNet.C File Reference

Go to the source code of this file.

Namespaces

namespace  Moose
 MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to address this in their environment if C++17 compatibility isn't found.
 

Functions

void Moose::to_json (nlohmann::json &json, const Moose::LibtorchArtificialNeuralNet *const &network)
 Dump an artificial neural network into JSON for reporter output and debugging.
 
void Moose::loadLibtorchArtificialNeuralNetState (Moose::LibtorchArtificialNeuralNet &nn, const std::string &filename)
 Load an artificial-neural-network checkpoint written as a native libtorch state archive.
 
template<>
void dataStore< Moose::LibtorchArtificialNeuralNet > (std::ostream &stream, std::shared_ptr< Moose::LibtorchArtificialNeuralNet > &nn, void *context)
 Serialize the artificial-neural-network metadata needed for restart.
 
template<>
void dataLoad< Moose::LibtorchArtificialNeuralNet > (std::istream &stream, std::shared_ptr< Moose::LibtorchArtificialNeuralNet > &nn, void *context)
 Deserialize the artificial-neural-network metadata needed for restart.
 
template<>
void dataStore< Moose::LibtorchArtificialNeuralNet const > (std::ostream &, Moose::LibtorchArtificialNeuralNet const *&, void *)
 Placeholder serializer for reporter-only artificial-neural-network pointers.
 
template<>
void dataLoad< Moose::LibtorchArtificialNeuralNet const > (std::istream &, Moose::LibtorchArtificialNeuralNet const *&, void *)
 Placeholder deserializer for reporter-only artificial-neural-network pointers.
 

Function Documentation

◆ dataLoad< Moose::LibtorchArtificialNeuralNet >()

template<>
void dataLoad< Moose::LibtorchArtificialNeuralNet > ( std::istream &  stream,
std::shared_ptr< Moose::LibtorchArtificialNeuralNet > &  nn,
void *  context 
)

Deserialize the artificial-neural-network metadata needed for restart.

Parameters
streamStream that provides the serialized data.
nnArtificial neural network shared pointer to populate.
contextSerialization context passed through MOOSE data I/O.

Definition at line 516 of file LibtorchArtificialNeuralNet.C.

519{
520 std::string name;
521 dataLoad(stream, name, context);
522
523 unsigned int num_inputs;
524 dataLoad(stream, num_inputs, context);
525
526 unsigned int num_outputs;
527 dataLoad(stream, num_outputs, context);
528
529 unsigned int num_hidden_layers;
530 dataLoad(stream, num_hidden_layers, context);
531
532 std::vector<unsigned int> num_neurons_per_layer;
533 num_neurons_per_layer.resize(num_hidden_layers);
534 dataLoad(stream, num_neurons_per_layer, context);
535
536 unsigned int num_activation_items;
537 dataLoad(stream, num_activation_items, context);
538
539 std::vector<std::string> activation_functions;
540 activation_functions.resize(num_activation_items);
541 dataLoad(stream, activation_functions, context);
542
543 std::underlying_type<torch::DeviceType>::type device_type;
544 dataLoad(stream, device_type, context);
545 const torch::DeviceType divt(static_cast<torch::DeviceType>(device_type));
546
547 std::underlying_type<torch::ScalarType>::type data_type;
548 dataLoad(stream, data_type, context);
549 const torch::ScalarType datt(static_cast<torch::ScalarType>(data_type));
550
551 nn = std::make_shared<Moose::LibtorchArtificialNeuralNet>(
552 name, num_inputs, num_outputs, num_neurons_per_layer, activation_functions, divt, datt);
553
555}
void dataLoad(std::istream &stream, LineSegment &l, void *context)
void loadLibtorchArtificialNeuralNetState(Moose::LibtorchArtificialNeuralNet &nn, const std::string &filename)
Load an artificial-neural-network checkpoint written as a native libtorch state archive.
MPI_Datatype data_type
std::string name(const ElemQuality q)

◆ dataLoad< Moose::LibtorchArtificialNeuralNet const >()

template<>
void dataLoad< Moose::LibtorchArtificialNeuralNet const > ( std::istream &  stream,
Moose::LibtorchArtificialNeuralNet const *&  nn,
void *  context 
)

Placeholder deserializer for reporter-only artificial-neural-network pointers.

Parameters
streamStream that would provide the serialized data.
nnReporter neural network pointer.
contextSerialization context passed through MOOSE data I/O.

Definition at line 567 of file LibtorchArtificialNeuralNet.C.

572{
573}

◆ dataStore< Moose::LibtorchArtificialNeuralNet >()

template<>
void dataStore< Moose::LibtorchArtificialNeuralNet > ( std::ostream &  stream,
std::shared_ptr< Moose::LibtorchArtificialNeuralNet > &  nn,
void *  context 
)

Serialize the artificial-neural-network metadata needed for restart.

Parameters
streamStream that receives the serialized data.
nnArtificial neural network shared pointer to serialize.
contextSerialization context passed through MOOSE data I/O.

Definition at line 478 of file LibtorchArtificialNeuralNet.C.

481{
482 std::string n(nn->name());
483 dataStore(stream, n, context);
484
485 unsigned int ni(nn->numInputs());
486 dataStore(stream, ni, context);
487
488 unsigned int no(nn->numOutputs());
489 dataStore(stream, no, context);
490
491 unsigned int nhl(nn->numHiddenLayers());
492 dataStore(stream, nhl, context);
493
494 std::vector<unsigned int> nnpl(nn->numNeuronsPerLayer());
495 dataStore(stream, nnpl, context);
496
497 unsigned int afs(nn->activationFunctions().size());
498 dataStore(stream, afs, context);
499
500 std::vector<std::string> items(afs);
501 for (unsigned int i = 0; i < afs; ++i)
502 items[i] = nn->activationFunctions()[i];
503
504 dataStore(stream, items, context);
505
506 auto device_type = static_cast<std::underlying_type<torch::DeviceType>::type>(nn->deviceType());
507 dataStore(stream, device_type, context);
508
509 auto data_type = static_cast<std::underlying_type<torch::ScalarType>::type>(nn->dataType());
510 dataStore(stream, data_type, context);
511
512 torch::save(nn, nn->name());
513}
void dataStore(std::ostream &stream, LineSegment &l, void *context)

◆ dataStore< Moose::LibtorchArtificialNeuralNet const >()

template<>
void dataStore< Moose::LibtorchArtificialNeuralNet const > ( std::ostream &  stream,
Moose::LibtorchArtificialNeuralNet const *&  nn,
void *  context 
)

Placeholder serializer for reporter-only artificial-neural-network pointers.

Parameters
streamStream that would receive the serialized data.
nnReporter neural network pointer.
contextSerialization context passed through MOOSE data I/O.

Definition at line 558 of file LibtorchArtificialNeuralNet.C.

563{
564}