class_docstr: Optimizer for building fully trained quantum circuits by adding gates adaptively.
  
  Quantum circuits can be built by adding gates
  `adaptively <https://www.nature.com/articles/s41467-019-10988-2>`_. The adaptive optimizer
  implements an algorithm that grows and optimizes an input quantum circuit by selecting and
  adding gates from a user-defined collection of operators. The algorithm starts by adding all
  the gates to the circuit and computing the circuit gradients with respect to the gate
  parameters. The algorithm then retains the gate which has the largest gradient and optimizes its
  parameter. The process of growing the circuit can be repeated until the computed gradients
  converge to zero within a given threshold. The optimizer returns the fully trained and
  adaptively-built circuit. The adaptive optimizer can be used to implement
  algorithms such as `ADAPT-VQE <https://www.nature.com/articles/s41467-019-10988-2>`_.
  
  Args:
      param_steps (int): number of steps for optimizing the parameter of a selected gate
      stepsize (float): step size for optimizing the parameter of a selected gate
  
  **Example**
  
  This examples shows an implementation of the
  `ADAPT-VQE <https://www.nature.com/articles/s41467-019-10988-2>`_ algorithm for building an
  adaptive circuit for the :math:`\text{H}_3^+` cation.
  
  >>> import pennylane as qml
  >>> from pennylane import numpy as np
  
  The molecule is defined and the Hamiltonian is computed with:
  
  >>> symbols = ["H", "H", "H"]
  >>> geometry = np.array([[0.01076341, 0.04449877, 0.0],
  ...                      [0.98729513, 1.63059094, 0.0],
  ...                      [1.87262415, -0.00815842, 0.0]], requires_grad=False)
  >>> H, qubits = qml.qchem.molecular_hamiltonian(symbols, geometry, charge = 1)
  
  The collection of gates to grow the circuit adaptively contains all single and double
  excitations:
  
  >>> n_electrons = 2
  >>> singles, doubles = qml.qchem.excitations(n_electrons, qubits)
  >>> singles_excitations = [qml.SingleExcitation(0.0, x) for x in singles]
  >>> doubles_excitations = [qml.DoubleExcitation(0.0, x) for x in doubles]
  >>> operator_pool = doubles_excitations + singles_excitations
  
  An initial circuit preparing the Hartree-Fock state and returning the expectation value of the
  Hamiltonian is defined:
  
  >>> hf_state = qml.qchem.hf_state(n_electrons, qubits)
  >>> dev = qml.device("default.qubit", wires=qubits)
  >>> @qml.qnode(dev)
  ... def circuit():
  ...     qml.BasisState(hf_state, wires=range(qubits))
  ...     return qml.expval(H)
  
  The optimizer is instantiated and then the circuit is created and optimized adaptively:
  
  >>> opt = AdaptiveOptimizer()
  >>> for i in range(len(operator_pool)):
  ...     circuit, energy, gradient = opt.step_and_cost(circuit, operator_pool, drain_pool=True)
  ...     print('Energy:', energy)
  ...     print(qml.draw(circuit, show_matrices=False)())
  ...     print('Largest Gradient:', gradient)
  ...     print()
  ...     if gradient < 1e-3:
  ...         break
  
  .. code-block :: pycon
  
      Energy: -1.2465499384199699
      0: ─╭|Ψ⟩─╭G²(0.20)─┤ ╭<𝓗>
      1: ─├|Ψ⟩─├G²(0.20)─┤ ├<𝓗>
      2: ─├|Ψ⟩─│─────────┤ ├<𝓗>
      3: ─├|Ψ⟩─│─────────┤ ├<𝓗>
      4: ─├|Ψ⟩─├G²(0.20)─┤ ├<𝓗>
      5: ─╰|Ψ⟩─╰G²(0.20)─┤ ╰<𝓗>
      Largest Gradient: 0.1439987277673651
  
      Energy: -1.2613740231522532
      0: ─╭|Ψ⟩─╭G²(0.20)─╭G²(0.19)─┤ ╭<𝓗>
      1: ─├|Ψ⟩─├G²(0.20)─├G²(0.19)─┤ ├<𝓗>
      2: ─├|Ψ⟩─│─────────├G²(0.19)─┤ ├<𝓗>
      3: ─├|Ψ⟩─│─────────╰G²(0.19)─┤ ├<𝓗>
      4: ─├|Ψ⟩─├G²(0.20)───────────┤ ├<𝓗>
      5: ─╰|Ψ⟩─╰G²(0.20)───────────┤ ╰<𝓗>
      Largest Gradient: 0.13493495624211427
  
      Energy: -1.2743971719772815
      0: ─╭|Ψ⟩─╭G²(0.20)─╭G²(0.19)──────────┤ ╭<𝓗>
      1: ─├|Ψ⟩─├G²(0.20)─├G²(0.19)─╭G(0.00)─┤ ├<𝓗>
      2: ─├|Ψ⟩─│─────────├G²(0.19)─│────────┤ ├<𝓗>
      3: ─├|Ψ⟩─│─────────╰G²(0.19)─╰G(0.00)─┤ ├<𝓗>
      4: ─├|Ψ⟩─├G²(0.20)────────────────────┤ ├<𝓗>
      5: ─╰|Ψ⟩─╰G²(0.20)────────────────────┤ ╰<𝓗>
      Largest Gradient: 0.0004084175253678331
docstr: Update the circuit with one step of the optimizer.
  
  Args:
      circuit (.QNode): user-defined circuit returning an expectation value
      operator_pool (list[Operator]): list of the gates to be used for adaptive optimization
      params_zero (bool): flag to initiate circuit parameters at zero
  
  Returns:
      .QNode: the optimized circuit
code: def step(self, circuit, operator_pool, params_zero=True):
      r"""Update the circuit with one step of the optimizer.
  
      Args:
          circuit (.QNode): user-defined circuit returning an expectation value
          operator_pool (list[Operator]): list of the gates to be used for adaptive optimization
          params_zero (bool): flag to initiate circuit parameters at zero
  
      Returns:
          .QNode: the optimized circuit
      """
      return self.step_and_cost(
          circuit, operator_pool, params_zero=params_zero
      )[0]
  
file_path: pennylane/pennylane/optimize/adaptive.py
imports: import copy
  from typing import Sequence, Callable
  import pennylane
  from pennylane import numpy
  from pennylane.tape import QuantumTape
  from pennylane import transform
label_desc: Use image node_id 3 for calling the AdaptiveOptimizer obj's underlying member method code with example usage: obj.step(circuit, operator_pool, params_zero) and returns: self