- 3.0.2 core module.
DerivativesCppadSettings.h
Go to the documentation of this file.
1 /**********************************************************************************************************************
2 This file is part of the Control Toolbox (https://github.com/ethz-adrl/control-toolbox), copyright by ETH Zurich.
3 Licensed under the BSD-2 license (see LICENSE file in main directory)
4 **********************************************************************************************************************/
5 
6 #pragma once
7 
8 #include <iostream>
9 #include <map>
10 #include <boost/property_tree/ptree.hpp>
11 #include <boost/property_tree/info_parser.hpp>
12 
13 namespace ct {
14 namespace core {
15 
16 
23 {
24 public:
25  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
26 
27  typedef enum CompilerType
28  {
29  GCC = 0,
30  CLANG = 1,
32  } Compiler_t;
33 
38  : multiThreading_(false),
39  createForwardZero_(false),
40  createForwardOne_(false),
41  createReverseOne_(false),
42  createReverseTwo_(false),
43  createJacobian_(false),
44  createSparseJacobian_(false),
45  createHessian_(false),
46  createSparseHessian_(false),
47  maxAssignements_(20000),
48  compiler_(GCC),
49  generateSourceCode_(false),
50  useDynamicLibrary_(true)
51  {
52  }
53 
67 
71  void print()
72  {
73  std::cout << "=============================================================" << std::endl;
74  std::cout << "\tCPPAD Derivatives Settings: " << std::endl;
75  std::cout << "=============================================================" << std::endl;
76 
77  if (multiThreading_)
78  std::cout << "Enabling multithreading in JIT lib" << std::endl;
79  if (createForwardZero_)
80  std::cout << "Generating Forward Zero in JIT lib" << std::endl;
81  if (createReverseOne_)
82  std::cout << "Generating Reverse One in JIT lib" << std::endl;
83  if (createReverseTwo_)
84  std::cout << "Generating Reverse Two in JIT lib" << std::endl;
85  if (createJacobian_)
86  std::cout << "Generating Jacobian in JIT lib" << std::endl;
87  if (createSparseJacobian_)
88  std::cout << "Generating Sparse Jacobian in JIT lib" << std::endl;
89  if (createHessian_)
90  std::cout << "Generating Hessian in JIT lib" << std::endl;
91  if (createSparseHessian_)
92  std::cout << "Generating Sparse Hessian in JIT lib" << std::endl;
93 
94  std::cout << "Using " + compilerToString[compiler_] + " to compile the generated derivatives" << std::endl;
95 
96  std::cout << "Max Assignements per generated Function:" << maxAssignements_ << std::endl;
97 
98  if (generateSourceCode_)
99  std::cout << "Generating and saving Source Code" << std::endl;
100 
101  if (useDynamicLibrary_)
102  std::cout << "Creating a dynamic library (*.so will be saved in execution directory)" << std::endl;
103  }
104 
110  bool parametersOk() const { return true; }
111 
119  void load(const std::string& filename, bool verbose = true, const std::string& ns = "solver")
120  {
121  boost::property_tree::ptree pt;
122  boost::property_tree::read_info(filename, pt);
123 
124  multiThreading_ = pt.get<bool>(ns + ".MultiThreading");
125  createForwardZero_ = pt.get<bool>(ns + ".CreateForwardZero");
126  createForwardOne_ = pt.get<bool>(ns + ".CreateForwardOne");
127  createReverseOne_ = pt.get<bool>(ns + ".CreateReverseOne");
128  createReverseTwo_ = pt.get<bool>(ns + ".CreateReverseTwo");
129  createJacobian_ = pt.get<bool>(ns + ".CreateJacobian");
130  createSparseJacobian_ = pt.get<bool>(ns + ".CreateSparseJacobian");
131  createHessian_ = pt.get<bool>(ns + ".CreateHessian");
132  createSparseHessian_ = pt.get<bool>(ns + ".CreateSparseHessian");
133  maxAssignements_ = pt.get<unsigned int>(ns + ".MaxAssignements");
134  generateSourceCode_ = pt.get<bool>(ns + ".GenerateSourceCode");
135  useDynamicLibrary_ = pt.get<bool>(ns + ".UseDynamicLibrary");
136 
137  std::string compilerStr = pt.get<std::string>(ns + ".Compiler");
138 
139  if (stringTocompiler.find(compilerStr) != stringTocompiler.end())
140  compiler_ = stringTocompiler[compilerStr];
141  else
142  {
143  std::cout << "Invalid compiler specified in config, should be one of the following:" << std::endl;
144 
145  for (auto it = stringTocompiler.begin(); it != stringTocompiler.end(); it++)
146  std::cout << it->first << std::endl;
147  }
148 
149  if (verbose)
150  {
151  std::cout << "Loaded Derivatives CPPAD settings from " << filename << ": " << std::endl;
152  print();
153  }
154  }
155 
156 private:
157  std::map<CompilerType, std::string> compilerToString = {{GCC, "GCC"}, {CLANG, "CLANG"}};
158  std::map<std::string, CompilerType> stringTocompiler = {{"GCC", GCC}, {"CLANG", CLANG}};
159 };
160 
161 
162 } // namespace core
163 } // namespace ct
bool createSparseJacobian_
Definition: DerivativesCppadSettings.h:60
bool multiThreading_
Definition: DerivativesCppadSettings.h:54
bool createSparseHessian_
Definition: DerivativesCppadSettings.h:62
bool createReverseTwo_
Definition: DerivativesCppadSettings.h:58
CompilerType compiler_
Definition: DerivativesCppadSettings.h:64
DerivativesCppadSettings()
Default constructor, set default settings.
Definition: DerivativesCppadSettings.h:37
Definition: DerivativesCppadSettings.h:29
bool generateSourceCode_
Definition: DerivativesCppadSettings.h:65
Definition: DerivativesCppadSettings.h:31
bool createReverseOne_
Definition: DerivativesCppadSettings.h:57
Definition: DerivativesCppadSettings.h:30
bool createJacobian_
Definition: DerivativesCppadSettings.h:59
void load(const std::string &filename, bool verbose=true, const std::string &ns="solver")
Loads the settings from a .info file.
Definition: DerivativesCppadSettings.h:119
bool parametersOk() const
Checks whether to settings are filled with meaningful values.
Definition: DerivativesCppadSettings.h:110
const bool verbose
Definition: JacobianCGTest.h:19
bool createHessian_
Definition: DerivativesCppadSettings.h:61
EIGEN_MAKE_ALIGNED_OPERATOR_NEW enum ct::core::DerivativesCppadSettings::CompilerType Compiler_t
bool createForwardZero_
Definition: DerivativesCppadSettings.h:55
Contains the NLP solver settings.
Definition: DerivativesCppadSettings.h:22
bool useDynamicLibrary_
Definition: DerivativesCppadSettings.h:66
bool createForwardOne_
Definition: DerivativesCppadSettings.h:56
CompilerType
Definition: DerivativesCppadSettings.h:27
size_t maxAssignements_
Definition: DerivativesCppadSettings.h:63
void print()
Prints out settings.
Definition: DerivativesCppadSettings.h:71