Are Pyomo numeric constants floats?

9 views
Skip to first unread message

Bill Hart

unread,
May 18, 2018, 2:59:08 AM5/18/18
to Pyomo Developers
Historically, we have converted integer numeric constants to floats.  Early on, there were a number of users who got caught by Python's integer division, so this simplified the user experience.

However, I want to revisit that decision.  I think that this decision made a lot more sense when working with Abstract models.  But with Concrete models, users are loading their own data into the model.  Hence, I'm not sure why we shouldn't compute the same calculation when a user hands us integers.

Additionally, integer numeric values are directly used by kernel and the matrix, and they can show up in expression trees.  Hence, automatically coercing values to floats seems like an incomplete solution that doesn't "fix" the problem anyway.

Thoughts?

--Bill

David Woodruff

unread,
May 18, 2018, 8:05:51 AM5/18/18
to pyomo-de...@googlegroups.com
This change may (will?) cause data-dependant troubles for some users of Python 2.7 so I while I like the idea a lot, I think we should wait until after our last 2.7-supporitng release.  Full disclosure: I would prefer that our next release be our last 2,7-supporting release.
   Dave

--
You received this message because you are subscribed to the Google Groups "Pyomo Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Laird, Carl Damon

unread,
May 18, 2018, 9:24:34 AM5/18/18
to pyomo-de...@googlegroups.com

I agree with David’s first point (not so much with the second one he sneakily tried to sneak in)… I think it is better to keep floating point behavior for python data otherwise people will get burned. (OK fine… Carl will get burned.)

 

Incidentally, other python packages are not sold on the integer division either. While it is my understanding that numpy does truncated division with int by default, pandas does not.

 

>>> print(df)

   A  B

0  1  3

1  2  4

>>> df.div(2)

     A    B

0  0.5  1.5

1  1.0  2.0

>>>

 

Regards,

 

Carl.

--

To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-develope...@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.

 

--

You received this message because you are subscribed to the Google Groups "Pyomo Developers" group.

To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-develope...@googlegroups.com.

Laird, Carl Damon

unread,
May 18, 2018, 9:33:43 AM5/18/18
to pyomo-de...@googlegroups.com

(The pandas code was done in Python 2.7)

Siirola, John D

unread,
May 18, 2018, 10:01:23 AM5/18/18
to pyomo-de...@googlegroups.com

I believe that this discussion was triggered by a discussion Bill and I am having on a PR.  There are already a number of sneaky inconsistencies in Pyomo:

 

>>> m = ConcreteModel()

>>> m.p = Param(initialize=1)

>>> m.p / 2

0.5

>>> m.q = Param([1], initialize=1)

>>> m.q[1]/2

0

>>> m.r = Param(initialize=1, mutable=True)

>>> m.r/2

<pyomo.core.expr.expr_pyomo5.NPV_ProductExpression object at 0x7fc2362d9f30>

>>> value(m.r/2)

0.5

>>> 

 

There is another one related to putting numpy floats into immutable indexed Params…

 

john

Reply all
Reply to author
Forward
0 new messages