code: def test_deterministics(inline_views):
      """Test handling of deterministics.
  
      We don't want Deterministics in the middle of the FunctionGraph, as they would make rewrites cumbersome
      However we want them in the middle of Model.basic_RVs, so they display nicely in graphviz
  
      There is one edge case that has to be considered, when a Deterministic is just a copy of a RV.
      In that case we don't bother to reintroduce it in between other Model.basic_RVs
      """
      with pm.Model() as m:
          x = pm.Normal("x")
          mu = pm.Deterministic("mu", pm.math.abs(x))
          sigma = pm.math.exp(x)
          pm.Deterministic("sigma", sigma)
          y = pm.Normal("y", mu, sigma)
          # Special case where the Deterministic
          # is a direct view on another model variable
          y_ = pm.Deterministic("y_", y)
          # Just for kicks, make it a double one!
          y__ = pm.Deterministic("y__", y_)
          z = pm.Normal("z", y__)
  
      # Deterministic mu is in the graph of x to y but not sigma
      assert m["y"].owner.inputs[3] is m["mu"]
      assert m["y"].owner.inputs[4] is not m["sigma"]
  
      fg, _ = fgraph_from_model(m, inlined_views=inline_views)
  
      # Check that no Deterministics are in graph of x to y and y to z
      x, y, z, det_mu, det_sigma, det_y_, det_y__ = fg.outputs
      # [Det(mu), Det(sigma)]
      mu = det_mu.owner.inputs[0]
      sigma = det_sigma.owner.inputs[0]
      assert y.owner.inputs[0].owner.inputs[4] is sigma
      assert det_y_ is not det_y__
      assert det_y_.owner.inputs[0] is y
      if not inline_views:
          # FreeRV(y(mu, sigma)) not FreeRV(y(Det(mu), Det(sigma)))
          assert y.owner.inputs[0].owner.inputs[3] is mu
          # FreeRV(z(y)) not FreeRV(z(Det(Det(y))))
          assert z.owner.inputs[0].owner.inputs[3] is y
          # Det(y), not Det(Det(y))
          assert det_y__.owner.inputs[0] is y
      else:
          assert y.owner.inputs[0].owner.inputs[3] is det_mu
          assert z.owner.inputs[0].owner.inputs[3] is det_y__
          assert det_y__.owner.inputs[0] is det_y_
  
      # Both mu and sigma deterministics are now in the graph of x to y
      m = model_from_fgraph(fg)
      assert m["y"].owner.inputs[3] is m["mu"]
      assert m["y"].owner.inputs[4] is m["sigma"]
      # But not y_* in y to z, since there was no real Op in between
      assert m["z"].owner.inputs[3] is m["y"]
      assert m["y_"].owner.inputs[0] is m["y"]
      assert m["y__"].owner.inputs[0] is m["y"]
  
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 5 for calling a global function with example usage: test_deterministics(inline_views) without return types