-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
BUG: Calling pm.set_data() on MutableData with dims causes error #6497
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
Comments
Not being able to resize dimension Your second example works because Maybe the exception message is not clear enough:
In the first example, the More concerning is that running the second example on latest main gives a Python 3.9.13 | packaged by conda-forge | (main, May 27 2022, 16:51:29) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymc as pm
>>> coords = {"x": [1, 2, 3]}
>>> with pm.Model(coords=coords):
... pm.MutableData("y", [0, 0, 0])
... pm.set_data({"y": range(5)}, coords={"x": range(5)})
...
y
Traceback (most recent call last):
File "C:\Users\zufal\miniconda3\envs\pmdev\lib\site-packages\pytensor\link\basic.py", line 111, in __set__
self.storage[0] = self.type.filter_inplace(
File "C:\Users\zufal\miniconda3\envs\pmdev\lib\site-packages\pytensor\graph\type.py", line 130, in filter_inplace
raise NotImplementedError()
NotImplementedError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
File "E:\Source\Repos\pymc\pymc\model.py", line 1887, in set_data
model.set_data(variable_name, new_value, coords=coords)
File "E:\Source\Repos\pymc\pymc\model.py", line 1283, in set_data
shared_object.set_value(values)
File "C:\Users\zufal\miniconda3\envs\pmdev\lib\site-packages\pytensor\compile\sharedvalue.py", line 134, in set_value
self.container.value = copy.deepcopy(new_value)
File "C:\Users\zufal\miniconda3\envs\pmdev\lib\site-packages\pytensor\link\basic.py", line 115, in __set__
self.storage[0] = self.type.filter(value, **kwargs)
File "C:\Users\zufal\miniconda3\envs\pmdev\lib\site-packages\pytensor\tensor\type.py", line 199, in filter
raise TypeError(err_msg)
TypeError: ('TensorType(int32, (?,)) cannot store a value of dtype float64 without risking loss of precision. If you do not mind this loss, you can: 1) explicitly cast your data to int32, or 2) set "allow_input_downcast=True" when calling "function". Value: "array([0., 1., 2., 3., 4.])"', 'Container name "y"')
>>> |
IMO, we should do one of the following:
The current API is not discoverable nor intuitive. |
We considered a |
Is there a performance problem if coords are mutable by default? Or maybe we can just check if coords are used inside of a MutableData container and then set it mutable? Sounds a bit hackish but 🤷 |
Retracted there might be issues with value variables not having static shapes... |
Hey I would like to take up this issue. Have a look at this example: import pymc as pm
coords = {"x": range(2)}
with pm.Model(coords = coords):
pm.MutableData("y", [0, 0, 0])
model.add_coord("x", coords, mutable=True)
pm.set_data({"y": [1, 2, 3, 4, 5]}, coords={"x": range(5)}) what we want to achieve is this: import pymc as pm
coords = {"x": range(2)}
with pm.Model(mutable_coords = coords):
pm.MutableData("y", [0, 0, 0])
pm.set_data({"y": [1, 2, 3, 4, 5]}, coords={"x": range(5)}) However, not setting the mutable = 'True' does not produce any error import pymc as pm
coords = {"x": range(2)}
with pm.Model(coords = coords):
pm.MutableData("y", [0, 0, 0])
pm.set_data({"y": [1, 2, 3, 4, 5]}, coords={"x": range(5)}) |
@Dhruvanshu-Joshi you can focus on this line: Line 588 in ac9652e
...and make it for iterate to call self.add_coord(..., mutable=True) similar to how add_coords does it.
|
Closed via #6515 |
Describe the issue:
For some reaoson, having a
pm.MutableData()
that sets dims seems to turn it into aConstantData
? At least when callingpm.set_data()
to update it, along with updating coords, raises an error. Not having rely it on dims makes it work.Reproduceable code example:
Error message:
PyMC version information:
5.0.1
Context for the issue:
Happened during a workshop, confusing for beginners.
The text was updated successfully, but these errors were encountered: