Description
Summary
During tracking down a totally different problem, I noticed that there is a doctest from uncertainty_sets
that is invalid code and doesn't run. We don't fail on warnings, so we hadn't noticed before.
Steps to reproduce the issue
I noticed this in the doctests when I was looking at something else entirely
D:\a\pyomo\pyomo\doc\OnlineDocs\..\..\pyomo\contrib\pyros\uncertainty_sets.py.rst:
WARNING: ignoring invalid doctest code:
'>>> conf_ellipsoid = EllipsoidalSet(\n... center=np.zeros(4),\n... shape_matrix=np.diag(range(1, 5)),\n... scale=None,\n... gaussian_conf_lvl=0.95,\n... )\n>>> conf_ellipsoid.center\narray([0, 0, 0, 0])\n>>> conf_ellipsoid.shape_matrix\narray([[1, 0, 0, 0]],\n [0, 2, 0, 0]],\n [0, 0, 3, 0]],\n [0, 0, 0. 4]])\n>>> conf_ellipsoid.scale\n...9.4877...\n>>> conf_ellipsoid.gaussian_conf_lvl\n0.95'
...
In looking at that code, there is, in fact, a problem. Here is the code now:
A 4D 95% confidence ellipsoid:
>>> conf_ellipsoid = EllipsoidalSet(
... center=np.zeros(4),
... shape_matrix=np.diag(range(1, 5)),
... scale=None,
... gaussian_conf_lvl=0.95,
... )
>>> conf_ellipsoid.center
array([0, 0, 0, 0])
>>> conf_ellipsoid.shape_matrix
array([[1, 0, 0, 0]],
[0, 2, 0, 0]],
[0, 0, 3, 0]],
[0, 0, 0. 4]])
>>> conf_ellipsoid.scale
...9.4877...
>>> conf_ellipsoid.gaussian_conf_lvl
0.95
I think it should actually be:
A 4D 95% confidence ellipsoid:
>>> conf_ellipsoid = EllipsoidalSet(
... center=np.zeros(4),
... shape_matrix=np.diag(range(1, 5)),
... scale=None,
... gaussian_conf_lvl=0.95,
... )
>>> conf_ellipsoid.center
array([0., 0., 0., 0.])
>>> conf_ellipsoid.shape_matrix
array([[1, 0, 0, 0],
[0, 2, 0, 0],
[0, 0, 3, 0],
[0, 0, 0, 4]])
>>> conf_ellipsoid.scale
9.4877...
>>> conf_ellipsoid.gaussian_conf_lvl
0.95
The thing that is unclear to me, however - this test fails because conf_ellipsoid.scale
outputs np.float64(9.4877...)
. Is it intended that XX.scale
can return an np.float
object, or is it intended to be cast to a raw Python float
? I didn't want to make an assumption, so I hand this off to the PyROS folks to decide what the right behavior is.
Error Message
Document: api/pyomo.contrib.pyros.uncertainty_sets.EllipsoidalSet
-----------------------------------------------------------------
**********************************************************************
File "..\..\pyomo\contrib\pyros\uncertainty_sets.py", line ?, in default
Failed example:
conf_ellipsoid.scale
Expected:
9.4877...
Got:
np.float64(9.487729036781154)
**********************************************************************
1 item had failures:
1 of 15 in default
15 tests in 1 item.
14 passed and 1 failed.
***Test Failed*** 1 failure.
Information on your system
Pyomo version: 6.9.2.dev0
Python version: Multiple
Operating system: Windows (NOTE: Only seems to happen on Windows)
How Pyomo was installed (PyPI, conda, source): source
Solver (if applicable):