code: def test_basic():
      """Test we can convert from a PyMC Model to a FunctionGraph and back"""
      with pm.Model(coords={"test_dim": range(3)}) as m_old:
          x = pm.Normal("x")
          y = pm.Deterministic("y", x + 1)
          w = pm.HalfNormal("w", pm.math.exp(y))
          z = pm.Normal(
              "z", y, w, observed=[0, 1, 2], dims=("test_dim",)
          )
          pot = pm.Potential("pot", x * 2)
  
      m_fgraph, memo = fgraph_from_model(m_old)
      assert isinstance(m_fgraph, FunctionGraph)
  
      assert isinstance(memo[x].owner.op, ModelFreeRV)
      assert isinstance(memo[y].owner.op, ModelDeterministic)
      assert isinstance(memo[w].owner.op, ModelFreeRV)
      assert isinstance(memo[z].owner.op, ModelObservedRV)
      assert isinstance(memo[pot].owner.op, ModelPotential)
  
      m_new = model_from_fgraph(m_fgraph)
      assert isinstance(m_new, pm.Model)
  
      assert m_new.coords == {"test_dim": tuple(range(3))}
      assert m_new._dim_lengths["test_dim"].eval() == 3
      assert m_new.named_vars_to_dims == {"z": ["test_dim"]}
  
      named_vars = {"x", "y", "w", "z", "pot"}
      assert set(m_new.named_vars) == named_vars
      for named_var in named_vars:
          assert m_new[named_var] is not m_old[named_var]
      for value_new, value_old in zip(
          m_new.rvs_to_values.values(), m_old.rvs_to_values.values()
      ):
          # Constants are not cloned
          if not isinstance(value_new, Constant):
              assert value_new is not value_old
      assert m_new["x"] in m_new.free_RVs
      assert m_new["w"] in m_new.free_RVs
      assert m_new["y"] in m_new.deterministics
      assert m_new["z"] in m_new.observed_RVs
      assert m_new["pot"] in m_new.potentials
      assert m_new.rvs_to_transforms[m_new["x"]] is None
      assert (
          m_new.rvs_to_transforms[m_new["w"]]
          is pm.distributions.transforms.log
      )
      assert m_new.rvs_to_transforms[m_new["z"]] is None
  
      # Test random
      new_y_draw, new_z_draw = pm.draw(
          [m_new["y"], m_new["z"]], draws=5, random_seed=1
      )
      old_y_draw, old_z_draw = pm.draw(
          [m_old["y"], m_old["z"]], draws=5, random_seed=1
      )
      np.testing.assert_array_equal(new_y_draw, old_y_draw)
      np.testing.assert_array_equal(new_z_draw, old_z_draw)
  
      # Test logp
      ip = m_new.initial_point()
      np.testing.assert_equal(
          m_new.compile_logp()(ip),
          m_old.compile_logp()(ip),
      )
  
file_path: pymc/tests/model/test_fgraph.py
imports: import numpy
  import pytensor.tensor
  import pytest
  from pytensor import config, shared
  from pytensor.graph import Constant, FunctionGraph, node_rewriter
  from pytensor.graph.rewriting.basic import in2out
  from pytensor.tensor.exceptions import NotScalarConstantError
  import pymc
  from pymc.model.fgraph import ModelDeterministic, ModelFreeRV, ModelNamed, ModelObservedRV, ModelPotential, ModelVar, clone_model, fgraph_from_model, model_deterministic, model_free_rv, model_from_fgraph
label_desc: Use image node_id 1 for calling a global function with example usage: test_basic() without return types