qml.specs¶
-
specs
(qnode, max_expansion=None, expansion_strategy=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
.expansion_strategy (str) –
The strategy to use when circuit expansions or decompositions are required.
gradient
: The QNode will attempt to decompose the internal circuit such that all circuit operations are supported by the gradient method.device
: The QNode will attempt to decompose the internal circuit such that all circuit operations are natively supported by the device.
- 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]) hamiltonian = qml.dot([1.0, 0.5], [qml.X(0), qml.Y(0)]) dev = qml.device('default.qubit', wires=2) @qml.qnode(dev, diff_method="parameter-shift", shifts=np.pi / 4) def circuit(x, add_ry=True): qml.RX(x[0], wires=0) qml.CNOT(wires=(0,1)) qml.TrotterProduct(hamiltonian, time=1.0, n=4, order=2) if add_ry: qml.RY(x[1], wires=1) qml.TrotterProduct(hamiltonian, time=1.0, n=4, order=4) return qml.probs(wires=(0,1))
>>> qml.specs(circuit)(x, add_ry=False) {'resources': Resources(num_wires=2, num_gates=4, gate_types=defaultdict(<class 'int'>, {'RX': 1, 'CNOT': 1, 'TrotterPro duct': 2}}), gate_sizes=defaultdict(<class 'int'>, {1: 3, 2: 1}), depth=4, shots=Shots(total_shots=None, shot_vector=())), 'errors': {'SpectralNormError': SpectralNormError(0.42998560822421455)}, 'num_observables': 1, 'num_diagonalizing_gates': 0, 'num_trainable_params': 1, 'num_device_wires': 2, 'device_name': 'default.qubit', 'expansion_strategy': 'gradient', 'gradient_options': {'shifts': 0.7853981633974483}, 'interface': 'auto', 'diff_method': 'parameter-shift', 'gradient_fn': 'pennylane.gradients.parameter_shift.param_shift', 'num_gradient_executions': 2}