BlockEncoding.resources#

BlockEncoding.resources(*operands: QuantumVariable, meas_behavior: str | Callable = '0', max_qubits: int = 1024, max_allocations: int = 1000)[source]#

Estimate the quantum resources required for the BlockEncoding.

This method uses the count_ops and depth decorators to obtain gate counts, circuit depth, and (in future release) qubit usage for a single execution of block-encoding .unitary. Unlike apply_rus(), it does not run the simulator and does not include repetitions from the Repeat-Until-Success procedure.

Parameters:
*operandsQuantumVariable

QuantumVariables serving as operands for the block-encoding.

meas_behaviorstr or callable, optional

Specifies the measurement outcome to assume during the tracing process (e.g., “0”, or “1”). The default is “0”.

max_qubitsint, optional

The maximum number of qubits supported for depth computation. Default is 1024.

max_allocationsint, optional

The maximum number of allocation/deallocation events supported for tracking. Default is 1000.

Returns:
dict

A dictionary containing resource metrics with the following structure:

  • “gate counts” : A dictionary of counted quantum operations.

  • “depth”: The circuit depth as an integer.

Raises:
ValueError

If the number of provided operands does not match the required number of operands (self.num_ops).

Examples

Example 1: Estimate the quantum resources for a block-encoded Pauli operator.

from qrisp import *
from qrisp.block_encodings import BlockEncoding
from qrisp.operators import X, Z

H = X(0)*X(1) + 0.5*Z(0)*Z(1)
BE = BlockEncoding.from_operator(H)

res_dict = BE.resources(QuantumFloat(2))
print(res_dict)
# {'gate counts': {'x': 3, 'cz': 2, 'u3': 2, 'cx': 4, 'gphase': 2},
# 'depth': 12, 'qubits': 4}

Example 2: Estimate the quantum resources for applying the Quantum Eigenvalue Transform.

from qrisp import *
from qrisp.algorithms.gqsp import QET
from qrisp.block_encodings import BlockEncoding
from qrisp.operators import X, Z

H = X(0)*X(1) + 0.5*Z(0)*Z(1)
BE = BlockEncoding.from_operator(H)

# real, fixed parity polynomial
p = np.array([0, 1, 0, 1])
BE_QET = QET(BE, p)

res_dict = BE_QET.resources(QuantumFloat(2))
print(res_dict)
# {'gate counts': {'x': 11, 'cz': 8, 'rx': 2, 'u3': 6, 'cx': 16,
# 'gphase': 6, 'p': 2}, 'depth': 42, 'qubits': 5}