class_docstr: Test suite for algorithm AxOptimizer
class_docstr_tok: ["Test","suite","for","algorithm","AxOptimizer"]
docstr: Verify that resetting state makes sampling deterministic
docstr_tok: ["Verify","that","resetting","state","makes","sampling","deterministic"]
code: def test_state_dict(self, seed: int, phase: TestPhase):
      """Verify that resetting state makes sampling deterministic"""
      algo = self.create_algo(seed=seed)
      state = algo.state_dict
      a = algo.suggest(1)[0]
  
      # Create a new algo, without setting a seed.
  
      # The other algorithm is initialized at the start of the next phase.
      n_initial_trials = phase.end_n_trials
      # Use max_trials-1 so the algo can always sample at least one trial.
      if n_initial_trials == self.max_trials:
          n_initial_trials -= 1
  
      # NOTE: Seed is part of configuration, not state. Configuration is assumed to be the same
      #       for both algorithm instances.
      new_algo = self.create_algo(
          n_observed_trials=n_initial_trials, seed=seed
      )
      new_state = new_algo.state_dict
      b = new_algo.suggest(1)[0]
      assert a != b
  
      new_algo.set_state(state)
      c = new_algo.suggest(1)[0]
      numpy.testing.assert_allclose(
          numpy.array(list(a.params.values())).astype(float),
          numpy.array(list(c.params.values())).astype(float),
          atol=TOL,
          rtol=TOL,
      )
  
imports: import statistics
  from typing import ClassVar, List
  import pytest
  from orion.algo.axoptimizer import import_optional
  from orion.benchmark.task.base import BenchmarkTask
  from orion.core.utils import backward
  from orion.testing.algo import BaseAlgoTests, TestPhase, first_phase_only
  import numpy
  from botorch.test_functions.multi_objective import BraninCurrin
  from torch import Tensor
label_desc: Use image node_id 5 for calling the TestAxOptimizer obj's underlying member method code with example usage: obj.test_state_dict(seed, phase) without return types