[petsc-dev] coding style

Munson, Todd tmunson at mcs.anl.gov
Tue Aug 16 18:52:52 CDT 2016


Yes, many solvers treat linear constraints special and remain feasible with respect
to those constraints.


For now, my plan is to update and fix bugs in the existing methods, while getting
the code up to the PETSc coding standards, making sure we have test case 
coverage, and reorganizing the code base in a better manner.

Beyond that, we will see what gets funded by ECP and SciDAC-4.  :)

I do know that we will work on robust optimization methods, which will require 
related work on generic nonlinear programming methods.

Todd.

> On Aug 16, 2016, at 6:33 PM, Oxberry, Geoffrey Malcolm <oxberry1 at llnl.gov> wrote:
> 
> Instead of a flag for linear constraints, one could also just as easily set up a callback for linear constraints for NLP solvers, and then incorporate that information into algorithms as appropriate. If I remember correctly, SNOPT treats linear constraints separately, so there is precedent in other optimization solvers for this type of mechanism.
> 
> re: splitting up TAO methods, I like this idea, in that it reflects more how problem taxonomy is thought of in optimization (at least, in the chemical engineering and operations research subcommunities in this area). Reorganizing solvers based on taxonomy begs the question: what do you guys have planned for TAO? I hate to ask such a broad question, and of course, I can appreciate if you'd rather not answer it in a public forum, or talk about it to someone not at ANL. As someone who is interested in both contributing to TAO and using it in research, this question is very interesting to me.
> 
> Best,
> Geoff
> ________________________________________
> From: Munson, Todd [tmunson at mcs.anl.gov]
> Sent: Tuesday, August 16, 2016 4:09 PM
> To: Oxberry, Geoffrey Malcolm
> Cc: Smith, Barry F.; petsc-dev
> Subject: Re: [petsc-dev] coding style
> 
> Is there a reason to put flags into PETSc for linear or nonlinear equations?  In PETSc
> there is a natural difference between linear (KSP) and nonlinear (SNES) that is
> reflected in the objects.
> 
> Any thoughts on splitting up the TAO methods in a similar way and distinguish at
> least between between quadratic and general nonlinear problems, rather than
> putting in flags.  This would be consistent with the rest of PETSc.
> 
> For example, instead of having a single "bound" directory, having something
> like a "bco" directory for generic nonlinear bound-constrained optimization
> and a "bqp" directory for bound constrained quadratic programs.
> 
> I'd do the same for "unconstrained" into "uco" and "uqp".
> 
> General constraints then become more cumbersome with too many combinations.
> Could probably get by with generic "lp", "qp", and "nlp" though.
> 
> The methods would then explicitly mention the type of optimization problem
> with, for example, TAO_UCO_LMVM, TAO_BCO_TRON, and TAO_BQP_GPCG.
> 
> Thoughts?
> 
> Todd.
> 
> 
>> On Aug 16, 2016, at 4:32 PM, Oxberry, Geoffrey Malcolm <oxberry1 at llnl.gov> wrote:
>> 
>> Definitely flags for linear problems would be helpful for TAO. Once there is an example up, I'd be happy to add that to the SQPTR pull request.
>> 
>> ________________________________________
>> From: petsc-dev-bounces at mcs.anl.gov [petsc-dev-bounces at mcs.anl.gov] on behalf of Barry Smith [bsmith at mcs.anl.gov]
>> Sent: Monday, August 15, 2016 6:18 PM
>> To: Munson, Todd
>> Cc: petsc-dev
>> Subject: Re: [petsc-dev] coding style
>> 
>>> On Aug 15, 2016, at 8:08 PM, Munson, Todd <tmunson at mcs.anl.gov> wrote:
>>> 
>>> 
>>> Since we are only doing diagonal modifications to the matrix in
>>> my case, should I simply create a matnest in my part of the
>>> code and apply the diagonal modification in the matnest
>>> without directly modifying any of the matrices?
>>> That might be cleaner for the users.
>> 
>>  It will be dependent on the solver how much of the matrix you need retain the parts you have modified.
>> 
>>  MatNest isn't the right thing here. I think you can do MatGetDiagonal() to keep the valid diagonal entries then MatDiagonalSet() to put back the valid entries.
>> 
>>  Barry
>> 
>> 
>>> 
>>> Todd.
>>> 
>>>> On Aug 15, 2016, at 7:55 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
>>>> 
>>>> 
>>>>> On Aug 15, 2016, at 7:42 PM, Munson, Todd <tmunson at mcs.anl.gov> wrote:
>>>>> 
>>>>> 
>>>>> Got it.  I will get all the code fragments in the developer doc that
>>>>> are not meant to be deliberately wrong fixed tomorrow; at least
>>>>> that code will be compliant...  :)
>>>>> 
>>>>> Then its onto fixing bqpip.
>>>>> 
>>>>> Was there a final say on the Hessian/Jacobian matrix when they are
>>>>> modified?  Were we adding a "dirty" bit or was I changing my code
>>>>> to not modify those matrices?
>>>> 
>>>> Changing email to petsc-dev since this is a general PETSc/TAO issue.
>>>> 
>>>> This is why we don't wait months to fix something :-) I have completely forgot the context you are asking  about.
>>>> 
>>>> I think the general issue comes up when a problem is linear and the user just wants to set and forget the matrices while when the problem is nonlinear the user needs to reset values into the matrix anyways so it is fine for you to change the matrix internally. Unless there is a way for the user to explicitly indicate the system is linear your code cannot know if it needs to make a copy of the matrix.
>>>> 
>>>> In TS we have typedef enum {TS_LINEAR,TS_NONLINEAR} TSProblemType; and TSSetProblemType() that can be used to indicate if the matrices can be changed or not (though I don't think we use it in this way, we have an open issue https://bitbucket.org/petsc/petsc/issues/135/memory-optimization-for-ts
>>>> 
>>>> I think you should start by having a flag that indicates if it is safe to modify the matrices associated with the TAO object and if not safe keep a backup copy.
>>>> 
>>>> Barry
>>>> 
>>>> 
>>>> 
>>>>> 
>>>>> Todd.
>>>>> 
>>>>>> On Aug 15, 2016, at 6:09 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
>>>>>> 
>>>>>> 
>>>>>> Todd,
>>>>>> 
>>>>>>> On Aug 15, 2016, at 10:26 AM, Satish Balay <balay at mcs.anl.gov> wrote:
>>>>>>> 
>>>>>>> Todd,
>>>>>>> 
>>>>>>> Forwarding this to Barry.
>>>>>>> 
>>>>>>> Satish
>>>>>>> 
>>>>>>> On Mon, 15 Aug 2016, Munson, Todd wrote:
>>>>>>> 
>>>>>>>> 
>>>>>>>> I'm going through the developer documentation.  There seems to be
>>>>>>>> a few things missing from the coding style.
>>>>>>>> 
>>>>>>>> For example, in function prototypes, is it:
>>>>>>>> 
>>>>>>>> PetscErrorCode MyFunction(char *,const int *,int);
>>>>>>>> 
>>>>>>>> or
>>>>>>>> 
>>>>>>>> PetscErrorCode MyFunction(char*,const int*,int)
>>>>>> 
>>>>>> The second one because the preference is to not have unnecessary space.
>>>>>> 
>>>>>>>> 
>>>>>>>> 
>>>>>>>> Same thing in the definitions:
>>>>>>>> 
>>>>>>>> PetscErrorCode MyFunction(char *c,const int *i,int j)
>>>>>>>> {
>>>>>>>> }
>>>>>>>> 
>>>>>>>> or
>>>>>>>> 
>>>>>>>> PetscErrorCode MyFunction(char* c,const int* i,int j)
>>>>>> 
>>>>>> The * should always be attached to the variable.
>>>>>>>> {
>>>>>>>> }
>>>>>>>> 
>>>>>>>> The same questions apply with * replaced by [].
>>>>>>>> 
>>>>>>>> 
>>>>>>>> Next is in the types for variables.  Are pointers grouped
>>>>>>>> separately or together with the type:
>>>>>>>> 
>>>>>>>> int   *i,j,*k;
>>>>>>>> 
>>>>>>>> or
>>>>>>>> 
>>>>>>>> int   *i,*k;
>>>>>>>> int   j;
>>>>>>>> 
>>>>>>>> If grouped together, should they be ordered with pointers first
>>>>>>>> and the others later?
>>>>>>>> 
>>>>>>>> int   *i,*k,j;
>>>>>> 
>>>>>> There is no preference on the above; the pointers do not have to be on their own line.
>>>>>>>> 
>>>>>>>> On the next topic, do you use
>>>>>>>> 
>>>>>>>> char    *blah;
>>>>>>>> 
>>>>>>>> or
>>>>>>>> 
>>>>>>>> char*   blah;
>>>>>>>> 
>>>>>>>> when there is only one of them?
>>>>>> 
>>>>>> * belongs on the variable
>>>>>> 
>>>>>>>> 
>>>>>>>> I have the same issues with the typedefs.  Sometimes there is
>>>>>>>> 
>>>>>>>> typedef struct _EH* EH;
>>>>>>>> 
>>>>>>>> and other times
>>>>>>>> 
>>>>>>>> typedef struct _EH *EH;
>>>>>> 
>>>>>> Here the * belongs as in the first case
>>>>>>>> 
>>>>>>>> 
>>>>>>>> My personal thought is to be consistent and use char * with a space
>>>>>>>> everywhere, but you tell me.  I will then go and fix the developer
>>>>>>>> documentation to be consistent with the style guide as a test of
>>>>>>>> my branch management.
>>>>>>>> 
>>>>>>>> Todd.
>>>>>>>> 
>>>>>>>> 
>>>>>>> 
>>>>>> 
>>>>> 
>>>> 
>>> 
>> 
> 




More information about the petsc-dev mailing list