code: def test_sampler_stats(self):
      with pm.Model() as model:
          pm.Normal("x", mu=0, sigma=1)
          with warnings.catch_warnings():
              warnings.filterwarnings(
                  "ignore", ".*number of samples.*", UserWarning
              )
              trace = pm.sample(
                  draws=10, tune=1, chains=1, return_inferencedata=False
              )
  
      # Assert stats exist and have the correct shape.
      expected_stat_names = {
          "depth",
          "diverging",
          "energy",
          "energy_error",
          "model_logp",
          "max_energy_error",
          "mean_tree_accept",
          "step_size",
          "step_size_bar",
          "tree_size",
          "tune",
          "perf_counter_diff",
          "perf_counter_start",
          "process_time_diff",
          "reached_max_treedepth",
          "index_in_trajectory",
          "largest_eigval",
          "smallest_eigval",
          "warning",
      }
      assert trace.stat_names == expected_stat_names
      for varname in trace.stat_names:
          if varname == "warning":
              # Warnings don't squeeze reliably.
              # But once we stop squeezing altogether that's going to be OK.
              # See https://github.com/pymc-devs/pymc/issues/6207
              continue
          assert trace.get_sampler_stats(varname).shape == (10,)
  
      # Assert model logp is computed correctly: computing post-sampling
      # and tracking while sampling should give same results.
      model_logp_fn = model.compile_logp()
      model_logp_ = np.array(
          [
              model_logp_fn(trace.point(i, chain=c))
              for c in trace.chains
              for i in range(len(trace))
          ]
      )
      assert (trace.model_logp == model_logp_).all()
  
imports: import logging
  import sys
  import warnings
  import numpy
  import pytensor.tensor
  import pytest
  import pymc
  from pymc.exceptions import SamplingError
  from pymc.pytensorf import floatX
  from pymc.step_methods.hmc import NUTS
  from tests import sampler_fixtures
  from tests.helpers import RVsAssignmentStepsTester, StepMethodTester
label_desc: Use image node_id 5 for calling the TestNutsCheckTrace obj's underlying member method code with example usage: obj.test_sampler_stats() without return types