Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluate the use of NumericConstants #468

Closed
whart222 opened this issue May 5, 2018 · 13 comments
Closed

Evaluate the use of NumericConstants #468

whart222 opened this issue May 5, 2018 · 13 comments

Comments

@whart222
Copy link
Member

whart222 commented May 5, 2018

There is a fundamental conflict between the use of NumericConstants in Pyomo and the design of the matrix constraint.

A Constraint component represents lower and upper constraint bounds with NumericConstant objects that wrap numeric values. Thus, the lb/ub methods return objects that can be interrogated in a standard manner (e.g. is_potentially_variable()).

A MatrixConstraint component represents lower and upper constraint bounds as arrays of numeric values. Thus, the lb/ub methods return numeric values.

I don't see an obvious way to reconcile this design differences. I'm leaning towards allowing bounds to be numeric values.

But I don't see how we can represent matrix constraints where bounds are non-variable expressions (i.e. that include mutable parameters). Is that possible?

@ghackebeil
Copy link
Member

In Kernel, the constraint component does not wrap the lb and ub properties on assignment. It does call as_numeric on what is being assigned, but this is only done so that it can assert the argument is "not potentially variable".

As with assignment to the expr attribute on named expressions, I think the more intuitive behavior for users is to not change the object they assigned to properties like this, so that they will not be surprised when using that property. E.g.,

c = constraint()
c.lb = 5
if c.lb <= 5:
    ...

I don't think something like this should result in an exception (it would if we converted 5 to a NumericConstant).

@whart222
Copy link
Member Author

whart222 commented May 7, 2018

@ghackebeil I like your example.

It occurs to me that the core issue here is that sometimes we want to think about our modeling environment w.r.t. expressions, and sometimes w.r.t. matrices/vectors/numbers. It could be that that is the core difference between a kernel layer and an AML layer.

BUT, that start's looking like two modeling environments; already kernel has that feel to me.

As an example, what would it mean for a user to define a set of constraints:

A x == b

where (1) A and b are matrices and vectors (i.e. with only numeric values), or (2) where A and b are modeling components for matrix and vector-like things where elements can be expressions? In (1), it's clear how a user would create numerical algorithms directly with the model. In (2), the user should expect to translate their model in some manner before passing it to a numerical algorithm.

But do we treat these separately in Pyomo? Or allow the user to specify both types and require the transformation only when necessary?

@jwatsonnm
Copy link
Contributor

I will argue here for co-existence. As a motivating exemplar, I would like the ability to translate between the AML and kernel layers. We have a lot of problems in which a large chunk of the model is invariant or at least very stable. And despite this, we re-build these chunks over and over and over - with the associated build time and memory expense. An alternative would be to "compile" said things into the kernel layer once we are happy with them. And then we could perform very fast (well, at least faster than standard Python) I/O, e.g., by going through numpy. Memory reductions would also be a plus.

@whart222
Copy link
Member Author

whart222 commented May 7, 2018

@jwatsonnm But would we need/want mixed models? For example, models where some components are type (1) and some are type (2)? Or for simplicity would it make more sense to convert from (2) to (1). We're not really doing that today, which is why I ask.

@jwatsonnm
Copy link
Contributor

Yes - I am arguing for models with mixed types of components. I think we would want to convert from AML to Kernel, and then embed the resulting Kernels in AML models. I do not think converting from kernel to AML is useful, in that the symbolics are gone once you convert to kernel.

@whart222
Copy link
Member Author

whart222 commented May 7, 2018

If we're going to support mixed types of components, then it seems natural for us to have symbolic components - like our AML models - and numeric components - like Kernel. I'm OK tentatively closing this ticket if others agree that that plan seems desirable. But I think we need to have a separate design discussion regarding this type of distinction and the pros and cons.

@whart222
Copy link
Member Author

whart222 commented May 7, 2018

FWIW, I like thinking about this as a means towards performance optimization. I could even imagine having decorators for stable parts of a model with which kernel-level representations are automatically generated. Hmm...

For example, supporting mutable parameters is expensive. So there are real wins to be had by generating a mathematically structured problem representation (e.g. linear constraints).

@carldlaird
Copy link
Member

Not sure that the separation between AML and kernel is "symbolic" vs "numeric". I don't understand this distinction.

@whart222
Copy link
Member Author

whart222 commented May 7, 2018

@carldlaird For example, is a lower or upper bound value always a number or could it be a pyomo expression.

@jwatsonnm
Copy link
Contributor

I like the idea of decorators being used to automatically compile stable parts of the model. "Hmm" indeed!

@michaelbynum
Copy link
Contributor

I thought the goal was to merge AML and kernel so that kernel is used under the hood, making kernel and AML models compatible. Is it valuable to maintain both AML and kernel separately long term? Maybe I don't fully understand the discussion...

@whart222
Copy link
Member Author

whart222 commented May 8, 2018

@michaelbynum Yes, that's the plan. But we need to resolve discrepancies like this if we're going to do that merge. OR, we could decide to not merge. (Though, if we go down that route, there are important design ideas we need to use from kernel to rework the AML.)

@mrmundt
Copy link
Contributor

mrmundt commented Jan 3, 2024

In an effort to clean up old issues, we are moving some design discussions to our Archived Design Discussions wiki.

@mrmundt mrmundt closed this as completed Jan 3, 2024
@blnicho blnicho closed this as not planned Won't fix, can't repro, duplicate, stale Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants