Skip to content

Commit

Permalink
issue #1959: nlpsol verbose output colouring information
Browse files Browse the repository at this point in the history
  • Loading branch information
Joris Gillis committed Apr 3, 2018
1 parent d4a8eb0 commit 99baddd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 8 additions & 2 deletions casadi/core/factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ namespace casadi {
std::vector<HBlock> hess_;

// Constructor
Factory(const Function::AuxOut& aux) : aux_(aux) {}
Factory(const Function::AuxOut& aux, bool verbose=false) : aux_(aux), verbose_(verbose) {}

// Add an input expression
void add_input(const std::string& s, const MatType& e);
Expand Down Expand Up @@ -130,6 +130,8 @@ namespace casadi {
// Get output scheme
std::vector<std::string> name_out() const;

// Verbose?
bool verbose_;
};

template<typename MatType>
Expand Down Expand Up @@ -246,6 +248,8 @@ namespace casadi {
void Factory<MatType>::calculate() {
using namespace std;

Dict all_opts = {{"verbose", verbose_}};

// Dual variables
for (auto&& e : out_) {
in_["lam:" + e.first] = MatType::sym("lam_" + e.first, e.second.sparsity());
Expand All @@ -269,6 +273,7 @@ namespace casadi {
}
// Calculate directional derivatives
Dict opts = {{"always_inline", true}};
opts["verbose"] = verbose_;
try {
sens = forward(res, arg, seed, opts);
} catch (exception& e) {
Expand Down Expand Up @@ -298,6 +303,7 @@ namespace casadi {
}
// Calculate directional derivatives
Dict opts = {{"always_inline", true}};
opts["verbose"] = verbose_;
try {
sens = reverse(res, arg, seed, opts);
} catch (exception& e) {
Expand All @@ -324,7 +330,7 @@ namespace casadi {
const MatType& ex = out_.at(b.ex);
const MatType& arg = in_.at(b.arg);
try {
out_["jac:" + b.ex + ":" + b.arg] = MatType::jacobian(ex, arg);
out_["jac:" + b.ex + ":" + b.arg] = MatType::jacobian(ex, arg, all_opts);
} catch (exception& e) {
casadi_error("Jacobian generation failed:\n" + str(e.what()));
}
Expand Down
6 changes: 5 additions & 1 deletion casadi/core/x_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1003,8 +1003,12 @@ namespace casadi {
const Dict& opts) const {
using namespace std;

auto it = opts.find("verbose");
bool verbose = false;
if (it!=opts.end()) verbose = it->second;

// Create an expression factory
Factory<MatType> f(aux);
Factory<MatType> f(aux, verbose);
for (casadi_int i=0; i<in_.size(); ++i) f.add_input(name_in_[i], in_[i]);
for (casadi_int i=0; i<out_.size(); ++i) f.add_output(name_out_[i], out_[i]);

Expand Down

3 comments on commit 99baddd

@jgillis
Copy link
Member

@jgillis jgillis commented on 99baddd Apr 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jaeandersson is this an okay commit, or an ugly symptom of a needed option passing overhaul?

@jaeandersson
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's harmless. A way of passing options more generally might be useful, but this is better than nothing.

@jgillis
Copy link
Member

@jgillis jgillis commented on 99baddd May 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's more options that may need to get passed. LIke enable_forward and siblings..

Please sign in to comment.