qml.tape.TapeCircuitGraph¶

class
TapeCircuitGraph
(ops, obs, wires)[source]¶ Bases:
pennylane.circuit_graph.CircuitGraph
New circuit graph object. This will eventually grow to replace the existing CircuitGraph; for now, we simply inherit from the current CircuitGraph, and modify the instantiation so that it can be created via the quantum tape.
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.
Observables in the circuit, in a fixed topological order.
Operations in the circuit.
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.

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.

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.
Depth of the quantum circuit (longest path in the DAG).
Greedily collected layers of the circuit.
has_path
(a, b)Checks if a path exists between the two given nodes.
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.
to_openqasm
([rotations])Serialize the circuit as an OpenQASM 2.0 program.
update_node
(old, new)Replaces the given circuit graph node with a new one.
wire_indices
(wire)Operator indices on the given wire.

ancestors
(ops)¶ Ancestors of a given set of operators.

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

descendants
(ops)¶ Descendants of a given set of operators.

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

draw
(charset='unicode', show_variable_names=False)¶ 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
()¶ 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
()¶ 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
()¶ Parametrized layers of the circuit.
 Returns
layers with extra metadata
 Return type
Iterable[LayerData]

nodes_between
(a, b)¶ 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.

print_contents
()¶ Prints the contents of the quantum circuit.

serialize
()¶ 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

to_openqasm
(rotations=True)¶ Serialize the circuit as an OpenQASM 2.0 program.
Only operations are serialized; all measurements are assumed to take place in the computational basis.
Note
The serialized OpenQASM program assumes that gate definitions in
qelib1.inc
are available. Parameters
rotations (bool) – in addition to serializing userspecified operations, also include the gates that diagonalize the measured wires such that they are in the eigenbasis of the circuit observables.
 Returns
OpenQASM serialization of the circuit
 Return type
str

update_node
(old, new)¶ Replaces the given circuit graph node with a new one.

wire_indices
(wire)¶ Operator indices on the given wire.
 Parameters
wire (int) – wire to examine
 Returns
indices of operators on the wire, in temporal order
 Return type
list[int]

Contents
Using PennyLane
Development
API
Downloads