qml.CircuitGraph¶

class
CircuitGraph
(ops, variable_deps)[source]¶ Bases:
object
Represents a quantum circuit as a directed acyclic graph.
In this representation the
Operator
instances are the nodes of the graph, and each directed edge represent a subsystem (or a group of subsystems) on which the two Operators act subsequently. This representation can describe the causal relationships between arbitrary quantum channels and measurements, not just unitary gates. Parameters
ops (Iterable[Operator]) – quantum operators constituting the circuit, in temporal order
variable_deps (dict[int, list[ParameterDependency]]) – Free parameters of the quantum circuit. The dictionary key is the parameter index.
Attributes
Returns the gates that diagonalize the measured wires such that they are in the eigenbasis of the circuit observables.
The graph representation of the quantum circuit.
Creating a hash for the circuit graph based on the string generated by serialize.
Returns
True
if the circuit graph contains observables which are sampled.Observables in the circuit, in a fixed topological order.
Observables in the circuit, in a fixed topological order.
Operations in the circuit, in a fixed topological order.
Operations in the circuit, in a fixed topological order.
Identify the parametrized layer structure of the circuit.

diagonalizing_gates
¶ Returns the gates that diagonalize the measured wires such that they are in the eigenbasis of the circuit observables.
 Returns
the operations that diagonalize the observables
 Return type
List[Operation]

graph
¶ The graph representation of the quantum circuit.
The graph has nodes representing
Operator
instances, and directed edges pointing from nodes to their immediate dependents/successors. Returns
the directed acyclic graph representing the quantum circuit
 Return type
networkx.DiGraph

hash
¶ Creating a hash for the circuit graph based on the string generated by serialize.
 Returns
the hash of the serialized quantum circuit graph
 Return type
int

is_sampled
¶ Returns
True
if the circuit graph contains observables which are sampled.

observables
¶ Observables in the circuit, in a fixed topological order.
The topological order used by this method is guaranteed to be the same as the order in which the measured observables are returned by the quantum function. Currently the topological order is determined by the queue index.
 Returns
observables
 Return type
list[Observable]

observables_in_order
¶ Observables in the circuit, in a fixed topological order.
The topological order used by this method is guaranteed to be the same as the order in which the measured observables are returned by the quantum function. Currently the topological order is determined by the queue index.
 Returns
observables
 Return type
list[Observable]

operations
¶ Operations in the circuit, in a fixed topological order.
Currently the topological order is determined by the queue index.
The complement of
QNode.observables()
. Together they return everyOperator
instance in the circuit. Returns
operations
 Return type
list[Operation]

operations_in_order
¶ Operations in the circuit, in a fixed topological order.
Currently the topological order is determined by the queue index.
The complement of
QNode.observables()
. Together they return everyOperator
instance in the circuit. Returns
operations
 Return type
list[Operation]

parametrized_layers
¶ Identify the parametrized layer structure of the circuit.
 Returns
layers of the circuit
 Return type
list[Layer]
Methods
ancestors
(ops)Ancestors of a given set of operators.
ancestors_in_order
(ops)Operator ancestors in a topological order.
descendants
(ops)Descendants of a given set of operators.
descendants_in_order
(ops)Operator descendants in a topological order.
draw
([charset, show_variable_names])Draw the CircuitGraph as a circuit diagram.
Greedily collected layers of the circuit.
Operations that cannot affect the circuit output.
Parametrized layers of the circuit.
nodes_between
(a, b)Nodes on all the directed paths between the two given nodes.
Prints the contents of the quantum circuit.
Serialize the quantum circuit graph based on the operations and observables in the circuit graph and the index of the variables used by them.
update_node
(old, new)Replaces the given circuit graph node with a new one.
wire_indices
(wire)Operator indices on the given wire.

ancestors_in_order
(ops)[source]¶ Operator ancestors in a topological order.
Currently the topological order is determined by the queue index.

descendants_in_order
(ops)[source]¶ Operator descendants in a topological order.
Currently the topological order is determined by the queue index.

draw
(charset='unicode', show_variable_names=False)[source]¶ Draw the CircuitGraph as a circuit diagram.
 Parameters
charset (str, optional) – The charset that should be used. Currently, “unicode” and “ascii” are supported.
show_variable_names (bool, optional) – Show variable names instead of variable values.
 Raises
ValueError – If the given charset is not supported
 Returns
The circuit diagram representation of the
CircuitGraph
 Return type
str

greedy_layers
()[source]¶ Greedily collected layers of the circuit. Empty slots are filled with
None
.Layers are built by pushing back gates in the circuit as far as possible, so that every Gate is at the lower possible layer.
 Returns
Tuple of the circuits operations and the circuits observables, both indexed by wires.
 Return type
Tuple[list[list[Operation]], list[list[Observable]]]

invisible_operations
()[source]¶ Operations that cannot affect the circuit output.
An
Operation
instance in a quantum circuit is invisible if is not an ancestor of an observable. Such an operation cannot affect the circuit output, and usually indicates there is something wrong with the circuit. Returns
operations that cannot affect the output
 Return type
set[Operator]

iterate_parametrized_layers
()[source]¶ Parametrized layers of the circuit.
 Returns
layers with extra metadata
 Return type
Iterable[LayerData]

nodes_between
(a, b)[source]¶ Nodes on all the directed paths between the two given nodes.
Returns the set of all nodes
s
that fulfill \(a \le s \le b\). There is a directed path froma
vias
tob
iff the set is nonempty. The endpoints belong to the path.

serialize
()[source]¶ Serialize the quantum circuit graph based on the operations and observables in the circuit graph and the index of the variables used by them.
The string that is produced can be later hashed to assign a unique value to the circuit graph.
 Returns
serialized quantum circuit graph
 Return type
string
Contents
Using PennyLane
Development
API
Downloads