trilinos / Trilinos

Primary repository for the Trilinos Project
https://trilinos.org/
Other
1.22k stars 568 forks source link

ROL: adding an inequality constraint #9659

Closed Adrian-Diaz closed 2 years ago

Adrian-Diaz commented 3 years ago

Question

@trilinos/rol

Greetings,

I've been trying to add an inequality constraint to my optimization problem, c(x) < A, but it seems that the bounds I set are not being enforced by ROL since the values of c(x) far exceed the bounds I'm trying to set. The code I used to add the constrain to the problem is the following:

ROL::Ptr<std::vector > li_ptr = ROL::makePtr<std::vector>(1,0.0); ROL::Ptr<std::vector > ll_ptr = ROL::makePtr<std::vector>(1,0.0); ROL::Ptr<std::vector > lu_ptr = ROL::makePtr<std::vector>(1,simparam->maximum_strain_energy);

ROL::Ptr<ROL::Vector > constraint_mul = ROL::makePtr<ROL::StdVector>(li_ptr); ROL::Ptr<ROL::Vector > ll = ROL::makePtr<ROL::StdVector>(ll_ptr); ROL::Ptr<ROL::Vector > lu = ROL::makePtr<ROL::StdVector>(lu_ptr);

ROL::Ptr<ROL::Constraint> ineq_constraint = ROL::makePtr(this, nodal_density_flag, simparam->maximum_strain_energy); ROL::Ptr<ROL::BoundConstraint> constraint_bnd = ROL::makePtr<ROL::Bounds>(ll,lu); problem->addConstraint("Inequality Constraint",ineq_constraint,constraint_mul,constraint_bnd);

Where the constrain value function is as follows:

void value(ROL::Vector &c, const ROL::Vector &z, real_t &tol ) {

ROL::Ptr<std::vector<real_t>> cp = dynamic_cast<ROL::StdVector<real_t>&>(c).getVector();
//communicate ghosts and solve for nodal degrees of freedom as a function of the current design variables
if(last_comm_step!=current_step){
  FEM_->update_and_comm_variables();
  last_comm_step = current_step;
}

ROL_Force = ROL::makePtr<ROL_MV>(FEM_->Global_Nodal_Forces);
ROL_Displacements = ROL::makePtr<ROL_MV>(FEM_->node_displacements_distributed);

real_t current_strain_energy = ROL_Displacements->dot(*ROL_Force);
std::cout << "CURRENT STRAIN ENERGY " << current_strain_energy << std::endl;
(*cp)[0] = current_strain_energy;

}

Thanks for any help rendered.

Adrian-Diaz commented 3 years ago

@dridzal

Adrian-Diaz commented 3 years ago

To add to this, I can't make it call the child's applyJacobian routine for some reason. It keeps printing out as if its evaluating value many times to try and numerically evaluate the constraint jacobian instead. I implemented it as follows:

void applyJacobian(ROL::Vector &jv, const ROL::Vector &v, const ROL::Vector &x, real_t &tol) { //communicate ghosts and solve for nodal degrees of freedom as a function of the current design variables if(last_comm_step!=currentstep){ FEM->update_and_comm_variables(); last_comm_step = current_step; } //get Tpetra multivector pointer from the ROL vector ROL::Ptr zp = getVector(x); ROL::Ptr<std::vector> jvp = dynamic_cast<ROL::StdVector&>(jv).getVector();

//get local view of the data
host_vec_array constraint_gradients = constraint_gradients_distributed->getLocalView<HostSpace> (Tpetra::Access::ReadWrite);
const_host_vec_array design_densities = zp->getLocalView<HostSpace> (Tpetra::Access::ReadOnly);

int rnum_elem = FEM_->rnum_elem;
if(nodal_density_flag_){
  FEM_->compute_adjoint_gradients(design_densities, constraint_gradients);
}
else{
  /*
  //update per element volumes
  FEM_->compute_element_volumes();
  //ROL_Element_Volumes = ROL::makePtr<ROL_MV>(FEM_->Global_Element_Volumes);
  //local view of element volumes
  const_host_vec_array element_volumes = FEM_->Global_Element_Volumes->getLocalView<HostSpace> (Tpetra::Access::ReadOnly);
  for(int ig = 0; ig < rnum_elem; ig++)
    objective_gradients(ig,0) = element_volumes(ig,0);
    */
}
ROL_Gradients = ROL::makePtr<ROL_MV>(constraint_gradients_distributed);
real_t gradient_dot_v = ROL_Gradients->dot(v);
//debug print
std::cout << "Constraint Gradient value " << gradient_dot_v << std::endl;

(*jvp)[0] = gradient_dot_v;

}

jhux2 commented 3 years ago

@trilinos/rol

Adrian-Diaz commented 3 years ago

Update, I figured out it wanted the adjoint Jacobian method. However I still can't seem to make the algorithm stay under the constraint bounds at the moment. As an example, if I set something like 0.5 as an upper bound it'll end up iterating around 0.57 and never leave that.

dridzal commented 3 years ago

@Adrian-Diaz , which algorithm are you using to enforce the constraint? Can you say more about the mathematical properties of the constraint function? For example, is it scalar valued? Is it linear or nonlinear in the optimization variables? Is the feasible set always non-empty? This information may help us recommend a different problem formulation or a different algorithm (my guess is that the algorithm you're using penalizes the constraint rather than enforcing it as a hard constraint). Also adding @dpkouri to the conversation.

Adrian-Diaz commented 3 years ago

Greetings, I've just been using the default solver command I saw in the Version2.0 doc with my problem:

ROL::ParameterList parlist; // Instantiate Solver. ROL::Solver solver(problem,parlist);

The current constraint I'm working with is just a mass computation, linear in the design variables (which are FEA node values for density). The gradient is essentially a fixed vector throughout the run when I print it (as it should be).

Thanks for the help.

dridzal commented 3 years ago

You may want to try adding the constraint as a linear constraint, as described here

https://github.com/trilinos/Trilinos/blob/master/packages/rol/Version-2.0.md

specifically the block

    // TypeB (bound constrained) specification
    ROL::Ptr<ROL::BoundConstraint<double>> bnd = ROL::makePtr<MyBoundConstraint<double>>();
    problem.addBoundConstraint(bnd)    
    // TypeB can now handle polyhedral constraints specified by
    // a bound constraint and linear equality/inequality constraints.
    // If a linear equality/inequality constraint is added to the problem,
    // the TypeB problem will create a PolyhedralProjection object to
    // handle the linear constraints.
    ROL::Ptr<ROL::Constraint<double>>     lin_icon = ROL::makePtr<MyLinearInequalityConstraint<double>>();
    ROL::Ptr<ROL::Vector<double>>         lin_imul = ROL::makePtr<MyLinearInequalityConstraintMultiplier<double>>();
    ROL::Ptr<ROL:BoundConstraint<double>> lin_ibnd = ROL::makePtr<MyLinearInequalityConstraintBound<double>>();
    problem.addLinearConstraint("Linear Inequality Constraint",lin_icon,lin_imul,lin_ibnd);

@dpkouri developed this capability and has recently used it to solve topology optimization problems with great success (combined with the Lin-More algorithm with polyhedral projections). @dpkouri , please chime in.

dridzal commented 3 years ago

Another note: It may make sense to enforce the constraint as an equality constraint (clearly, this depends on the application). This can sometimes result in faster convergence of the algorithm. In other words, use addLinearConstraint and set it as an equality constraint.

Adrian-Diaz commented 3 years ago

How does one force the solver object to adhere to a specific algorithm? Also I got the following shell output when using addLinearConstraint with the default solve object with both equality and inequality constraint versions of the mass.

ROL::Problem::finalize Problem Summary: Has Bound Constraint? .............. yes Has Equality Constraint? ........... no Has Inequality Constraint? ......... no Has Linear Equality Constraint? .... yes Names: ........................... Equality Constraint Total: ........................... 1 Has Linear Inequality Constraint? .. no

ROL::PolyhedralProjection::project : Projection may be inaccurate! rnorm = 3.69504 rtol = 1.81899e-12 CURRENT STRAIN ENERGY 3.020895419 ROL::PolyhedralProjection::project : Projection may be inaccurate! rnorm = 3.695041723 rtol = 1.818989404e-12

RUNTIME OF CODE ON TASK 0 is 0.171875

Adrian-Diaz commented 3 years ago

The resulting design variables for that attempt were just all set to my lower bound constraint (which is 10% of the initial mass rather than 50% mass as desired).

dridzal commented 3 years ago

Take a look at:

https://github.com/trilinos/Trilinos/blob/master/packages/rol/example/PDE-OPT/topo-opt/elasticity/input_ex01.xml

Note that this input file contains problem-specific parameters and ROL parameters. The latter start with the 'General' list. There is a section in ROL's 'General' input section that pertains to the projections. For a scalar-valued constraint, the Dai-Fletcher option should work well. Your output should include the type of algorithm you're running by default. What is it? In any case, for this problem it should be Truncated CG / Lin-More and the polyhedral projection should be set in the code using a call like problem->setProjectionAlgorithm(*parlist);

Adrian-Diaz commented 3 years ago

I'll give that a try. Regarding output it doesn't print the algorithm. I'm guessing that information would come from the solver object somehow but using ROL::Solver solver(problem,parlist) hasn't printed that.

dridzal commented 3 years ago

Solver's solve() method takes an output stream as an input.

Adrian-Diaz commented 3 years ago

I set it to std::cout as I did with problem->finalize(false,true,std::cout) but I haven't seen anything other than the problem summary to date in the shell.

dridzal commented 3 years ago

What's your 'Output Level' in the input xml file ('General' section)?

Adrian-Diaz commented 3 years ago

I hadn't set that variable, I've only tried the default parameter list object and another xml file from the topology optimization example that didn't have that option set. Using the recommended xml file with the output level command has it printing:

Augmented Lagrangian Solver (Type G, General Constraints) Subproblem Solver: Trust Region iter fval cnorm gLnorm snorm penalty feasTol optTol #fval #grad #cval subIter 0 3.020895e-01 5.000000e-01 1.079563e+00 --- 1.00e+01 1.26e-01 1.08e-02 1 1 1 ---

Adrian-Diaz commented 3 years ago

I used problem->addLinearConstraint("Equality Constraint",eq_constraint,constraint_mul); problem->setProjectionAlgorithm(*parlist); //finalize problem problem->finalize(false,true,std::cout);

// Instantiate Solver. ROL::Solver solver(problem,*parlist);

// Solve optimization problem. //std::ostream outStream; solver.solve(std::cout);

using the recommended xml file (havn't changed anything in it yet since it looked like the named algorithms were set) which gave me the result with all the design variables at the upper bound now instead. The shell output was:

ROL::Problem::finalize Problem Summary: Has Bound Constraint? .............. yes Has Equality Constraint? ........... no Has Inequality Constraint? ......... no Has Linear Equality Constraint? .... yes Names: ........................... Equality Constraint Total: ........................... 1 Has Linear Inequality Constraint? .. no

ROL::PolyhedralProjection::project : Projection may be inaccurate! rnorm = 1.5 rtol = 1.81899e-12 CURRENT STRAIN ENERGY 0.3020895419 ROL::PolyhedralProjection::project : Projection may be inaccurate! rnorm = 1.5 rtol = 1.818989404e-12 Constraint Gradient value

Lin-More Trust-Region Method (Type B, Bound Constraints) iter value gnorm snorm delta #fval #grad #hess #proj tr_flag iterCG flagCG 0 3.020895e-01 0.000000e+00 --- 2.000000e+01 1 1 0 2 --- --- --- Optimization Terminated with Status: Converged

Adrian-Diaz commented 3 years ago

Linear Constraints aside, I will need to be able to enforce the constraint limit with non-linear cases as well. How would I force it to comply with that? I tried just updating the penalty parameter in the file but then it seems to go on forever even for a very small model.

dridzal commented 3 years ago

Have you implemented derivatives? Have you checked them using problem->check()? See

https://github.com/trilinos/Trilinos/blob/master/packages/rol/example/PDE-OPT/topo-opt/elasticity/example_01.cpp

for how the entire infrastructure is used in a mini application.

It looks like the polyhedral projection algorithm isn't working at all on your linear constraint. This is very unusual. Note that the projected gradient norm gnorm is reported as zero, which would normally mean that the method has converged. However, with the projection failure, this doesn't mean much.

I would focus on checking all derivatives and making sure that the linear constraint is implemented correctly. As far as I understand, your constraint is simply sum_i (c_i * x_i) = M, so checking the weights c_i on a small example shouldn't be difficult.

Nonlinear constraints will require going back to the Augmented Lagrangian method. We have a few other options available. Having said that, you should get Lin-More with polyhedral projections working on the linearly constrained problem first. It looks like there is a problem with the constraint implementation, so any lessons learned may be useful for the nonlinear case.

Adrian-Diaz commented 3 years ago

So far it looks like the constraint gradient has what it should when I printed on the augmented lagrangian runs. In that case gnorm was non-zero, I also just use the describe on the tpetra vector to see the values through iterations (It just prints the c_i over and over as expected). What I'm not too sure about is whether it needs applyjacobian as well for the polyhedral projection. So far I just implemented value and applyAdjointJacobian as follows:

void applyAdjointJacobian(ROL::Vector &ajv, const ROL::Vector &v, const ROL::Vector &x, real_t &tol) override { //get Tpetra multivector pointer from the ROL vector ROL::Ptr zp = getVector(x); ROL::Ptr<const std::vector> vp = dynamic_cast<const ROL::StdVector&>(v).getVector(); ROL::Ptr ajvp = getVector(ajv);

//ROL::Ptr<ROL_MV> ROL_Element_Volumes;

//get local view of the data
const_host_vec_array design_densities = zp->getLocalView<HostSpace> (Tpetra::Access::ReadOnly);
//host_vec_array constraint_gradients = constraint_gradients_distributed->getLocalView<HostSpace> (Tpetra::Access::ReadWrite);
host_vec_array constraint_gradients = ajvp->getLocalView<HostSpace> (Tpetra::Access::ReadWrite);
//host_vec_array dual_constraint_vector = vp->getLocalView<HostSpace> (Tpetra::Access::ReadOnly);

//communicate ghosts and solve for nodal degrees of freedom as a function of the current design variables
if(last_comm_step!=current_step){
  FEM_->update_and_comm_variables();
  last_comm_step = current_step;
}

int rnum_elem = FEM_->rnum_elem;

if(nodal_density_flag_){
  FEM_->compute_nodal_gradients(design_densities, constraint_gradients);
  //debug print of gradient
  //std::ostream &out = std::cout;
  //Teuchos::RCP<Teuchos::FancyOStream> fos = Teuchos::fancyOStream(Teuchos::rcpFromRef(out));
  //if(FEM_->myrank==0)
  //*fos << "Gradient data :" << std::endl;
  //ajvp->describe(*fos,Teuchos::VERB_EXTREME);
  //*fos << std::endl;
  //std::fflush(stdout);
  for(int i = 0; i < FEM_->nlocal_nodes; i++){
    constraint_gradients(i,0) *= (*vp)[0]/initial_mass;
  }
}
dridzal commented 3 years ago

Please run problem->check(), making sure that you supply the proper arguments. It should tell us if there are inconsistencies. I would implement all methods. @dpkouri , what do the polyhedral projection algorithms use from the constraint implementation?

dpkouri commented 3 years ago

The polyhedral projection will compute and store the adjoint constraint Jacobian as well as the constraint value at x=0, assuming the range of the constraint is one dimensional.

dridzal commented 3 years ago

@dpkouri , so which method must be implemented when the constraint range is one-dimensional?

dpkouri commented 3 years ago

@dridzal As my previous post stated, you need the "adjoint constraint Jacobian" and the "constraint value".

Adrian-Diaz commented 3 years ago

The output from problem->check:

Check primal optimization space vector

** Begin verification of linear algebra. *****

Commutativity of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Associativity of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 1.110223024625e-16 Identity element of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Inverse elements of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Identity element of scalar multiplication. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Consistency of scalar multiplication with field multiplication. Consistency error: >>>>>>>>>>> 0.000000000000e+00 Distributivity of scalar multiplication with respect to field addition. Consistency error: >>> 0.000000000000e+00 Distributivity of scalar multiplication with respect to vector addition. Consistency error: >> 4.578749955050e-16 Commutativity of dot (inner) product over the field of reals. Consistency error: >>>>>>>>>>>>> 0.000000000000e+00 Additivity of dot (inner) product. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 1.946797305985e-16 Consistency of scalar multiplication and norm. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>> 2.220446049250e-16 Reflexivity. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Consistency of apply and dual:>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00

** End verification of linear algebra. ***

Check dual optimization space vector

** Begin verification of linear algebra. *****

Commutativity of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Associativity of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Identity element of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Inverse elements of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Identity element of scalar multiplication. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Consistency of scalar multiplication with field multiplication. Consistency error: >>>>>>>>>>> 0.000000000000e+00 Distributivity of scalar multiplication with respect to field addition. Consistency error: >>> 0.000000000000e+00 Distributivity of scalar multiplication with respect to vector addition. Consistency error: >> 0.000000000000e+00 Commutativity of dot (inner) product over the field of reals. Consistency error: >>>>>>>>>>>>> 0.000000000000e+00 Additivity of dot (inner) product. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Consistency of scalar multiplication and norm. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Reflexivity. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Consistency of apply and dual:>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00

** End verification of linear algebra. ***

Equality Constraint: Check primal linear constraint space vector

** Begin verification of linear algebra. *****

Commutativity of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Associativity of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Identity element of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Inverse elements of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Identity element of scalar multiplication. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Consistency of scalar multiplication with field multiplication. Consistency error: >>>>>>>>>>> 0.000000000000e+00 Distributivity of scalar multiplication with respect to field addition. Consistency error: >>> 0.000000000000e+00 Distributivity of scalar multiplication with respect to vector addition. Consistency error: >> 0.000000000000e+00 Commutativity of dot (inner) product over the field of reals. Consistency error: >>>>>>>>>>>>> 0.000000000000e+00 Additivity of dot (inner) product. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Consistency of scalar multiplication and norm. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Reflexivity. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Consistency of apply and dual:>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00

** End verification of linear algebra. ***

Equality Constraint: Check dual linear constraint space vector

** Begin verification of linear algebra. *****

Commutativity of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Associativity of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Identity element of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Inverse elements of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Identity element of scalar multiplication. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Consistency of scalar multiplication with field multiplication. Consistency error: >>>>>>>>>>> 0.000000000000e+00 Distributivity of scalar multiplication with respect to field addition. Consistency error: >>> 0.000000000000e+00 Distributivity of scalar multiplication with respect to vector addition. Consistency error: >> 0.000000000000e+00 Commutativity of dot (inner) product over the field of reals. Consistency error: >>>>>>>>>>>>> 0.000000000000e+00 Additivity of dot (inner) product. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Consistency of scalar multiplication and norm. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Reflexivity. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Consistency of apply and dual:>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00

** End verification of linear algebra. ***

ROL::Problem::checkLinearity Constraint Equality Constraint: ||c(x+alphay) - (c(x)+alpha(c(y)-c(0)))|| = 0.00000000e+00

Check objective function

       Step size           grad'*dir           FD approx           abs error
       ---------           ---------           ---------           ---------

1.00000000000e+00 -1.82214061754e-02 0.00000000000e+00 1.82214061754e-02 1.00000000000e-01 -1.82214061754e-02 0.00000000000e+00 1.82214061754e-02 1.00000000000e-02 -1.82214061754e-02 0.00000000000e+00 1.82214061754e-02 1.00000000000e-03 -1.82214061754e-02 0.00000000000e+00 1.82214061754e-02 1.00000000000e-04 -1.82214061754e-02 0.00000000000e+00 1.82214061754e-02 1.00000000000e-05 -1.82214061754e-02 0.00000000000e+00 1.82214061754e-02 1.00000000000e-06 -1.82214061754e-02 0.00000000000e+00 1.82214061754e-02 1.00000000000e-07 -1.82214061754e-02 0.00000000000e+00 1.82214061754e-02 1.00000000000e-08 -1.82214061754e-02 0.00000000000e+00 1.82214061754e-02 1.00000000000e-09 -1.82214061754e-02 0.00000000000e+00 1.82214061754e-02 1.00000000000e-10 -1.82214061754e-02 0.00000000000e+00 1.82214061754e-02 1.00000000000e-11 -1.82214061754e-02 0.00000000000e+00 1.82214061754e-02 1.00000000000e-12 -1.82214061754e-02 0.00000000000e+00 1.82214061754e-02 Step size norm(Hess*vec) norm(FD approx) norm(abs error)


1.00000000000e+00 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-01 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-02 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-03 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-04 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-05 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-06 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-07 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-08 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-09 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-10 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-11 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-12 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 <w, H(x)v> <v, H(x)w> abs error 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00

Equality Constraint: Check constraint function

       Step size       norm(Jac*vec)     norm(FD approx)     norm(abs error)
       ---------       -------------     ---------------     ---------------

1.00000000000e+00 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-01 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-02 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-03 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-04 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-05 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-06 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-07 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-08 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-09 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-10 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-11 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-12 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00

Test Consistency of Jacobian and its adjoint: <w,Jv> - <adj(J)w,v> = 4.79333812e-03 <w,Jv> = 0.00000000e+00 Relative Error = 2.15423776e+305 Step size norm(adj(H)(u,v)) norm(FD approx) norm(abs error)

1.00000000000e+00 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-01 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-02 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-03 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-04 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-05 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-06 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-07 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-08 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-09 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-10 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-11 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-12 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00

ROL::PolyhedralProjection::project : Projection may be inaccurate! rnorm = 1.5 rtol = 1.8189894e-12 ROL::PolyhedralProjection::project : Projection may be inaccurate! rnorm = 1.5 rtol = 1.818989404e-12

Lin-More Trust-Region Method (Type B, Bound Constraints) iter value gnorm snorm delta #fval #grad #hess #proj tr_flag iterCG flagCG
0 3.020895e-01 0.000000e+00 --- 2.000000e+01 1 1 0 2 --- --- ---
Optimization Terminated with Status: Converged

dridzal commented 3 years ago

@Adrian-Diaz it looks like your objective value() is implemented as constant. Is that what you want? Also, the constraint value appears to be constant. Note that the constraint value, in the above notation, is (sum_i (c_i*x_i)) - M, because the complete constraint equation is (sum_i (c_i*x_i)) - M = 0.

dpkouri commented 3 years ago

@Adrian-Diaz We should point out that the finite difference checks perform the following operations:

Objective Function: |f(x+th) - f(x) - t< f'(x), h>| / t || f'(x+th) - f'(x) - t f''(x)h || / t where x and h are random vectors and t is a positive constant that is reduced from 1 down to 1e-12. The checks perform similar computations for the constraint. If the derivatives are implemented properly, then the final column should be nonzero and decay until the precision limit is met, after which the error typically increases.

Adrian-Diaz commented 3 years ago

Not sure what constant means in this context, the value is definitely changing with the densities; I've printed out the value history for the augmented Lagrangian runs and seen it change. The return value for my constraint is (*cp)[0] = current_mass/initial_mass - constraintvalue and I've also seen current_mass change in those runs.

Adrian-Diaz commented 3 years ago

This is the value function:

real_t value(const ROL::Vector &z, real_t &tol) { ROL::Ptr zp = getVector(z); real_t c = 0.0;

const_host_vec_array design_densities = zp->getLocalView<HostSpace> (Tpetra::Access::ReadOnly);
//communicate ghosts and solve for nodal degrees of freedom as a function of the current design variables
if(last_comm_step!=current_step){
  FEM_->update_and_comm_variables();
  last_comm_step = current_step;
}

ROL_Force = ROL::makePtr<ROL_MV>(FEM_->Global_Nodal_Forces);
ROL_Displacements = ROL::makePtr<ROL_MV>(FEM_->node_displacements_distributed);

real_t current_strain_energy = ROL_Displacements->dot(*ROL_Force);
std::cout.precision(10);
//if(FEM_->myrank==0)
//std::cout << "CURRENT STRAIN ENERGY " << current_strain_energy << std::endl;
return current_strain_energy;

}

Does check invoke the update function? the only thing I can think of is the static equilibrium solve is not being called with the updated variable since its enclosed by the update check.

EDIT:Actually turning off the update check in value didn't change the check report.

dridzal commented 3 years ago

Adding to the finite difference comment by @dpkouri : The third column should not be zero. Our checks perturb reference vectors in random directions and compute value(). All value() calls seem to give you the same numbers, because norm(FD approx) computes their differences, and they are all zero (for both the objective and the constraint). This is what I mean by "constant." I was going to mention update() functions as a potential cause, but it sounds like they are not the culprit. I believe that the checks will call updates. Can you print the value of current_strain_energy? These values should be different every time the vector is perturbed in the finite difference check.

Adrian-Diaz commented 3 years ago

I figured out the issue was passing the design vector through to my FEM class. I was using a reference to the vector I passed to the problem but apparently that one is not always the right vector. That's doing a better job with the Augmented Lagrangian, check follows:

ROL::Problem::finalize Problem Summary: Has Bound Constraint? .............. yes Has Equality Constraint? ........... yes Names: ........................... Equality Constraint Total: ........................... 1 Has Inequality Constraint? ......... no Has Linear Equality Constraint? .... no Has Linear Inequality Constraint? .. no

Check primal optimization space vector

** Begin verification of linear algebra. *****

Commutativity of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Associativity of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 1.110223024625e-16 Identity element of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Inverse elements of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Identity element of scalar multiplication. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Consistency of scalar multiplication with field multiplication. Consistency error: >>>>>>>>>>> 0.000000000000e+00 Distributivity of scalar multiplication with respect to field addition. Consistency error: >>> 0.000000000000e+00 Distributivity of scalar multiplication with respect to vector addition. Consistency error: >> 4.578749955050e-16 Commutativity of dot (inner) product over the field of reals. Consistency error: >>>>>>>>>>>>> 0.000000000000e+00 Additivity of dot (inner) product. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 1.946797305985e-16 Consistency of scalar multiplication and norm. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>> 2.220446049250e-16 Reflexivity. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Consistency of apply and dual:>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00

** End verification of linear algebra. ***

Check dual optimization space vector

** Begin verification of linear algebra. *****

Commutativity of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Associativity of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Identity element of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Inverse elements of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Identity element of scalar multiplication. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Consistency of scalar multiplication with field multiplication. Consistency error: >>>>>>>>>>> 0.000000000000e+00 Distributivity of scalar multiplication with respect to field addition. Consistency error: >>> 0.000000000000e+00 Distributivity of scalar multiplication with respect to vector addition. Consistency error: >> 0.000000000000e+00 Commutativity of dot (inner) product over the field of reals. Consistency error: >>>>>>>>>>>>> 0.000000000000e+00 Additivity of dot (inner) product. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Consistency of scalar multiplication and norm. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Reflexivity. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Consistency of apply and dual:>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00

** End verification of linear algebra. ***

Equality Constraint: Check primal constraint space vector

** Begin verification of linear algebra. *****

Commutativity of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Associativity of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Identity element of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Inverse elements of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Identity element of scalar multiplication. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Consistency of scalar multiplication with field multiplication. Consistency error: >>>>>>>>>>> 0.000000000000e+00 Distributivity of scalar multiplication with respect to field addition. Consistency error: >>> 0.000000000000e+00 Distributivity of scalar multiplication with respect to vector addition. Consistency error: >> 0.000000000000e+00 Commutativity of dot (inner) product over the field of reals. Consistency error: >>>>>>>>>>>>> 0.000000000000e+00 Additivity of dot (inner) product. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Consistency of scalar multiplication and norm. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Reflexivity. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Consistency of apply and dual:>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00

** End verification of linear algebra. ***

Equality Constraint: Check dual constraint space vector

** Begin verification of linear algebra. *****

Commutativity of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Associativity of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Identity element of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Inverse elements of addition. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Identity element of scalar multiplication. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Consistency of scalar multiplication with field multiplication. Consistency error: >>>>>>>>>>> 0.000000000000e+00 Distributivity of scalar multiplication with respect to field addition. Consistency error: >>> 0.000000000000e+00 Distributivity of scalar multiplication with respect to vector addition. Consistency error: >> 0.000000000000e+00 Commutativity of dot (inner) product over the field of reals. Consistency error: >>>>>>>>>>>>> 0.000000000000e+00 Additivity of dot (inner) product. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Consistency of scalar multiplication and norm. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Reflexivity. Consistency error: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00 Consistency of apply and dual:>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0.000000000000e+00

** End verification of linear algebra. ***

Check objective function

       Step size           grad'*dir           FD approx           abs error
       ---------           ---------           ---------           ---------

1.00000000000e+00 -2.20649916974e+00 3.07226592487e+01 3.29291584184e+01 1.00000000000e-01 -2.20649916974e+00 -7.31337755045e-01 1.47516141470e+00 1.00000000000e-02 -2.20649916974e+00 -1.42390079191e+00 7.82598377833e-01 1.00000000000e-03 -2.20649916974e+00 -1.63783420312e+00 5.68664966617e-01 1.00000000000e-04 -2.20649916974e+00 -1.66248872378e+00 5.44010445962e-01 1.00000000000e-05 -2.20649916974e+00 -1.66499155019e+00 5.41507619553e-01 1.00000000000e-06 -2.20649916974e+00 -1.66524221493e+00 5.41256954814e-01 1.00000000000e-07 -2.20649916974e+00 -1.66526730461e+00 5.41231865134e-01 1.00000000000e-08 -2.20649916974e+00 -1.66527002743e+00 5.41229142312e-01 1.00000000000e-09 -2.20649916974e+00 -1.66526473167e+00 5.41234438076e-01 1.00000000000e-10 -2.20649916974e+00 -1.66528985046e+00 5.41209319280e-01 1.00000000000e-11 -2.20649916974e+00 -1.66610614194e+00 5.40393027801e-01 1.00000000000e-12 -2.20649916974e+00 -1.67713065657e+00 5.29368513167e-01 Step size norm(Hess*vec) norm(FD approx) norm(abs error)


1.00000000000e+00 8.29577235350e+01 5.49271967407e+05 5.49328502623e+05 1.00000000000e-01 8.29577235350e+01 1.87987916823e+01 6.77611960247e+01 1.00000000000e-02 8.29577235350e+01 6.73927726610e+01 1.56370671237e+01 1.00000000000e-03 8.29577235350e+01 8.11413740701e+01 1.82259757792e+00 1.00000000000e-04 8.29577235350e+01 8.27730295981e+01 1.85309264548e-01 1.00000000000e-05 8.29577235350e+01 8.29392335827e+01 1.85510633956e-02 1.00000000000e-06 8.29577235350e+01 8.29558851632e+01 1.84416298850e-03 1.00000000000e-07 8.29577235350e+01 8.29575520842e+01 1.71832865820e-04 1.00000000000e-08 8.29577235350e+01 8.29577270228e+01 3.90283159739e-06 1.00000000000e-09 8.29577235350e+01 8.29576356088e+01 9.20536540389e-05 1.00000000000e-10 8.29577235350e+01 8.29593734836e+01 1.75735140371e-03 1.00000000000e-11 8.29577235350e+01 8.29928137081e+01 3.54395943785e-02 1.00000000000e-12 8.29577235350e+01 8.33676889751e+01 4.12735515350e-01 <w, H(x)v> <v, H(x)w> abs error 4.01568763185e+01 -3.49349980803e+01 7.50918743987e+01

Equality Constraint: Check constraint function

       Step size       norm(Jac*vec)     norm(FD approx)     norm(abs error)
       ---------       -------------     ---------------     ---------------

1.00000000000e+00 1.16285316646e-01 1.16285315006e-01 1.63963681521e-09 1.00000000000e-01 1.16285316646e-01 1.16285315006e-01 1.63963664868e-09 1.00000000000e-02 1.16285316646e-01 1.16285315006e-01 1.63963442823e-09 1.00000000000e-03 1.16285316646e-01 1.16285315007e-01 1.63958446819e-09 1.00000000000e-04 1.16285316646e-01 1.16285315007e-01 1.63947344589e-09 1.00000000000e-05 1.16285316646e-01 1.16285315011e-01 1.63558767918e-09 1.00000000000e-06 1.16285316646e-01 1.16285315044e-01 1.60228097457e-09 1.00000000000e-07 1.16285316646e-01 1.16285315266e-01 1.38023636964e-09 1.00000000000e-08 1.16285316646e-01 1.16285320262e-01 3.61576724117e-09 1.00000000000e-09 1.16285316646e-01 1.16285370222e-01 5.35758033354e-08 1.00000000000e-10 1.16285316646e-01 1.16285314711e-01 1.93534788195e-09 1.00000000000e-11 1.16285316646e-01 1.16290310714e-01 4.99406826293e-06 1.00000000000e-12 1.16285316646e-01 1.16295861829e-01 1.05451833861e-05

Test Consistency of Jacobian and its adjoint: <w,Jv> - <adj(J)w,v> = 1.38907788e+02 <w,Jv> = 1.38876939e+02 Relative Error = 1.00022213e+00 Step size norm(adj(H)(u,v)) norm(FD approx) norm(abs error)

1.00000000000e+00 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-01 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-02 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-03 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-04 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-05 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-06 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-07 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-08 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-09 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-10 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-11 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 1.00000000000e-12 0.00000000000e+00 0.00000000000e+00 0.00000000000e+00 RUNTIME OF CODE ON TASK 0 is 0.296875 Local Node Strains :

However as soon as I set the Linear constraint and polyhedral projection my program crashes on the equilibrium solve since it insists on setting rho=0 for the check at some point even though the problem has lower bounds trying to prevent that.

Adrian-Diaz commented 3 years ago

I'm gonna try removing the solve step from the mass constraint anyway to see if that avoids the linear constraint issue. Right now comms and the solve were unnecessarily combined anyway every time it updated.

dpkouri commented 3 years ago

The issue that you are seeing is that the vectors used in "check" are random. This issue should not persist when running "solve". You can always check the derivatives manually. The ROL::Objective has functions called "checkGradient" and "checkHessVec". Similar functions exist for the constraint. In these functions, you are able to pass feasible vectors so that you bounds are satisfied.

On another note, your objective function gradient does not seem to be correct based on the finite difference check. This may be due to the infeasibility that you mentioned.

Adrian-Diaz commented 3 years ago

Yea the polyhedral solve still isn't working. I'll look into the strain energy gradient to make sure. Also, how can I force the Augmented Lagrangian solver to stop after a certain number of iterations?

dridzal commented 3 years ago

@dpkouri , I wonder if it would be useful/possible to apply constraints to the finite difference checks. I think that simply "chopping" some reference vector x should be easy, however, we must also ensure that x+t*h remain within bounds. Here, we can't just chop. The vector h must be chosen very carefully, as it depends on x and the size of t. Thoughts? Maybe x could be a small random perturbation of (a+b)/2, where a and b are the lower and upper bound vectors, and each h_i could be chosen based on the full range of t's and the size of the intervals b_i-x_i and x_i-a_i, for each index i.

dridzal commented 3 years ago

@Adrian-Diaz there should be an xml parameter for the number of optimization iterations in your input file.

Adrian-Diaz commented 3 years ago

Is it the one under "STATUS TEST SUBLIST" ?

dpkouri commented 3 years ago

@dridzal As you pointed out, simple chopping is not ideal. Another reason chopping is bad is that it could destroy the randomness, resulting in values only on the bounds. A better option is to generate the samples using elementwise features so that each component is uniformly distributed in the hypercube defined by the bounds. This has the obvious drawback that not everyone implements the elementwise functions of ROL::Vector.

dridzal commented 3 years ago

Yes.


From: Adrian-Diaz @.> Sent: Wednesday, October 13, 2021 15:24 To: trilinos/Trilinos @.> Cc: Ridzal, Denis @.>; Mention @.> Subject: [EXTERNAL] Re: [trilinos/Trilinos] ROL: adding an inequality constraint (#9659)

Is it the one under "STATUS TEST SUBLIST" ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/trilinos/Trilinos/issues/9659#issuecomment-942732738, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADYTKCQXNDWHIBYSOJKG2T3UGX2KFANCNFSM5DMLNDTQ. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

Adrian-Diaz commented 3 years ago

Just to clarify, does the polyhedral projection solve only require the constraint to be linear? or does the objective need to be linear in the design variable too?

dridzal commented 3 years ago

This is just for the constraint. There are certain methods (e.g., specifically tailored to very simple problems in structural optimization) that rely on both assumptions you stated. Polyhedral projection implicitly enforces the linear constraint. The objective can be nonlinear and nonconvex in the design variables.

Adrian-Diaz commented 3 years ago

This is what I got from the objective gradient check function for x = 1 and d = -0.00001 for all entries respectively:

Step size grad'*dir FD approx abs error


1.00000000000e+00 3.63636000000e-07 3.63645076532e-07 9.07653187385e-12 1.00000000000e-01 3.63636000000e-07 4.00010582628e-06 3.63646982628e-06 1.00000000000e-02 3.63636000000e-07 4.03647143215e-05 4.00010783215e-05 1.00000000000e-03 3.63636000000e-07 4.04010799376e-04 4.03647163376e-04 1.00000000000e-04 3.63636000000e-07 4.04047164993e-03 4.04010801393e-03 1.00000000000e-05 3.63636000000e-07 4.04050801555e-02 4.04047165195e-02 1.00000000000e-06 3.63636000000e-07 4.04051165215e-01 4.04050801579e-01 1.00000000000e-07 3.63636000000e-07 4.04051201585e+00 4.04051165222e+00 1.00000000000e-08 3.63636000000e-07 4.04051205213e+01 4.04051201576e+01 1.00000000000e-09 3.63636000000e-07 4.04051205580e+02 4.04051205217e+02 1.00000000000e-10 3.63636000000e-07 4.04051205617e+03 4.04051205580e+03 1.00000000000e-11 3.63636000000e-07 4.04051205617e+04 4.04051205613e+04 1.00000000000e-12 3.63636000000e-07 4.04051205617e+05 4.04051205616e+05

This is what I get with d = -0.000001:

Step size grad'*dir FD approx abs error


1.00000000000e+00 3.63656170348e-08 3.63657078114e-08 9.07766368287e-14 1.00000000000e-01 3.63656170348e-08 4.00022885719e-07 3.63657268684e-07 1.00000000000e-02 3.63656170348e-08 4.03659467501e-06 4.00022905797e-06 1.00000000000e-03 3.63656170348e-08 4.04023125684e-05 4.03659469514e-05 1.00000000000e-04 3.63656170348e-08 4.04059491508e-04 4.04023125891e-04 1.00000000000e-05 3.63656170348e-08 4.04063128078e-03 4.04059491516e-03 1.00000000000e-06 3.63656170348e-08 4.04063491780e-02 4.04063128124e-02 1.00000000000e-07 3.63656170348e-08 4.04063528123e-01 4.04063491757e-01 1.00000000000e-08 3.63656170348e-08 4.04063531800e+00 4.04063528164e+00 1.00000000000e-09 3.63656170348e-08 4.04063532095e+01 4.04063531732e+01 1.00000000000e-10 3.63656170348e-08 4.04063532130e+02 4.04063532094e+02 1.00000000000e-11 3.63656170348e-08 4.04063532130e+03 4.04063532126e+03 1.00000000000e-12 3.63656170348e-08 4.04063532130e+04 4.04063532130e+04

This is what I get with d = -0.0000001:

1.00000000000e+00 3.63636000000e-09 3.63636090336e-09 9.03364055330e-16 1.00000000000e-01 3.63636000000e-09 3.99999708876e-08 3.63636108876e-08 1.00000000000e-02 3.63636000000e-09 4.03636071095e-07 3.99999711095e-07 1.00000000000e-03 3.63636000000e-09 4.03999707473e-06 4.03636071473e-06 1.00000000000e-04 3.63636000000e-09 4.04036071440e-05 4.03999707840e-05 1.00000000000e-05 3.63636000000e-09 4.04039707767e-04 4.04036071407e-04 1.00000000000e-06 3.63636000000e-09 4.04040071539e-03 4.04039707903e-03 1.00000000000e-07 3.63636000000e-09 4.04040107795e-02 4.04040071431e-02 1.00000000000e-08 3.63636000000e-09 4.04040111264e-01 4.04040107628e-01 1.00000000000e-09 3.63636000000e-09 4.04040111264e+00 4.04040110900e+00 1.00000000000e-10 3.63636000000e-09 4.04040111264e+01 4.04040111228e+01 1.00000000000e-11 3.63636000000e-09 4.04040111264e+02 4.04040111260e+02 1.00000000000e-12 3.63636000000e-09 4.04040111264e+03 4.04040111264e+03

For some reason only the first step call seems to be behave as expected, not sure what its doing for the other ones to suddenly get a very different answer.

Adrian-Diaz commented 3 years ago

On another note, I've noticed ROL seems to hang near the end of my solves (the design iterations look like they're about to finish since nothing is perceptibly changing). I put a bunch of prints to determine that all of the constraint and objective implementations are completing on all MPI ranks; it seems something in the ROL algorithm is not exiting gracefully or still looping. I've noticed this happen on serial runs too. Any idea what could cause that?

dridzal commented 3 years ago

@Adrian-Diaz is this with projections?

Adrian-Diaz commented 3 years ago

The hanging issue is with the augmented Lagrangian run. It tends to converge to a design every time such as attached but it won't exit the run. image

dridzal commented 3 years ago

ROL displays a message with the final status (converged, etc.). Do you see this message?

Adrian-Diaz commented 3 years ago

No there's no finalization, its still looping in the algorithm somewhere.

dridzal commented 3 years ago

Please try increasing the level of output to 4. This should give you more info about the inner iterations.

Adrian-Diaz commented 3 years ago

I'll give that a try.

Adrian-Diaz commented 3 years ago

This is the last thing it printed before getting stuck

image