class_docstr: QSVT(UA,projectors)
  Implements the
  `quantum singular value transformation <https://arxiv.org/abs/1806.01838>`__ (QSVT) circuit.
  
  .. note ::
  
      This template allows users to define hardware-compatible block encoding and
      projector-controlled phase shift circuits. For a QSVT implementation that is
      tailored for simulators see :func:`~.qsvt` .
  
  Given an :class:`~.Operator` :math:`U`, which block encodes the matrix :math:`A`, and a list of
  projector-controlled phase shift operations :math:`\vec{\Pi}_\phi`, this template applies a
  circuit for the quantum singular value transformation as follows.
  
  When the number of projector-controlled phase shifts is even (:math:`d` is odd), the QSVT
  circuit is defined as:
  
  .. math::
  
      U_{QSVT} = \tilde{\Pi}_{\phi_1}U\left[\prod^{(d-1)/2}_{k=1}\Pi_{\phi_{2k}}U^\dagger
      \tilde{\Pi}_{\phi_{2k+1}}U\right]\Pi_{\phi_{d+1}}.
  
  
  And when the number of projector-controlled phase shifts is odd (:math:`d` is even):
  
  .. math::
  
      U_{QSVT} = \left[\prod^{d/2}_{k=1}\Pi_{\phi_{2k-1}}U^\dagger\tilde{\Pi}_{\phi_{2k}}U\right]
      \Pi_{\phi_{d+1}}.
  
  This circuit applies a polynomial transformation (:math:`Poly^{SV}`) to the singular values of
  the block encoded matrix:
  
  .. math::
  
      \begin{align}
           U_{QSVT}(A, \vec{\phi}) &=
           \begin{bmatrix}
              Poly^{SV}(A) & \cdot \\
              \cdot & \cdot
          \end{bmatrix}.
      \end{align}
  
  .. seealso::
  
      :func:`~.qsvt` and `A Grand Unification of Quantum Algorithms <https://arxiv.org/pdf/2105.02859.pdf>`_.
  
  Args:
      UA (Operator): the block encoding circuit, specified as an :class:`~.Operator`,
          like :class:`~.BlockEncode`
      projectors (Sequence[Operator]): a list of projector-controlled phase
          shifts that implement the desired polynomial
  
  Raises:
      ValueError: if the input block encoding is not an operator
  
  **Example**
  
  To implement QSVT in a circuit, we can use the following method:
  
  >>> dev = qml.device("default.qubit", wires=2)
  >>> A = np.array([[0.1]])
  >>> block_encode = qml.BlockEncode(A, wires=[0, 1])
  >>> shifts = [qml.PCPhase(i + 0.1, dim=1, wires=[0, 1]) for i in range(3)]
  >>> @qml.qnode(dev)
  >>> def example_circuit():
  ...    qml.QSVT(block_encode, shifts)
  ...    return qml.expval(qml.PauliZ(wires=0))
  
  The resulting circuit implements QSVT.
  
  >>> print(qml.draw(example_circuit)())
  0: ─╭QSVT─┤  <Z>
  1: ─╰QSVT─┤
  
  To see the implementation details, we can expand the circuit:
  
  >>> q_script = qml.tape.QuantumScript(ops=[qml.QSVT(block_encode, shifts)])
  >>> print(q_script.expand().draw(decimals=2))
  0: ─╭∏_ϕ(0.10)─╭BlockEncode(M0)─╭∏_ϕ(1.10)─╭BlockEncode(M0)†─╭∏_ϕ(2.10)─┤
  1: ─╰∏_ϕ(0.10)─╰BlockEncode(M0)─╰∏_ϕ(1.10)─╰BlockEncode(M0)†─╰∏_ϕ(2.10)─┤
  
  When working with this class directly, we can make use of any PennyLane operation
  to represent our block-encoding and our phase-shifts.
  
  >>> dev = qml.device("default.qubit", wires=[0])
  >>> block_encoding = qml.Hadamard(wires=0)  # note H is a block encoding of 1/sqrt(2)
  >>> phase_shifts = [qml.RZ(-2 * theta, wires=0) for theta in (1.23, -0.5, 4)]  # -2*theta to match convention
  >>>
  >>> @qml.qnode(dev)
  >>> def example_circuit():
  ...     qml.QSVT(block_encoding, phase_shifts)
  ...     return qml.expval(qml.PauliZ(wires=0))
  >>>
  >>> example_circuit()
  tensor(0.54030231, requires_grad=True)
  
  Once again, we can visualize the circuit as follows:
  
  >>> print(qml.draw(example_circuit)())
  0: ──QSVT─┤  <Z>
  
  To see the implementation details, we can expand the circuit:
  
  >>> q_script = qml.tape.QuantumScript(ops=[qml.QSVT(block_encoding, phase_shifts)])
  >>> print(q_script.expand().draw(decimals=2))
  0: ──RZ(-2.46)──H──RZ(1.00)──H†──RZ(-8.00)─┤
class_docstr_tok: ["QSVT","(","UA",",","projectors",")","Implements","the","`","quantum","singular","value","transformation","<","https",":","\/\/arxiv.org\/abs\/1806.01838",">","`","__","(","QSVT",")","circuit",".","..","note",":",":","This","template","allows","users","to","define","hardware-compatible","block","encoding","and","projector-controlled","phase","shift","circuits",".","For","a","QSVT","implementation","that","is","tailored","for","simulators","see",":","func",":","`","~.qsvt","`",".","Given","an",":","class",":","`","~.Operator","`",":","math",":","`","U","`",",","which","block","encodes","the","matrix",":","math",":","`","A","`",",","and","a","list","of","projector-controlled","phase","shift","operations",":","math",":","`","\\vec","{","\\Pi","}","_\\phi","`",",","this","template","applies","a","circuit","for","the","quantum","singular","value","transformation","as","follows",".","When","the","number","of","projector-controlled","phase","shifts","is","even","(",":","math",":","`","d","`","is","odd",")",",","the","QSVT","circuit","is","defined","as",":","..","math",":",":","U_","{","QSVT","}","=","\\tilde","{","\\Pi","}","_","{","\\phi_1","}","U\\left","[","\\prod^","{","(","d-1",")","\/2","}","_","{","k=1","}","\\Pi_","{","\\phi_","{","2k","}","}","U^\\dagger","\\tilde","{","\\Pi","}","_","{","\\phi_","{","2k+1","}","}","U\\right","]","\\Pi_","{","\\phi_","{","d+1","}","}",".","And","when","the","number","of","projector-controlled","phase","shifts","is","odd","(",":","math",":","`","d","`","is","even",")",":","..","math",":",":","U_","{","QSVT","}","=","\\left","[","\\prod^","{","d\/2","}","_","{","k=1","}","\\Pi_","{","\\phi_","{","2k-1","}","}","U^\\dagger\\tilde","{","\\Pi","}","_","{","\\phi_","{","2k","}","}","U\\right","]","\\Pi_","{","\\phi_","{","d+1","}","}",".","This","circuit","applies","a","polynomial","transformation","(",":","math",":","`","Poly^","{","SV","}","`",")","to","the","singular","values","of","the","block","encoded","matrix",":","..","math",":",":","\\begin","{","align","}","U_","{","QSVT","}","(","A",",","\\vec","{","\\phi","}",")","&","=","\\begin","{","bmatrix","}","Poly^","{","SV","}","(","A",")","&","\\cdot","\\\\","\\cdot","&","\\cdot","\\end","{","bmatrix","}",".","\\end","{","align","}","..","seealso",":",":",":","func",":","`","~.qsvt","`","and","`","A","Grand","Unification","of","Quantum","Algorithms","<","https",":","\/\/arxiv.org\/pdf\/2105.02859.pdf",">","`","_",".","Args",":","UA","(","Operator",")",":","the","block","encoding","circuit",",","specified","as","an",":","class",":","`","~.Operator","`",",","like",":","class",":","`","~.BlockEncode","`","projectors","(","Sequence","[","Operator","]",")",":","a","list","of","projector-controlled","phase","shifts","that","implement","the","desired","polynomial","Raises",":","ValueError",":","if","the","input","block","encoding","is","not","an","operator","*","*","Example","*","*","To","implement","QSVT","in","a","circuit",",","we","can","use","the","following","method",":",">",">",">","dev","=","qml.device","(","``","default.qubit","''",",","wires=2",")",">",">",">","A","=","np.array","(","[","[","0.1","]","]",")",">",">",">","block_encode","=","qml.BlockEncode","(","A",",","wires=","[","0",",","1","]",")",">",">",">","shifts","=","[","qml.PCPhase","(","i","+","0.1",",","dim=1",",","wires=","[","0",",","1","]",")","for","i","in","range","(","3",")","]",">",">",">","@","qml.qnode","(","dev",")",">",">",">","def","example_circuit","(",")",":","...","qml.QSVT","(","block_encode",",","shifts",")","...","return","qml.expval","(","qml.PauliZ","(","wires=0",")",")","The","resulting","circuit","implements","QSVT",".",">",">",">","print","(","qml.draw","(","example_circuit",")","(",")",")","0",":","\u2500\u256dQSVT\u2500\u2524","<","Z",">","1",":","\u2500\u2570QSVT\u2500\u2524","To","see","the","implementation","details",",","we","can","expand","the","circuit",":",">",">",">","q_script","=","qml.tape.QuantumScript","(","ops=","[","qml.QSVT","(","block_encode",",","shifts",")","]",")",">",">",">","print","(","q_script.expand","(",")",".draw","(","decimals=2",")",")","0",":","\u2500\u256d\u220f_\u03d5","(","0.10",")","\u2500\u256dBlockEncode","(","M0",")","\u2500\u256d\u220f_\u03d5","(","1.10",")","\u2500\u256dBlockEncode","(","M0",")","\u2020\u2500\u256d\u220f_\u03d5","(","2.10",")","\u2500\u2524","1",":","\u2500\u2570\u220f_\u03d5","(","0.10",")","\u2500\u2570BlockEncode","(","M0",")","\u2500\u2570\u220f_\u03d5","(","1.10",")","\u2500\u2570BlockEncode","(","M0",")","\u2020\u2500\u2570\u220f_\u03d5","(","2.10",")","\u2500\u2524","When","working","with","this","class","directly",",","we","can","make","use","of","any","PennyLane","operation","to","represent","our","block-encoding","and","our","phase-shifts",".",">",">",">","dev","=","qml.device","(","``","default.qubit","''",",","wires=","[","0","]",")",">",">",">","block_encoding","=","qml.Hadamard","(","wires=0",")","#","note","H","is","a","block","encoding","of","1\/sqrt","(","2",")",">",">",">","phase_shifts","=","[","qml.RZ","(","-2","*","theta",",","wires=0",")","for","theta","in","(","1.23",",","-0.5",",","4",")","]","#","-2","*","theta","to","match","convention",">",">",">",">",">",">","@","qml.qnode","(","dev",")",">",">",">","def","example_circuit","(",")",":","...","qml.QSVT","(","block_encoding",",","phase_shifts",")","...","return","qml.expval","(","qml.PauliZ","(","wires=0",")",")",">",">",">",">",">",">","example_circuit","(",")","tensor","(","0.54030231",",","requires_grad=True",")","Once","again",",","we","can","visualize","the","circuit","as","follows",":",">",">",">","print","(","qml.draw","(","example_circuit",")","(",")",")","0",":","\u2500\u2500QSVT\u2500\u2524","<","Z",">","To","see","the","implementation","details",",","we","can","expand","the","circuit",":",">",">",">","q_script","=","qml.tape.QuantumScript","(","ops=","[","qml.QSVT","(","block_encoding",",","phase_shifts",")","]",")",">",">",">","print","(","q_script.expand","(",")",".draw","(","decimals=2",")",")","0",":","\u2500\u2500RZ","(","-2.46",")","\u2500\u2500H\u2500\u2500RZ","(","1.00",")","\u2500\u2500H\u2020\u2500\u2500RZ","(","-8.00",")","\u2500\u2524"]
code: def label(self, decimals=None, base_label=None, cache=None):
      op_label = base_label or self.__class__.__name__
      return op_label
  
file_path: pennylane/pennylane/templates/subroutines/qsvt.py
imports: import copy
  import numpy
  import pennylane
  from pennylane.queuing import QueuingManager
  from pennylane.ops import BlockEncode, PCPhase
  from pennylane.ops.op_math import adjoint
  from pennylane.operation import AnyWires, Operation
label_desc: Use image node_id 5 for calling the QSVT obj's underlying member method code with example usage: obj.label(decimals, base_label, cache) and returns: op_label