qml.io.ToBloq

class ToBloq(op, map_ops=False, custom_mapping=None, **kwargs)[source]

Bases: object

An adapter to convert a PennyLane QNode, Qfunc, or Operation to a Qualtran Bloq.

Note

This class requires the latest version of Qualtran. We recommend installing the latest release via pip:

pip install qualtran
Parameters:
  • op (QNode| Qfunc | Operation) – a PennyLane QNode, Qfunc, or operator to be wrapped as a Qualtran Bloq.

  • map_ops (bool) – Whether to map operations to a Qualtran Bloq. Operations are wrapped as a ToBloq when False. Default is True.

  • custom_mapping (dict) – Dictionary to specify a mapping between a PennyLane operator and a Qualtran Bloq. A default mapping is used if not defined.

Raises:

TypeError – operator must be an instance of Operation.

See also

to_bloq() for the recommended way to convert from PennyLane objects to their Qualtran equivalents

Example

This example shows how to use qml.ToBloq:

>>> from qualtran.resource_counting.generalizers import generalize_rotation_angle
>>> op = qml.QuantumPhaseEstimation(
...     qml.RX(0.2, wires=[0]), estimation_wires=[1, 2]
... )
>>> op_as_bloq = qml.ToBloq(op)
>>> graph, sigma = op_as_bloq.call_graph(generalize_rotation_angle)
>>> sigma
{Hadamard(): 4,
Controlled(subbloq=Rx(angle=0.2, eps=1e-11), ctrl_spec=CtrlSpec(qdtypes=(QBit(),), cvs=(array(1),))): 3,
TwoBitSwap(): 1,
CNOT(): 2,
ZPowGate(exponent=\phi, eps=5e-12): 2,
ZPowGate(exponent=\phi, eps=1e-11): 1}

signature

Compute and return Qualtran signature for given op or QNode.

signature

Compute and return Qualtran signature for given op or QNode.

build_call_graph(ssa)

Build Qualtran call graph with defined call graph if available, otherwise build said call graph with the decomposition

decompose_bloq()

Decompose the bloq using the op's decomposition or the tape of the QNode

build_call_graph(ssa)[source]

Build Qualtran call graph with defined call graph if available, otherwise build said call graph with the decomposition

decompose_bloq()[source]

Decompose the bloq using the op’s decomposition or the tape of the QNode