Commit 12fd285b authored by Alejandro Mota's avatar Alejandro Mota
Browse files

ROL: Add MiniTensor interface for optimization problems with bound and

equality constraints.

Intrepid2 MiniTensor: Slight refactor of equality constraint interface
to prepare to accommodate an inequality constraint as in ROL. Propagate
changes to ROL.

Build/Test Cases Summary
Enabled Packages: Intrepid2, ROL
Enabled all Forward Packages
0) MPI_DEBUG => Skipped configure, build, test due to no enabled packages! => Does not affect push readiness! (-1.00 min)
1) SERIAL_RELEASE => Skipped configure, build, test due to no enabled packages! => Does not affect push readiness! (-1.00 min)
2) SERIAL_RELEASE_ST => passed: passed=243,notpassed=0 (20.90 min)
parent 4421dcba
......@@ -943,7 +943,7 @@ public:
// Identity
//
template<typename S, Index NC, Index NV>
class Identity : public Constraint_Base<Identity<S, NC, NV>, S, NC, NV>
class Identity : public Equality_Constraint<Identity<S, NC, NV>, S, NC, NV>
{
public:
......@@ -953,7 +953,7 @@ public:
char const * const
NAME{"Identity Map"};
using Base = Constraint_Base<Identity<S, NC, NV>, S, NC, NV>;
using Base = Equality_Constraint<Identity<S, NC, NV>, S, NC, NV>;
// Explicit value.
template<typename T, Index N>
......@@ -977,7 +977,7 @@ public:
// A nonlinear function
//
template<typename S, Index NC = 3, Index NV = 5>
class Nonlinear01 : public Constraint_Base<Nonlinear01<S, NC, NV>, S, NC, NV>
class Nonlinear01 : public Equality_Constraint<Nonlinear01<S, NC, NV>, S, NC, NV>
{
public:
......@@ -987,7 +987,7 @@ public:
char const * const
NAME{"Nonlinear map 01"};
using Base = Constraint_Base<Nonlinear01<S, NC, NV>, S, NC, NV>;
using Base = Equality_Constraint<Nonlinear01<S, NC, NV>, S, NC, NV>;
// Explicit value.
template<typename T, Index N = 5>
......@@ -1021,7 +1021,7 @@ public:
// Circumference feasible region
//
template<typename S, Index NC = 1, Index NV = 2>
class Circumference : public Constraint_Base<Circumference<S, NC, NV>, S, NC, NV>
class Circumference : public Equality_Constraint<Circumference<S, NC, NV>, S, NC, NV>
{
public:
......@@ -1035,7 +1035,7 @@ public:
char const * const
NAME{"Nonlinear map 01"};
using Base = Constraint_Base<Circumference<S, NC, NV>, S, NC, NV>;
using Base = Equality_Constraint<Circumference<S, NC, NV>, S, NC, NV>;
// Explicit value.
template<typename T, Index N = 5>
......
......@@ -108,13 +108,13 @@ public:
};
///
/// Constraint base class that defines the interface to Mini Solvers.
/// Equality constraint base class that defines the interface to Mini Solvers.
///
template<typename ConstraintDerived, typename S, Index NC, Index NV>
struct Constraint_Base
struct Equality_Constraint
{
public:
Constraint_Base()
Equality_Constraint()
{
}
......
......@@ -151,7 +151,7 @@ hessian(FunctionDerived & f, Vector<T, N> const & x)
template<typename ConstraintDerived, typename S, Index NC, Index NV>
template<typename T, Index N>
Vector<T, NC>
Constraint_Base<ConstraintDerived, S, NC, NV>::
Equality_Constraint<ConstraintDerived, S, NC, NV>::
value(ConstraintDerived & c, Vector<T, N> const & x)
{
assert(x.get_dimension() == NUM_VAR);
......@@ -164,7 +164,7 @@ value(ConstraintDerived & c, Vector<T, N> const & x)
template<typename ConstraintDerived, typename S, Index NC, Index NV>
template<typename T, Index N>
Matrix<T, NC, NV>
Constraint_Base<ConstraintDerived, S, NC, NV>::
Equality_Constraint<ConstraintDerived, S, NC, NV>::
gradient(ConstraintDerived & c, Vector<T, N> const & x)
{
using AD = FAD<T, N>;
......
......@@ -88,6 +88,17 @@ public:
Intrepid2::Vector<T, N> & soln,
Intrepid2::Vector<T, NC> & cv);
template<typename FN, typename EC, typename BC, Index NC>
void
solve(
std::string const & algoname,
Teuchos::ParameterList & params,
FN & fn,
EC & ec,
BC & bc,
Intrepid2::Vector<T, N> & soln,
Intrepid2::Vector<T, NC> & cv);
void
printReport(std::ostream & os);
......
......@@ -155,9 +155,9 @@ solve(
MiniTensorVector<T, N>
hi(bc.upper);
// Define constraint
// Define bound constraint
ROL::MiniTensor_BoundConstraint<T, N>
constr(lo, hi);
bound_constr(lo, hi);
ROL::Algorithm<T>
algo(algoname, params);
......@@ -167,7 +167,7 @@ solve(
x(soln);
// Run Algorithm
algo.run(x, obj, constr, verbose);
algo.run(x, obj, bound_constr, verbose);
soln = ROL::MTfromROL<T, N>(x);
......@@ -190,7 +190,6 @@ solve(
return;
}
//
//
//
......@@ -224,7 +223,7 @@ solve(
// Define constraint
ROL::MiniTensor_EqualityConstraint<EC, T, NC, N>
constr(ec);
eq_constr(ec);
ROL::Algorithm<T>
algo(algoname, params);
......@@ -238,7 +237,7 @@ solve(
c(cv);
// Run Algorithm
algo.run(x, c, obj, constr, verbose);
algo.run(x, c, obj, eq_constr, verbose);
soln = ROL::MTfromROL<T, N>(x);
......@@ -262,7 +261,87 @@ solve(
return;
}
//
//
//
template<typename T, Index N>
template<typename FN, typename EC, typename BC, Index NC>
void
MiniTensor_Minimizer<T, N>::
solve(
std::string const & algoname,
Teuchos::ParameterList & params,
FN & fn,
EC & ec,
BC & bc,
Intrepid2::Vector<T, N> & soln,
Intrepid2::Vector<T, NC> & cv)
{
step_method_name = algoname.c_str();
function_name = FN::NAME;
initial_guess = soln;
Intrepid2::Vector<T, N>
resi = fn.gradient(soln);
initial_value = fn.value(soln);
previous_value = initial_value;
failed = failed || fn.failed;
initial_norm = Intrepid2::norm(resi);
// Define algorithm.
ROL::MiniTensor_Objective<FN, T, N>
obj(fn);
MiniTensorVector<T, N>
lo(bc.lower);
MiniTensorVector<T, N>
hi(bc.upper);
// Define bound constraint
ROL::MiniTensor_BoundConstraint<T, N>
bound_constr(lo, hi);
// Define equality constraint
ROL::MiniTensor_EqualityConstraint<EC, T, NC, N>
eq_constr(ec);
ROL::Algorithm<T>
algo(algoname, params);
// Set Initial Guess
ROL::MiniTensorVector<T, N>
x(soln);
// Set constraint vector
ROL::MiniTensorVector<T, NC>
c(cv);
// Run Algorithm
algo.run(x, c, obj, eq_constr, bound_constr, verbose);
soln = ROL::MTfromROL<T, N>(x);
resi = fn.gradient(soln);
T const
norm_resi = Intrepid2::norm(resi);
updateConvergenceCriterion(norm_resi);
ROL::AlgorithmState<T> &
state = const_cast<ROL::AlgorithmState<T> &>(*(algo.getState()));
ROL::StatusTest<T>
status(params);
converged = status.check(state) == false;
recordFinals(fn, soln);
return;
}
//
//
//
......
......@@ -160,7 +160,7 @@ TEST(MiniTensor_ROL, Paraboloid_EqualityConstraint)
// Constraint that defines the feasible region
Intrepid2::Circumference<Real, NUM_CONSTR, NUM_VAR>
constr(r, a, b);
eq_constr(r, a, b);
// Define algorithm.
std::string const
......@@ -171,22 +171,24 @@ TEST(MiniTensor_ROL, Paraboloid_EqualityConstraint)
params;
params.sublist("Step").sublist(algoname).
sublist("Optimality System Solver").set("Nominal Relative Tolerance",1.e-8);
sublist("Optimality System Solver").set(
"Nominal Relative Tolerance",
1.e-8);
params.sublist("Step").sublist(algoname).
sublist("Optimality System Solver").set("Fix Tolerance",true);
sublist("Optimality System Solver").set("Fix Tolerance", true);
params.sublist("Step").sublist(algoname).
sublist("Tangential Subproblem Solver").set("Iteration Limit",128);
sublist("Tangential Subproblem Solver").set("Iteration Limit", 128);
params.sublist("Step").sublist(algoname).
sublist("Tangential Subproblem Solver").set("Relative Tolerance",1e-6);
sublist("Tangential Subproblem Solver").set("Relative Tolerance", 1e-6);
params.sublist("Step").sublist(algoname).set("Output Level",0);
params.sublist("Status Test").set("Gradient Tolerance",1.e-12);
params.sublist("Status Test").set("Constraint Tolerance",1.e-12);
params.sublist("Status Test").set("Step Tolerance",1.e-18);
params.sublist("Status Test").set("Iteration Limit",128);
params.sublist("Step").sublist(algoname).set("Output Level", 0);
params.sublist("Status Test").set("Gradient Tolerance", 1.0e-12);
params.sublist("Status Test").set("Constraint Tolerance", 1.0e-12);
params.sublist("Status Test").set("Step Tolerance", 1.0e-18);
params.sublist("Status Test").set("Iteration Limit", 128);
// Set initial guess
Intrepid2::Vector<Real, NUM_VAR>
......@@ -199,7 +201,7 @@ TEST(MiniTensor_ROL, Paraboloid_EqualityConstraint)
ROL::MiniTensor_Minimizer<Real, NUM_VAR>
minimizer;
minimizer.solve(algoname, params, fn, constr, x, c);
minimizer.solve(algoname, params, fn, eq_constr, x, c);
minimizer.printReport(os);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment