code: def observe(
      model: Model,
      vars_to_observations: Mapping[Union["str", TensorVariable], Any],
  ) -> Model:
      """Convert free RVs or Deterministics to observed RVs.
  
      Parameters
      ----------
      model: PyMC Model
      vars_to_observations: Dict of variable or name to TensorLike
          Dictionary that maps model variables (or names) to observed values.
          Observed values must have a shape and data type that is compatible
          with the original model variable.
  
      Returns
      -------
      new_model: PyMC model
          A distinct PyMC model with the relevant variables observed.
          All remaining variables are cloned and can be retrieved via `new_model["var_name"]`.
  
      Examples
      --------
      .. code-block:: python
  
          import pymc as pm
  
          with pm.Model() as m:
              x = pm.Normal("x")
              y = pm.Normal("y", x)
              z = pm.Normal("z", y)
  
          m_new = pm.observe(m, {y: 0.5})
  
      Deterministic variables can also be observed.
      This relies on PyMC ability to infer the logp of the underlying expression
  
      .. code-block:: python
  
          import pymc as pm
  
          with pm.Model() as m:
              x = pm.Normal("x")
              y = pm.Normal.dist(x, shape=(5,))
              y_censored = pm.Deterministic("y_censored", pm.math.clip(y, -1, 1))
  
          new_m = pm.observe(m, {y_censored: [0.9, 0.5, 0.3, 1, 1]})
  
  
      """
      vars_to_observations = {
          model[var] if isinstance(var, str) else var: obs
          for var, obs in vars_to_observations.items()
      }
  
      valid_model_vars = set(model.free_RVs + model.deterministics)
      if any(
          var not in valid_model_vars for var in vars_to_observations
      ):
          raise ValueError(
              "At least one var is not a free variable or deterministic in the model"
          )
  
      fgraph, memo = fgraph_from_model(model)
  
      replacements = {}
      for var, obs in vars_to_observations.items():
          model_var = memo[var]
  
          # Just a sanity check
          assert isinstance(
              model_var.owner.op, (ModelFreeRV, ModelDeterministic)
          )
          assert model_var in fgraph.variables
  
          var = model_var.owner.inputs[0]
          var.name = model_var.name
          dims = extract_dims(model_var)
          model_obs_rv = model_observed_rv(
              var, var.type.filter_variable(obs), *dims
          )
          replacements[model_var] = model_obs_rv
  
      toposort_replace(fgraph, tuple(replacements.items()))
  
      return model_from_fgraph(fgraph)
  
file_path: pymc/pymc/model/transform/conditioning.py
imports: import warnings
  from typing import Any, Mapping, Optional, Sequence, Union
  from pytensor.graph import ancestors
  from pytensor.tensor import TensorVariable
  from pymc import Model
  from pymc.logprob.transforms import Transform
  from pymc.logprob.utils import rvs_in_graph
  from pymc.model.fgraph import ModelDeterministic, ModelFreeRV, extract_dims, fgraph_from_model, model_deterministic, model_free_rv, model_from_fgraph, model_named, model_observed_rv
  from pymc.model.transform.basic import ModelVariable, parse_vars, prune_vars_detached_from_observed
  from pymc.pytensorf import replace_vars_in_graphs, toposort_replace
  from pymc.util import get_transformed_name, get_untransformed_name
label_desc: Use image node_id 1 for calling a global function with example usage: observe(model, vars_to_observations) and returns: model_from_fgraph