Plot quantum circuit or composite gate
Installation Required: This functionality requires MATLAB Support Package for Quantum Computing.
plot( plots into the
specified parent container instead of the current container. The argument
parent can precede any of the input argument combinations in the
Create and Plot Quantum Circuit
Create a quantum circuit that consists of a Hadamard gate and a controlled X gate to entangle two qubits.
gates = [hGate(1); cxGate(1,2)]; c = quantumCircuit(gates);
Plot the circuit.
Plot Quantum Circuit with Lines Separating Qubit Blocks
Create a quantum circuit that consists of four controlled controlled X (CCX) gates.
gates = ccxGate([1 3 4 5],[2 6 7 8],[6 7 8 9]); c = quantumCircuit(gates);
Plot the circuit with lines separating the qubit blocks. The qubit blocks to be separated are the first 5 qubits, followed by the next 3 qubits, and the last 1 qubit. The first 5 qubits are the first control qubits of each of the four CCX gates as well as the second control qubit of the first gate. The next 3 qubits are the second control qubits of the rest of the CCX gates. And the last 1 qubit is the final target qubit that holds the result of applying the last CCX gate.
plot(c,QubitBlocks=[5 3 1])
Plot Quantum Circuit That Contains Composite Gates
Create an array of inner gates consisting of a Hadamard gate and a controlled X gate to entangle two qubits.
gates = [hGate(1); cxGate(1,2)];
Construct two composite gates from the array of inner gates. Name the two composite
"bell". The first composite gate acts on qubits 1 and 3 of
the outer circuit containing this gate. The second composite gate acts on qubits 2 and 4
of the outer circuit containing this gate.
cg1 = compositeGate(gates,[1 3],Name="bell"); cg2 = compositeGate(gates,[2 4],Name="bell");
Create a quantum circuit that contains these two composite gates.
circuit = quantumCircuit([cg1; cg2])
circuit = quantumCircuit with properties: NumQubits: 4 Gates: [2×1 quantum.gate.CompositeGate] Name: ""
Plot the circuit.
In a circuit diagram, each solid horizontal line represents a qubit. The top line is a qubit with index 1 and the remaining lines from top to bottom are labeled sequentially. In this example, the plotted circuit consists of four qubits with indices 1, 2, 3, and 4. The plot shows that qubits 1 and 3 of the circuit are mapped to qubits 1 and 2 of the inner gates of the first composite gate, and qubits 2 and 4 of the circuit are mapped to qubits 1 and 2 of the inner gates of the second composite gate.
Click one of the composite gate blocks in the plot. A new figure showing the internal gates of the composite gate appears.
Specify Location of Qubit Line Labels
Create and plot a quantum circuit that consists of a Hadamard gate
and a controlled X gate to entangle two qubits. Return the
QuantumCircuitChart object by specifying an output argument to
gates = [hGate(1); cxGate(1,2)]; c = quantumCircuit(gates); p = plot(c);
Display qubit labels on the left by modifying properties of the chart object.
p.QubitLabelLocation = "left";
parent — Parent container
Figure object (default) |
Panel object |
Tab object |
Parent container of the chart, specified as a
TiledChartLayout object. If you do not specify a parent container,
plot uses the current container.
Specify optional pairs of arguments as
the argument name and
Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
The quantum circuit chart properties listed here are only a subset. For a complete list, see QuantumCircuitChart Properties.
QubitBlocks — Block sizes to separate in plot
Block sizes to separate in the plot, specified as a vector of integers. Each element of the vector specifies the size of one block of qubits. The sum of the block sizes must equal the number of qubits in the circuit.
[3 2 1]
NumRows — Number of rows to wrap circuit over
positive integer scalar
Number of rows to wrap the circuit over, specified as a positive integer scalar.
If you do not specify
automatically determines the number of rows.
QubitLabelLocation — Location of qubit line labels
Location of qubit line labels, specified as
If you do not specify
plot automatically determines the label locations.
On a plotted quantum circuit or composite gate, you can move your mouse over the gate symbols (on the corners of the box symbol or on the markers of the gate symbol) to show additional information about the individual gates. This information includes the gate name, the gate index in the circuit, and the specified angle for the gate operation.
You can click on a plotted composite gate to open a new figure with the internal gates of the composite gate.
Version HistoryIntroduced in R2023a
R2023b: Control circuit plot appearance and behavior
When you plot a circuit or composite gate with the
plot method, you
can now specify an output argument to return a
Set properties of the object to control the appearance and behavior of the circuit plot. See
QuantumCircuitChart Properties for more information.