code: def test_step_and_cost_nodrain(circuit, energy_ref, pool):
      """Test that step_and_cost function returns the correct results when drain_pool is False."""
      opt = qml.AdaptiveOptimizer()
      for _ in range(4):
          circuit, energy, __ = opt.step_and_cost(
              circuit, pool, drain_pool=False
          )
  
      circuit()
      selected_excitations = [
          op.wires for op in circuit.tape.operations[1:]
      ]
  
      assert np.allclose(energy, energy_ref, rtol=1e-4)
      # assert that the operator pool is not drained, there are repeated gates in the circuit
      assert len(set(selected_excitations)) < len(selected_excitations)
  
file_path: pennylane/tests/optimize/test_adaptive.py
imports: import copy
  import pytest
  import pennylane
  from pennylane import numpy
label_desc: Use image node_id 5 for calling a global function with example usage: test_step_and_cost_nodrain(circuit, energy_ref, pool) without return types