qml.io.ToBloq

class ToBloq(op, map_ops=False, custom_mapping=None, call_graph='estimator', **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 | None) – Dictionary to specify a mapping between a PennyLane operator and a Qualtran Bloq. A default mapping is used if not defined.

  • call_graph (str) – Specifies how to build the call graph. If 'estimator', the call graph is built using the resource functionality of the estimator module. If 'decomposition', the call graph is built via the PennyLane decomposition. Default is 'estimator'.

Raises:
  • TypeErrorop must be an instance of Operation, QNode, or a quantum function.

  • ValueError – If call_graph is not 'estimator' or 'decomposition'.

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 for this Bloq.

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 for this Bloq.

The call graph is built based on the call_graph_mode specified at initialization:

  • 'estimator': Uses estimate() to get gate counts.

  • 'decomposition': Builds the call graph via the PennyLane decomposition.

decompose_bloq()[source]

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