qp.resource.PBCSpecsResources

class PBCSpecsResources(*, counts, extra=<factory>, measurement_processes, num_wires, circuit_depth=None, any_commuting_depth, qubit_disjoint_depth)[source]

Bases: SpecsResources

Class for storing resource information for a quantum circuit with additional PBC (Pauli-Based Computation) information.

See also

SpecsResources for the base class and its fields.

Warning

This class is intended to be immutable. Modifying the attributes after creation may lead to unexpected behaviour.

Parameters:
  • any_commuting_depth (int | Expression | None) – The any commuting depth of the circuit.

  • qubit_disjoint_depth (int | Expression | None) – The qubit disjoint depth of the circuit.

any_commuting_depth

qubit_disjoint_depth

circuit_depth

counts

depth

The circuit depth (alias for circuit_depth).

extra

is_symbolic

Returns True if this object contains any symbolic variables, False otherwise.

measurement_processes

num_wires

quantum_operations

A dictionary mapping quantum operations to their counts (alias for counts).

total_quantum_operations

vars

any_commuting_depth
qubit_disjoint_depth
circuit_depth
counts
depth

The circuit depth (alias for circuit_depth).

extra
is_symbolic

Returns True if this object contains any symbolic variables, False otherwise.

measurement_processes
num_wires
quantum_operations

A dictionary mapping quantum operations to their counts (alias for counts).

total_quantum_operations
vars

subs([substitutions])

Substitute symbolic variables in the object with concrete values.

to_dict()

Convert this SpecsResources to a dictionary.

to_pretty_str([preindent])

Pretty string representation of this PBCSpecsResources object.

subs(substitutions=None, **kwargs)

Substitute symbolic variables in the object with concrete values.

Automatically iterates over all fields of the dataclass and applies substitutions to any Expression instances, so derived classes do not have to explicitly implement this method unless they want to customize the behaviour.

Note

Every Expression leaf is substituted, including those nested to arbitrary depth within registered pytree containers (dict, list, tuple, …). The original container structure is preserved.

Parameters:

substitutions (dict[str, int | float] | None) – A dictionary mapping variable names to their values. If None, an empty dictionary is used. Additional keyword arguments can also be provided.

Example

>>> from pennylane.resource import SpecsResources, Expression
>>> res = SpecsResources(
...     counts={"CNOT": Expression({("x",): 1})},
...     measurement_processes={"expval(PauliX)": 1},
...     num_wires=2,
...     circuit_depth=1,
... )

Calling this method will return a new instance of the same type which has the same structure but with the symbolic variables substituted with the provided values. A substitution may either use a dictionary or keyword arguments:

>>> res.subs({"x": 3})
SpecsResources(counts={'CNOT': 3}, measurement_processes={'expval(PauliX)': 1}, num_wires=2, circuit_depth=1, total_quantum_operations=3)
>>> res.subs(x=3)
SpecsResources(counts={'CNOT': 3}, measurement_processes={'expval(PauliX)': 1}, num_wires=2, circuit_depth=1, total_quantum_operations=3)
to_dict()

Convert this SpecsResources to a dictionary.

to_pretty_str(preindent=0)[source]

Pretty string representation of this PBCSpecsResources object.

Parameters:

preindent (int) – Number of spaces to prepend to each line.

Returns:

A pretty representation of this object.

Return type:

str