Skip to content

Conversation

williambdean
Copy link
Contributor

@williambdean williambdean commented Jan 24, 2025

Description

Will need some help on this implementation and how to best test this.

Related Issue

Checklist

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

📚 Documentation preview 📚: https://pymc--7656.org.readthedocs.build/en/7656/

@github-actions github-actions bot added the bug label Jan 24, 2025
@ricardoV94
Copy link
Member

We need to tell InferenceData converter how to get the data values to put in constant_data, and observed_data. It had some hardcode logic assuming you could only due Casts

@ricardoV94
Copy link
Member

I don't consider this a bugfix, it's behavior that was explicitly forbidden for conservative reasons (more like a NotImplementedError)

@williambdean
Copy link
Contributor Author

We need to tell InferenceData converter how to get the data values to put in constant_data, and observed_data. It had some hardcode logic assuming you could only due Casts

Where does this happen in the code?

@williambdean
Copy link
Contributor Author

I think the MiniBatch tests will still fail. Any thoughts on how that should behave?

@williambdean
Copy link
Contributor Author

Also, feel free to choose a better title! I couldn't express it too well

@ricardoV94
Copy link
Member

ricardoV94 commented Jan 25, 2025

We need to tell InferenceData converter how to get the data values to put in constant_data, and observed_data. It had some hardcode logic assuming you could only due Casts

Where does this happen in the code?

obs_data = extract_obs_data(aux_obs)

def extract_obs_data(x: TensorVariable) -> np.ndarray:

We should be able to just use constant_fold (also in pytensor) for it

@ricardoV94 ricardoV94 changed the title Support ops to pm.Data in observed variables Support pytensor deterministic operations as observations Jan 25, 2025
@ricardoV94 ricardoV94 changed the title Support pytensor deterministic operations as observations Support PyTensor deterministic operations as observations Jan 25, 2025
@williambdean
Copy link
Contributor Author

We should be able to just use constant_fold (also in pytensor) for it

I have an implementation before this suggestion. I need a little help understanding this. Feel free to put suggestion

@ricardoV94
Copy link
Member

We should be able to just use constant_fold (also in pytensor) for it

I have an implementation before this suggestion. I need a little help understanding this. Feel free to put suggestion

What do you mean? My suggestion is to simply call constant_fold on the observed variable

@williambdean
Copy link
Contributor Author

williambdean commented Jan 28, 2025

I am not able to make this work with either constant_fold(x) or constant_fold([x]). Both return errors. Is the constant_fold from pymc.pytensorf or from pytensor?

@ricardoV94
Copy link
Member

I am not able to make this work with either constant_fold(x) or constant_fold([x]). Both return errors. Is the constant_fold from pymc.pytensorf or from pytensor?

From pymc.pytensorf. There's a raise_if_not_constant flag you can set, but what cases is it failing?

@ricardoV94
Copy link
Member

Ah if it's a SharedVariable like pm.Data of course constant_fold is not going to work... Dummy me.

@ricardoV94
Copy link
Member

ricardoV94 commented Jan 28, 2025

from pytensor.compile.mode import Mode
import pymc as pm

with pm.Model(coords={"date": [0, 1, 2]}) as m:
    data = pm.Data("data", [0, 1, 2], dims="date")
    x = pm.Normal("x")
    y = pm.Normal("y", x, observed=data, dims="date")

cheap_eval_mode = Mode(linker="py", optimizer=None)
m.rvs_to_values[y].eval(mode=cheap_eval_mode)
# array([0., 1., 2.])

@williambdean
Copy link
Contributor Author

Thanks for the suggestion. I've used mode on the random variable directly. Is it different to get the rvs_to_values from the model? it currently isn't accessed from the function at the moment.

@williambdean
Copy link
Contributor Author

Could you point me to similar tests for this?

@williambdean
Copy link
Contributor Author

I've just added to associated pytensorf test suite

@williambdean williambdean deleted the data-as-observed branch February 27, 2025 10:50
vandalt pushed a commit to vandalt/pymc that referenced this pull request May 14, 2025
ricardoV94 added a commit to ricardoV94/pymc that referenced this pull request Jun 29, 2025
* Use RV Op name when provided
* More robust detection of observed data variables (after pymc-devs#7656 arbitrary graphs are allowed)
* Remove self loops explicitly (closes pymc-devs#7722)
ricardoV94 added a commit to ricardoV94/pymc that referenced this pull request Jun 29, 2025
* Use RV Op name when provided
* More robust detection of observed data variables (after pymc-devs#7656 arbitrary graphs are allowed)
* Remove self loops explicitly (closes pymc-devs#7722)
ricardoV94 added a commit to ricardoV94/pymc that referenced this pull request Jun 30, 2025
* Use RV Op name when provided
* More robust detection of observed data variables (after pymc-devs#7656 arbitrary graphs are allowed)
* Remove self loops explicitly (closes pymc-devs#7722)
ricardoV94 added a commit to ricardoV94/pymc that referenced this pull request Jun 30, 2025
* Use RV Op name when provided
* More robust detection of observed data variables (after pymc-devs#7656 arbitrary graphs are allowed)
* Remove self loops explicitly (closes pymc-devs#7722)
ricardoV94 added a commit to ricardoV94/pymc that referenced this pull request Jun 30, 2025
* Use RV Op name when provided
* More robust detection of observed data variables (after pymc-devs#7656 arbitrary graphs are allowed)
* Remove self loops explicitly (closes pymc-devs#7722)
ricardoV94 added a commit to ricardoV94/pymc that referenced this pull request Jun 30, 2025
* Use RV Op name when provided
* More robust detection of observed data variables (after pymc-devs#7656 arbitrary graphs are allowed)
* Remove self loops explicitly (closes pymc-devs#7722)
ricardoV94 added a commit to ricardoV94/pymc that referenced this pull request Jun 30, 2025
* Use RV Op name when provided
* More robust detection of observed data variables (after pymc-devs#7656 arbitrary graphs are allowed)
* Remove self loops explicitly (closes pymc-devs#7722)
ricardoV94 added a commit to ricardoV94/pymc that referenced this pull request Jun 30, 2025
* Use RV Op name when provided
* More robust detection of observed data variables (after pymc-devs#7656 arbitrary graphs are allowed)
* Remove self loops explicitly (closes pymc-devs#7722)
ricardoV94 added a commit to ricardoV94/pymc that referenced this pull request Jul 2, 2025
* Use RV Op name when provided
* More robust detection of observed data variables (after pymc-devs#7656 arbitrary graphs are allowed)
* Remove self loops explicitly (closes pymc-devs#7722)
ricardoV94 added a commit to ricardoV94/pymc that referenced this pull request Jul 3, 2025
* Use RV Op name when provided
* More robust detection of observed data variables (after pymc-devs#7656 arbitrary graphs are allowed)
* Remove self loops explicitly (closes pymc-devs#7722)
ricardoV94 added a commit to ricardoV94/pymc that referenced this pull request Jul 3, 2025
* Use RV Op name when provided
* More robust detection of observed data variables (after pymc-devs#7656 arbitrary graphs are allowed)
* Remove self loops explicitly (closes pymc-devs#7722)
ricardoV94 added a commit to ricardoV94/pymc that referenced this pull request Jul 3, 2025
* Use RV Op name when provided
* More robust detection of observed data variables (after pymc-devs#7656 arbitrary graphs are allowed)
* Remove self loops explicitly (closes pymc-devs#7722)
ricardoV94 added a commit to ricardoV94/pymc that referenced this pull request Jul 3, 2025
* Use RV Op name when provided
* More robust detection of observed data variables (after pymc-devs#7656 arbitrary graphs are allowed)
* Remove self loops explicitly (closes pymc-devs#7722)
ricardoV94 added a commit to ricardoV94/pymc that referenced this pull request Jul 3, 2025
* Use RV Op name when provided
* More robust detection of observed data variables (after pymc-devs#7656 arbitrary graphs are allowed)
* Remove self loops explicitly (closes pymc-devs#7722)
ricardoV94 added a commit to ricardoV94/pymc that referenced this pull request Jul 3, 2025
* Use RV Op name when provided
* More robust detection of observed data variables (after pymc-devs#7656 arbitrary graphs are allowed)
* Remove self loops explicitly (closes pymc-devs#7722)
ricardoV94 added a commit to ricardoV94/pymc that referenced this pull request Jul 8, 2025
* Use RV Op name when provided
* More robust detection of observed data variables (after pymc-devs#7656 arbitrary graphs are allowed)
* Remove self loops explicitly (closes pymc-devs#7722)
ricardoV94 added a commit to ricardoV94/pymc that referenced this pull request Jul 8, 2025
* Use RV Op name when provided
* More robust detection of observed data variables (after pymc-devs#7656 arbitrary graphs are allowed)
* Remove self loops explicitly (closes pymc-devs#7722)
ricardoV94 added a commit to ricardoV94/pymc that referenced this pull request Jul 8, 2025
* Use RV Op name when provided
* More robust detection of observed data variables (after pymc-devs#7656 arbitrary graphs are allowed)
* Remove self loops explicitly (closes pymc-devs#7722)
ricardoV94 added a commit to ricardoV94/pymc that referenced this pull request Jul 11, 2025
* Use RV Op name when provided
* More robust detection of observed data variables (after pymc-devs#7656 arbitrary graphs are allowed)
* Remove self loops explicitly (closes pymc-devs#7722)
ricardoV94 added a commit to ricardoV94/pymc that referenced this pull request Jul 11, 2025
* Use RV Op name when provided
* More robust detection of observed data variables (after pymc-devs#7656 arbitrary graphs are allowed)
* Remove self loops explicitly (closes pymc-devs#7722)
ricardoV94 added a commit to ricardoV94/pymc that referenced this pull request Jul 11, 2025
* Use RV Op name when provided
* More robust detection of observed data variables (after pymc-devs#7656 arbitrary graphs are allowed)
* Remove self loops explicitly (closes pymc-devs#7722)
ricardoV94 added a commit to ricardoV94/pymc that referenced this pull request Jul 11, 2025
* Use RV Op name when provided
* More robust detection of observed data variables (after pymc-devs#7656 arbitrary graphs are allowed)
* Remove self loops explicitly (closes pymc-devs#7722)
ricardoV94 added a commit to ricardoV94/pymc that referenced this pull request Jul 11, 2025
* Use RV Op name when provided
* More robust detection of observed data variables (after pymc-devs#7656 arbitrary graphs are allowed)
* Remove self loops explicitly (closes pymc-devs#7722)
ricardoV94 added a commit to ricardoV94/pymc that referenced this pull request Jul 14, 2025
* Use RV Op name when provided
* More robust detection of observed data variables (after pymc-devs#7656 arbitrary graphs are allowed)
* Remove self loops explicitly (closes pymc-devs#7722)
ricardoV94 added a commit to ricardoV94/pymc that referenced this pull request Jul 22, 2025
* Use RV Op name when provided
* More robust detection of observed data variables (after pymc-devs#7656 arbitrary graphs are allowed)
* Remove self loops explicitly (closes pymc-devs#7722)
ricardoV94 added a commit that referenced this pull request Jul 22, 2025
* Use RV Op name when provided
* More robust detection of observed data variables (after #7656 arbitrary graphs are allowed)
* Remove self loops explicitly (closes #7722)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: data as observed in RV
3 participants