class_docstr: CosineWindow(wires)
  Prepares an initial state with a cosine wave function.
  
  The wave function is defined below where :math:`m` is the number of wires.
  
  .. math::
  
      |\psi\rangle = \sqrt{2^{1-m}} \sum_{k=0}^{2^m-1} \cos(\frac{\pi k}{2^m} - \frac{\pi}{2}) |k\rangle,
  
  .. figure:: ../../_static/templates/state_preparations/cosine_window.png
      :align: center
      :width: 65%
      :target: javascript:void(0);
  
  .. note::
  
      The wave function is shifted by :math:`\frac{\pi}{2}` units so that the window is centered.
  
  For more details see `Phys. Rev. D 106 (2022) <https://journals.aps.org/prd/abstract/10.1103/PhysRevD.106.034503>`_.
  
  .. seealso:: :class:`~.QuantumPhaseEstimation` and :class:`~.QFT`.
  
  Args:
      wires (Sequence[int] or int): the wire(s) the operation acts on
  
  **Example**
  
  >>> dev = qml.device('default.qubit', wires=2)
  >>> @qml.qnode(dev)
  ... def example_circuit():
  ...     qml.CosineWindow(wires=range(2))
  ...     return qml.probs()
  >>> print(example_circuit())
  [1.87469973e-33 2.50000000e-01 5.00000000e-01 2.50000000e-01]
docstr: Calculation of the state vector generated by the cosine window.
  
  Args:
      wire_order (Iterable, Wires): Custom order of wires for the returned state vector.
  
  Raises:
      WireError: Custom wire_order must contain all wires.
  
  Returns:
      TensorLike[complex]: output state
docstr_tok: ["Calculation","of","the","state","vector","generated","by","the","cosine","window",".","Args",":","wire_order","(","Iterable",",","Wires",")",":","Custom","order","of","wires","for","the","returned","state","vector",".","Raises",":","WireError",":","Custom","wire_order","must","contain","all","wires",".","Returns",":","TensorLike","[","complex","]",":","output","state"]
code: def state_vector(
      self, wire_order=None
  ):  # pylint: disable=arguments-differ,unused-argument
      r"""Calculation of the state vector generated by the cosine window.
  
      Args:
          wire_order (Iterable, Wires): Custom order of wires for the returned state vector.
  
      Raises:
          WireError: Custom wire_order must contain all wires.
  
      Returns:
          TensorLike[complex]: output state
      """
  
      num_op_wires = len(self.wires)
      op_vector_shape = (2,) * num_op_wires
      vector = np.array(
          [
              np.sqrt(2 ** (1 - num_op_wires))
              * np.cos(-np.pi / 2 + np.pi * x / 2**num_op_wires)
              for x in range(2**num_op_wires)
          ]
      )
      op_vector = math.reshape(vector, op_vector_shape)
  
      if wire_order is None or Wires(wire_order) == self.wires:
          return op_vector
  
      wire_order = Wires(wire_order)
      if not wire_order.contains_wires(self.wires):
          raise WireError(
              f"Custom wire_order must contain all {self.name} wires"
          )
  
      indices = tuple([Ellipsis] + [slice(None)] * num_op_wires)
  
      ket_shape = [2] * num_op_wires
      ket = np.zeros(ket_shape, dtype=np.complex128)
      ket[indices] = op_vector
  
      if self.wires != wire_order[:num_op_wires]:
          current_order = self.wires + list(
              Wires.unique_wires([wire_order, self.wires])
          )
          desired_order = [current_order.index(w) for w in wire_order]
          ket = ket.transpose(desired_order)
  
      return math.convert_like(ket, op_vector)
  
file_path: pennylane/pennylane/templates/state_preparations/cosine_window.py
imports: import numpy
  import pennylane
  from pennylane.operation import StatePrepBase
  from pennylane import math
  from pennylane.wires import Wires, WireError
label_desc: Use image node_id 3 for calling the CosineWindow obj's underlying member method code with example usage: obj.state_vector(wire_order) and returns: math, op_vector