Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-16 08:34:51

0001 // -*- C++ -*-
0002 #ifndef RIVET_RivetLWTNN_HH
0003 #define RIVET_RivetLWTNN_HH
0004 
0005 #include "Rivet/Tools/RivetPaths.hh"
0006 #include "lwtnn/LightweightNeuralNetwork.hh"
0007 #include "lwtnn/LightweightGraph.hh"
0008 #include "lwtnn/Exceptions.hh"
0009 #include "lwtnn/parse_json.hh"
0010 #include <fstream>
0011 
0012 namespace Rivet {
0013   using namespace std;
0014 
0015 
0016   /// Read a LWT DNN config from the JSON path
0017   ///
0018   /// @deprecated LWTNN is not under active development any more so Rivet support will be removed in the near future.
0019   /// Convert your neural net to ONNX instead.
0020   lwt::JSONConfig readLWTNNConfig(const string& jsonpath) {
0021     ifstream input;
0022     try {
0023       // Note: a failed read here may fail quietly, and cause the filestream to
0024       // go bad, making it look like the hepmc event-read has failed.
0025       input = std::ifstream(jsonpath);
0026       return lwt::parse_json(input);
0027     } catch (lwt::LightweightNNException &e) {
0028       input.close();
0029       throw IOError("Error loading LWTNN JSON config");
0030     }
0031   }
0032 
0033 
0034   /// @brief Read a LWT Graph config from the JSON path
0035   ///
0036   /// Note graph here means "not linear" rather than a GNN
0037   ///
0038   /// @deprecated LWTNN is not under active development any more so Rivet support will be removed in the near future.
0039   /// Convert your neural net to ONNX instead.
0040   lwt::GraphConfig readLWTNNGraphConfig(const string& jsonpath) {
0041     ifstream input;
0042     try {
0043       // Note: a failed read here may fail quietly, and cause the filestream to
0044       // go bad, making it look like the hepmc event-read has failed.
0045       input = std::ifstream(jsonpath);
0046       return lwt::parse_json_graph(input);
0047     } catch (lwt::LightweightNNException &e) {
0048       input.close();
0049       throw IOError("Error loading LWTNN JSON config");
0050     }
0051   }
0052 
0053   /// Make a LWT DNN from the JSON config object
0054   ///
0055   /// @deprecated LWTNN is not under active development any more so Rivet support will be removed in the near future.
0056   /// Convert your neural net to ONNX instead.
0057   std::unique_ptr<lwt::LightweightNeuralNetwork> mkLWTNN(const lwt::JSONConfig& jsonconfig) {
0058     try {
0059       return std::make_unique<lwt::LightweightNeuralNetwork>(jsonconfig.inputs, jsonconfig.layers, jsonconfig.outputs);
0060     } catch (lwt::LightweightNNException &e) {
0061       throw IOError("Error initialising from LWTNN JSON config");
0062     }
0063   }
0064 
0065   /// @brief Make a LWT Graph from the JSON config object
0066   ///
0067   /// Note graph here means "not linear" rather than a GNN
0068   /// @deprecated LWTNN is not under active development any more so Rivet support will be removed in the near future.
0069   /// Convert your neural net to ONNX instead.
0070   std::unique_ptr<lwt::LightweightGraph> mkGraphLWTNN(const lwt::GraphConfig& graphconfig) {
0071     try {
0072       return std::make_unique<lwt::LightweightGraph>(graphconfig);
0073     } catch (lwt::LightweightNNException &e) {
0074       throw IOError("Error initialising from LWTNN JSON config");
0075     }
0076   }
0077 
0078 
0079   /// Make a LWT DNN direct from the JSON config path
0080   ///
0081   /// @deprecated LWTNN is not under active development any more so Rivet support will be removed in the near future.
0082   /// Convert your neural net to ONNX instead.
0083   std::unique_ptr<lwt::LightweightNeuralNetwork> mkLWTNN(const string& jsonpath) {
0084     lwt::JSONConfig config = readLWTNNConfig(jsonpath);
0085     return mkLWTNN(config);
0086   }
0087 
0088   /// @brief Make a LWT graph direct from the JSON config path
0089   ///
0090   /// Note graph here means "not linear" rather than a GNN
0091   ///
0092   /// @deprecated LWTNN is not under active development any more so Rivet support will be removed in the near future.
0093   /// Convert your neural net to ONNX instead.
0094   std::unique_ptr<lwt::LightweightGraph> mkGraphLWTNN(const string& jsonpath) {
0095     lwt::GraphConfig config = readLWTNNGraphConfig(jsonpath);
0096     return mkGraphLWTNN(config);
0097   }
0098 
0099 }
0100 
0101 #endif