pymc-devs / pymc-devs/pymc-examples

Error in `examples/causal_inference/regression_discontinuity.ipynb`

Open
#725 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
398
Forks
325
Avg merge
9d 15m
Merged PRs (30d)
1

Description

This could be something with Windows

───────────────────────────────────── Error running examples/causal_inference/regression_discontinuity.ipynb ─────────────────────────────────────

---------------------------------------------------------------------------
Exception encountered at "In [10]":
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
File ~/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pytensor/link/basic.py:102, in Container.__set__(self, value)
    100 try:
    101     # Use in-place filtering when/if possible
--> 102     self.storage[0] = self.type.filter_inplace(
    103         value, self.storage[0], **kwargs
    104     )
    105 except NotImplementedError:

File ~/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pytensor/graph/type.py:128, in Type.filter_inplace(self, value, storage, strict,
allow_downcast)
    109 """Return data or an appropriately wrapped/converted data by converting it in-place.
    110
    111 This method allows one to reuse old allocated memory.  If this method
   (...)
    126 NotImplementedError
    127 """
--> 128 raise NotImplementedError()

NotImplementedError:

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
Cell In[10], line 8
      6 # posterior prediction (see technical note above)
      7 with model:
----> 8     pm.set_data({"x": _x, "treated": _treated})
      9     ppc = pm.sample_posterior_predictive(idata, var_names=["mu", "y"])
     11 # plotting

File ~/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/model/core.py:2092, in set_data(new_data, model, coords)
   2089 model = modelcontext(model)
   2091 for variable_name, new_value in new_data.items():
-> 2092     model.set_data(variable_name, new_value, coords=coords)

File ~/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/model/core.py:1161, in Model.set_data(self, name, values, coords)
   1158         # store it as tuple for immutability as in add_coord
   1159         self._coords = tuple(new_coords)
-> 1161 shared_object.set_value(values)

File ~/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pytensor/compile/sharedvalue.py:134, in SharedVariable.set_value(self,
new_value, borrow)
    132     self.container.value = new_value
    133 else:
--> 134     self.container.value = copy.deepcopy(new_value)

File ~/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pytensor/link/basic.py:106, in Container.__set__(self, value)
    102         self.storage[0] = self.type.filter_inplace(
    103             value, self.storage[0], **kwargs
    104         )
    105     except NotImplementedError:
--> 106         self.storage[0] = self.type.filter(value, **kwargs)
    108 except Exception as e:
    109     e.args = (*e.args, f'Container name "{self.name}"')

File ~/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pytensor/tensor/type.py:204, in TensorType.filter(self, data, strict,
allow_downcast)
    195     if up_dtype != self.dtype:
    196         err_msg = (
    197             f"{self} cannot store a value of dtype {data.dtype} without "
    198             "risking loss of precision. If you do not mind "
   (...)
    202             f'"function". Value: "{data!r}"'
    203         )
--> 204         raise TypeError(err_msg)
    205 elif (
    206     allow_downcast is None
    207     and isinstance(data, float | np.floating)
   (...)
    210     # Special case where we allow downcasting of Python float
    211     # literals to floatX, even when floatX=='float32'
    212     data = _asarray(data, self.dtype)

TypeError: ('Vector(bool, shape=(?,)) 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 bool, or 2) set "allow_input_downcast=True" when calling "function". Value: "array([0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n       0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n       0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n       0., 0., 0., 0., 0., 0., 0.])"', 'Container name "treated"')

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with examples/causal_inference/regression_discontinuity.ipynb, especially cell In[10] and the pm.set_data call for x and treated. Reproduce the notebook run and inspect the value passed for treated alongside the reported boolean-versus-float64 error. Done means the notebook runs past this cell without the TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
jupyter-notebook, python
Domain
machine-learning
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.