code: def test_mixture_basics():
      def create_mix_model(size, axis):
          X_rv = pt.random.normal(0, 1, size=size, name="X")
          Y_rv = pt.random.gamma(0.5, scale=2.0, size=size, name="Y")
  
          p_at = pt.scalar("p")
          p_at.tag.test_value = 0.5
  
          I_rv = pt.random.bernoulli(p_at, size=size, name="I")
          i_vv = I_rv.clone()
          i_vv.name = "i"
  
          if isinstance(axis, Variable):
              M_rv = pt.join(axis, X_rv, Y_rv)[I_rv]
          else:
              M_rv = pt.stack([X_rv, Y_rv], axis=axis)[I_rv]
  
          M_rv.name = "M"
          m_vv = M_rv.clone()
          m_vv.name = "m"
  
          return locals()
  
      env = create_mix_model(None, 0)
      X_rv = env["X_rv"]
      I_rv = env["I_rv"]
      i_vv = env["i_vv"]
      M_rv = env["M_rv"]
      m_vv = env["m_vv"]
  
      x_vv = X_rv.clone()
      x_vv.name = "x"
  
      with pytest.raises(
          RuntimeError, match="could not be derived: {m}"
      ):
          conditional_logp({M_rv: m_vv, I_rv: i_vv, X_rv: x_vv})
  
      with pytest.raises(
          RuntimeError, match="could not be derived: {m}"
      ):
          axis_at = pt.lscalar("axis")
          axis_at.tag.test_value = 0
          env = create_mix_model((2,), axis_at)
          I_rv = env["I_rv"]
          i_vv = env["i_vv"]
          M_rv = env["M_rv"]
          m_vv = env["m_vv"]
          conditional_logp({M_rv: m_vv, I_rv: i_vv})
  
imports: import numpy
  import pytensor
  import pytensor.tensor
  import pytest
  import scipy.stats.distributions
  from pytensor import function
  from pytensor.graph.basic import Variable
  from pytensor.ifelse import ifelse
  from pytensor.tensor.random.basic import CategoricalRV
  from pytensor.tensor.shape import shape_tuple
  from pytensor.tensor.subtensor import AdvancedSubtensor, AdvancedSubtensor1, Subtensor, as_index_constant
  from pymc.logprob.abstract import MeasurableVariable
  from pymc.logprob.basic import conditional_logp, logp
  from pymc.logprob.mixture import MeasurableSwitchMixture, expand_indices
  from pymc.logprob.rewriting import construct_ir_fgraph
  from pymc.logprob.utils import dirac_delta
  from pymc.testing import assert_no_rvs
  from tests.logprob.utils import scipy_logprob
label_desc: Use image node_id 1 for calling a global function with example usage: test_mixture_basics() and returns: locals