qml.specs

specs(qnode, max_expansion=None)[source]

Resource information about a quantum circuit.

This transform converts a QNode into a callable that provides resource information about the circuit.

Parameters

qnode (QNode) – the QNode to calculate the specifications for

Keyword Arguments

max_expansion (int) – The number of times the internal circuit should be expanded when calculating the specification. Defaults to qnode.max_expansion.

Returns

A function that has the same argument signature as qnode. This function returns a dictionary of information about qnode structure.

Example

x = np.array([0.1, 0.2])

dev = qml.device('default.qubit', wires=2)
@qml.qnode(dev)
def circuit(x, add_ry=True):
    qml.RX(x[0], wires=0)
    qml.CNOT(wires=(0,1))
    if add_ry:
        qml.RY(x[1], wires=1)
    return qml.probs(wires=(0,1))
>>> qml.specs(circuit)(x, add_ry=False)
{'gate_sizes': defaultdict(int, {1: 1, 2: 1}),
'gate_types': defaultdict(int, {'RX': 1, 'CNOT': 1}),
'num_operations': 2,
'num_observables': 1,
'num_diagonalizing_gates': 0,
'num_used_wires': 2,
'depth': 2,
'num_device_wires': 2,
'device_name': 'default.qubit.autograd',
'diff_method': 'backprop'}