class_docstr: Projector(state, wires, id=None)
  Observable corresponding to the state projector :math:`P=\ket{\phi}\bra{\phi}`.
  
  The expectation of this observable returns the value
  
  .. math::
      |\langle \psi | \phi \rangle |^2
  
  corresponding to the probability that :math:`|\psi\rangle` is projected onto :math:`|\phi\rangle` during measurement.
  
  **Details:**
  
  * Number of wires: Any
  * Number of parameters: 1
  * Gradient recipe: None
  
  Args:
      state (tensor-like): Input state of shape ``(n,)`` for a basis-state projector, or ``(2**n,)``
          for a state-vector projector.
      wires (Iterable): wires that the projector acts on.
      id (str or None): String representing the operation (optional).
  
  **Example**
  
  In the following example we consider projectors over two states: the :math:`|00\rangle` and the
  :math:`|++\rangle`. Since the first one is in the computational basis, we create its projector
  directly from its basis state representation, which is, ``zero_state=[0, 0]``. For the latter,
  we need to use its state vector form ``plusplus_state=np.array([1, 1, 1, 1])/2``.
  
  .. code-block::
  
      >>> dev = qml.device("default.qubit", wires=2)
      >>> @qml.qnode(dev)
      ... def circuit(state):
      ...     return qml.expval(qml.Projector(state, wires=[0, 1]))
      >>> zero_state = [0, 0]
      >>> circuit(zero_state)
      1.
      >>> plusplus_state = np.array([1, 1, 1, 1]) / 2
      >>> circuit(plusplus_state)
      0.25
class_docstr_tok: ["Projector","(","state",",","wires",",","id=None",")","Observable","corresponding","to","the","state","projector",":","math",":","`","P=\\ket","{","\\phi","}","\\bra","{","\\phi","}","`",".","The","expectation","of","this","observable","returns","the","value","..","math",":",":","|\\langle","\\psi","|","\\phi","\\rangle","|^2","corresponding","to","the","probability","that",":","math",":","`","|\\psi\\rangle","`","is","projected","onto",":","math",":","`","|\\phi\\rangle","`","during","measurement",".","*","*","Details",":","*","*","*","Number","of","wires",":","Any","*","Number","of","parameters",":","1","*","Gradient","recipe",":","None","Args",":","state","(","tensor-like",")",":","Input","state","of","shape","``","(","n",",",")","``","for","a","basis-state","projector",",","or","``","(","2","*","*","n",",",")","``","for","a","state-vector","projector",".","wires","(","Iterable",")",":","wires","that","the","projector","acts","on",".","id","(","str","or","None",")",":","String","representing","the","operation","(","optional",")",".","*","*","Example","*","*","In","the","following","example","we","consider","projectors","over","two","states",":","the",":","math",":","`","|00\\rangle","`","and","the",":","math",":","`","|++\\rangle","`",".","Since","the","first","one","is","in","the","computational","basis",",","we","create","its","projector","directly","from","its","basis","state","representation",",","which","is",",","``","zero_state=","[","0",",","0","]","``",".","For","the","latter",",","we","need","to","use","its","state","vector","form","``","plusplus_state=np.array","(","[","1",",","1",",","1",",","1","]",")","\/2","``",".","..","code-block",":",":",">",">",">","dev","=","qml.device","(","``","default.qubit","''",",","wires=2",")",">",">",">","@","qml.qnode","(","dev",")","...","def","circuit","(","state",")",":","...","return","qml.expval","(","qml.Projector","(","state",",","wires=","[","0",",","1","]",")",")",">",">",">","zero_state","=","[","0",",","0","]",">",">",">","circuit","(","zero_state",")","1",".",">",">",">","plusplus_state","=","np.array","(","[","1",",","1",",","1",",","1","]",")","\/","2",">",">",">","circuit","(","plusplus_state",")","0.25"]
docstr: Changes parents based on the state representation.
  
  Though all the types will be named "Projector", their *identity* and location in memory
  will be different based on whether the input state is a basis state or a state vector.
  We cache the different types in private class variables so that:
  
  >>> Projector(state, wires).__class__ is Projector(state, wires).__class__
  True
  >>> type(Projector(state, wries)) == type(Projector(state, wires))
  True
  >>> isinstance(Projector(state, wires), type(Projector(state, wires)))
  True
  >>> Projector(basis_state, wires).__class__ is Projector._basis_state_type
  True
  >>> Projector(state_vector, wires).__class__ is Projector._state_vector_type
  True
docstr_tok: ["Changes","parents","based","on","the","state","representation",".","Though","all","the","types","will","be","named","``","Projector","''",",","their","*","identity","*","and","location","in","memory","will","be","different","based","on","whether","the","input","state","is","a","basis","state","or","a","state","vector",".","We","cache","the","different","types","in","private","class","variables","so","that",":",">",">",">","Projector","(","state",",","wires",")",".__class__","is","Projector","(","state",",","wires",")",".__class__","True",">",">",">","type","(","Projector","(","state",",","wries",")",")","==","type","(","Projector","(","state",",","wires",")",")","True",">",">",">","isinstance","(","Projector","(","state",",","wires",")",",","type","(","Projector","(","state",",","wires",")",")",")","True",">",">",">","Projector","(","basis_state",",","wires",")",".__class__","is","Projector._basis_state_type","True",">",">",">","Projector","(","state_vector",",","wires",")",".__class__","is","Projector._state_vector_type","True"]
code: def __new__(cls, state, wires, **_):
      """Changes parents based on the state representation.
  
      Though all the types will be named "Projector", their *identity* and location in memory
      will be different based on whether the input state is a basis state or a state vector.
      We cache the different types in private class variables so that:
  
      >>> Projector(state, wires).__class__ is Projector(state, wires).__class__
      True
      >>> type(Projector(state, wries)) == type(Projector(state, wires))
      True
      >>> isinstance(Projector(state, wires), type(Projector(state, wires)))
      True
      >>> Projector(basis_state, wires).__class__ is Projector._basis_state_type
      True
      >>> Projector(state_vector, wires).__class__ is Projector._state_vector_type
      True
  
      """
      wires = Wires(wires)
      shape = qml.math.shape(state)
      if len(shape) != 1:
          raise ValueError(
              f"Input state must be one-dimensional; got shape {shape}."
          )
  
      if len(state) == len(wires):
          return object.__new__(BasisStateProjector)
  
      if len(state) == 2 ** len(wires):
          return object.__new__(StateVectorProjector)
  
      raise ValueError(
          "Input state should have the same length as the wires in the case "
          "of a basis state, or 2**len(wires) in case of a state vector. "
          f"The lengths for the input state and wires are {len(state)} and "
          f"{len(wires)}, respectively."
      )
  
imports: from copy import copy
  from collections.abc import Sequence
  import numpy
  from scipy.sparse import csr_matrix
  import pennylane
  from pennylane.operation import AnyWires, Observable, Operation
  from pennylane.wires import Wires
  from .matrix_ops import QubitUnitary
label_desc: Use image node_id 1 for calling the Projector obj's underlying member method code with example usage: obj.__new__(cls, state, wires) and returns: object, object