Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Represent a discrete quantum circuit operator
ResourceFunction["QuantumCircuitOperator"][{gate1,gate2,…},order,qb] represents a discrete quantum circuit operator with gates (i.e. QuantumDiscreteOperator or QuantumMeasurementOperator objects) gatei, applied to the qudits indexed by order, defined with respect to a specified QuantumBasis qb. | |
ResourceFunction["QuantumCircuitOperator"][qco,qb] transforms a specified ResourceFunction["QuantumCircuitOperator"] qco into a new QuantumBasis qb. | |
ResourceFunction["QuantumCircuitOperator"][qco,pic] transforms qco into the new quantum mechanical picture pic. |
"Operator" | association <|b11→e11,b12→e12,…|> of tensor products of basis names and matrix elements |
"Basis" | which QuantumBasis the circuit operator is defined with respect to |
"Picture" | which quantum mechanical picture the circuit operator is defined with respect to |
"BasisElements" | list of basis elements bi |
"MatrixRepresentation" | matrix representation mat of the circuit operator |
"OrderedMatrixRepresentation" | matrix representation adjusted according to the order of the circuit operator, assuming an input state containing Max[order] qudits (subsystems) |
{"OrderedMatrixRepresentation",n} | matrix representation adjusted according to the order of the circuit operator, assuming an input state containing n qudits (subsystems) |
"OperatorRepresentation" | representation of the circuit operator as a QuantumDiscreteOperator |
"Arity" | arity of the circuit operator |
"Dimensions" | dimensionality of each qudit (subsystem) in the input state for the circuit operator |
"Order" | order in which the circuit operator should be applied to qudits (subsystems) in the input state |
"HermitianQ" | whether the circuit operator is Hermitian (self-adjoint) |
"UnitaryQ" | whether the circuit operator is unitary (an automorphism of Hilbert space) |
"Eigenvalues" | eigenvalues of the matrix representation of the circuit operator |
"Eigenvectors" | eigenvectors of the matrix representation of the circuit operator |
"Gates" | list of gates (QuantumDiscreteOperator and QuantumMeasurementOperator objects) contained within the circuit operator |
"GateOperators" | list of associations <|b11→e11,b12→e12,…|> of tensor products of basis names and matrix elements for each QuantumDiscreteOperator or QuantumMeasurementOperator in the circuit |
"GateBases" | list of QuantumBasis objects for each QuantumDiscreteOperator or QuantumMeasurementOperator in the circuit |
"GatePictures" | list of quantum mechanical pictures for each QuantumDiscreteOperator or QuantumMeasurementOperator in the circuit |
"GateBasisElements" | list of lists of basis elements bi for each QuantumDiscreteOperator or QuantumMeasurementOperator in the circuit |
"GateMatrixRepresentations" | list of matrix representations mat for each QuantumDiscreteOperator or QuantumMeasurementOperator in the circuit |
"GateOrderedMatrixRepresentations" | list of ordered matrix representations for each QuantumDiscreteOperator or QuantumMeasurementOperator in the circuit, assuming an input state containing Max[Max/@orders] qudits (subsystems) |
{"GateOrderedMatrixRepresentations",n} | list of ordered matrix representations for each QuantumDiscreteOperator or QuantumMeasurementOperator in the circuit, assuming an input state containing n qudits (subsystems) |
"GateArities" | list of arities for each QuantumDiscreteOperator or QuantumMeasurementOperator in the circuit |
"GateDimensions" | list of qudit dimensionalities for each QuantumDiscreteOperator or QuantumMeasurementOperator in the circuit |
"GateOrders" | list of qudit application orders for each QuantumDiscreteOperator or QuantumMeasurementOperator in the circuit |
"Diagram" | diagrammatic representation of the circuit operator |
"Properties" | list of all property names |
"S" | S-gate (equivalent to a π/2 PHASE gate) |
"T" | T-gate (equivalent to a π/4 PHASE gate) |
"CNOT" | CNOT gate for qubits (controlled NOT - equivalent to a CX gate) |
{"CNOT",d} | CNOT gate for d-dimensional qudits |
"CPHASE" | CPHASE gate for qubits (controlled π PHASE gate) |
{"CPHASE",d} | CPHASE gate for d-dimensional qudits |
"CX" | CX gate for qubits (controlled Pauli-X gate - equivalent to a CNOT gate) |
{"CX",d} | CX gate for d-dimensional qudits |
"CY" | CY gate for qubits (controlled Pauli-Y gate) |
"CZ" | CZ gate for qubits (controlled Pauli-Z gate) |
{"CZ",d} | CZ gate for d-dimensional qudits |
"Fourier" | QFT gate for qubits (quantum Fourier transform) |
{"Fourier",d} | QFT gate for d-dimensional qudits |
"InverseFourier" | IQFT gate for qubits (inverse quantum Fourier transform) |
{"InverseFourier",d} | IQFT gate for d-dimensional qudits |
"SWAP" | SWAP gate for qubits (swap two qubits) |
{"SWAP",d} | SWAP gate for d-dimensional qudits |
"RootSWAP" | square root of the SWAP gate for qubits (half swap two qubits) |
{"RootSWAP",d} | square root of the SWAP gate for d-dimensional qudits |
"SUM" | SUM gate for qubits (half-adder for qubits - equivalent to a CNOT gate) |
{"SUM",d} | SUM gate for d-dimensional qudits |
"PauliX" | Pauli-X gate for qubits (equivalent to a π rotation around the x axis of the Bloch sphere) |
{"PauliX",d} | Pauli-X gate for d-dimensional qudits |
"PauliY" | Pauli-Y gate for qubits (equivalent to a π rotation around the y axis of the Bloch sphere) |
"PauliZ" | Pauli-Z gate for qubits (equivalent to a π rotation around the z axis of the Bloch sphere) |
{"PauliZ",d} | Pauli-Z gate for d-dimensional qudits |
"RootNOT" | square root of the Pauli-X gate for qubits (half NOT operation on one qubit) |
{"RootNOT",d} | square root of the Pauli-X gate for d-dimensional qudits |
"Hadamard" | Hadamard gate for qubits (equivalent to a QFT gate on one qubit) |
"Toffoli" | Toffoli gate on 3 qubits (equivalent to a π/2 Deutsch gate) |
{"Toffoli",n} | Toffoli gate on n qubits |
"CSWAP" | controlled SWAP gate for qubits (Fredkin gate) |
"PauliX" | measurement operator based on the Pauli-X gate for qubits (equivalent to a π rotation around the x axis of the Bloch sphere) |
{"PauliX",d} | measurement operator based on the Pauli-X gate for d-dimensional qudits (not Hermitian for general d>2) |
"PauliY" | measurement operator based on the Pauli-Y gate for qubits (equivalent to a π rotation around the y axis of the Bloch sphere) |
"PauliZ" | measurement operator based on the Pauli-Z gate for qubits (equivalent to a π rotation around the z axis of the Bloch sphere) |
{"PauliZ",d} | measurement operator based on the Pauli-Z gate for d-dimensional qudits (not Hermitian for general d>2) |
"Hadamard" | measurement operator based on the Hadamard gate for qubits (equivalent to a QFT gate on one qubit) |
"ComputationalBasis" | measurement in the 2-dimensional computational basis |
{"ComputationalBasis",d} | measurement in the d-dimensional computational basis |
{"ComputationalBasis",d,eigs} | measurement in the d-dimensional computational basis with eigenvalues (i.e. measurement outcomes) eigs |
"BellBasis" | measurement in the Bell basis |
{"BellBasis",eigs} | measurement in the Bell basis with eigenvalues (i.e. measurement outcomes) eigs |
"PauliBasis" | measurement in the basis of Pauli matrices |
{"PauliBasis",eigs} | measurement in the basis of Pauli matrices with eigenvalues (i.e. measurement outcomes) eigs |
"FourierBasis" | measurement in the 2-dimensional basis of the quantum Fourier transform |
{"FourierBasis",d} | measurement in the d-dimensional basis of the quantum Fourier transform |
{"FourierBasis",d,eigs} | measurement in the d-dimensional basis of the quantum Fourier transform with eigenvalues (i.e. measurement outcomes) eigs |
Create a discrete quantum circuit operator in the computational basis consisting of a Hadamard gate and a Pauli-Z gate applied in series:
In[1]:= | ![]() |
Out[1]= | ![]() |
Show the diagrammatic representation:
In[2]:= | ![]() |
Out[2]= | ![]() |
In[3]:= | ![]() |
Out[3]= | ![]() |
Apply the circuit operator to the first qubit (default) of a two-qubit discrete quantum state in the computational basis:
In[4]:= | ![]() |
Out[4]= | ![]() |
In[5]:= | ![]() |
Out[5]= | ![]() |
Apply the circuit operator to the second qubit of the state instead:
In[6]:= | ![]() |
Out[6]= | ![]() |
In[7]:= | ![]() |
Out[7]= | ![]() |
Apply the Hadamard and Pauli-Z gates in parallel to qubits 1 and 2 instead:
In[8]:= | ![]() |
Out[8]= | ![]() |
In[9]:= | ![]() |
Out[9]= | ![]() |
In[10]:= | ![]() |
Out[10]= | ![]() |
Create a discrete quantum circuit operator in the computational basis consisting of a CNOT gate with control qubit 2 and "active" qubit 3, followed by a SWAP gate for qubits 1 and 3, followed by a quantum Fourier transform gate for qubits 1, 2 and 3:
In[11]:= | ![]() |
Out[12]= | ![]() |
Return its matrix representation:
In[13]:= | ![]() |
Out[13]= | ![]() |
Return the ordered matrix representation (assuming a state of size 4):
In[14]:= | ![]() |
Out[14]= | ![]() |
In[15]:= | ![]() |
Out[15]= | ![]() |
In[16]:= | ![]() |
Out[16]= | ![]() |
In[17]:= | ![]() |
Out[18]= | ![]() |
Return the new ordered matrix representation (assuming a state of size 4):
In[19]:= | ![]() |
Out[19]= | ![]() |
Create a discrete quantum circuit operator in the computational basis consisting of an inverse quantum Fourier transform gate for qubits 1 and 2, followed by a computational basis measurement gate for qubit 2:
In[20]:= | ![]() |
Out[21]= | ![]() |
In[22]:= | ![]() |
Out[23]= | ![]() |
By default, all discrete quantum circuit operators are created in the Schrodinger picture:
In[24]:= | ![]() |
Out[25]= | ![]() |
Circuit operators in the Schrodinger picture can be applied to QuanumDiscreteState objects:
In[26]:= | ![]() |
Out[27]= | ![]() |
However, they cannot be applied to other operators (i.e. QuantumDiscreteOperator objects, QuantumMeasurementOperator objects or QuantumHamiltonianOperator objects). Doing so will return unevaluated:
In[28]:= | ![]() |
Out[29]= | ![]() |
On the other hand, circuit operators created in the Heisenberg picture cannot be applied to QuantumDiscreteState objects (will return unevaluated):
In[30]:= | ![]() |
Out[31]= | ![]() |
In[32]:= | ![]() |
Out[32]= | ![]() |
However, they can be applied to other operators in the Heisenberg picture (i.e. QuantumDiscreteOperator objects, QuantumMeasurementOperator objects or QuantumHamiltonianOperator objects):
In[33]:= | ![]() |
Out[34]= | ![]() |
In[35]:= | ![]() |
Out[36]= | ![]() |
In[37]:= | ![]() |
Out[38]= | ![]() |
Apply a discrete quantum circuit operator (without measurement gates) to a QuantumMeasurement object:
In[39]:= | ![]() |
Out[40]= | ![]() |
Show the resulting (evolved) states:
In[41]:= | ![]() |
Out[41]= | ![]() |
Apply a discrete quantum circuit operator (with measurement gates) to a QuantumMeasurement object:
In[42]:= | ![]() |
Out[43]= | ![]() |
Show the resulting joint distribution:
In[44]:= | ![]() |
Out[44]= | ![]() |
Create a discrete quantum circuit operator in the computational basis (default):
In[45]:= | ![]() |
Out[46]= | ![]() |
In[47]:= | ![]() |
Out[47]= | ![]() |
Transform the circuit operator to the Fourier basis:
In[48]:= | ![]() |
Out[49]= | ![]() |
In[50]:= | ![]() |
Out[50]= | ![]() |
Transform the circuit operator back to the computational basis:
In[51]:= | ![]() |
Out[52]= | ![]() |
In[53]:= | ![]() |
Out[53]= | ![]() |
Represent a discrete quantum circuit operator in the Heisenberg picture:
In[54]:= | ![]() |
Out[54]= | ![]() |
In[55]:= | ![]() |
Out[55]= | ![]() |
Transform the circuit to the interaction picture:
In[56]:= | ![]() |
Out[56]= | ![]() |
In[57]:= | ![]() |
Out[57]= | ![]() |
Represent a two-qubit discrete quantum circuit operator in the computational basis:
In[58]:= | ![]() |
Out[59]= | ![]() |
In[60]:= | ![]() |
Out[60]= | ![]() |
Represent the same circuit operator in the Pauli-X basis instead:
In[61]:= | ![]() |
Out[62]= | ![]() |
In[63]:= | ![]() |
Out[63]= | ![]() |
Circuit operators in the Schrodinger picture can be applied to QuantumDiscreteState objects that are also in the Schrodinger picture:
In[64]:= | ![]() |
Out[65]= | ![]() |
In[66]:= | ![]() |
Out[67]= | ![]() |
In[68]:= | ![]() |
Out[68]= | ![]() |
However, they cannot be applied to other operators in the Schrodinger picture (returns unevaluated):
In[69]:= | ![]() |
Out[69]= | ![]() |
In[70]:= | ![]() |
Out[70]= | ![]() |
Likewise, circuit operators in the "PhaseSpace" picture can be applied to QuantumDiscreteState objects in the "PhaseSpace" picture:
In[71]:= | ![]() |
Out[72]= | ![]() |
In[73]:= | ![]() |
Out[74]= | ![]() |
In[75]:= | ![]() |
Out[75]= | ![]() |
But they cannot be applied to other operators in the phase space picture (returns unevaluated):
In[76]:= | ![]() |
Out[76]= | ![]() |
In[77]:= | ![]() |
Out[77]= | ![]() |
On the other hand, circuit operators in the Heisenberg picture cannot be applied to QuantumDiscreteState objects in the Heisenberg picture:
In[78]:= | ![]() |
Out[79]= | ![]() |
In[80]:= | ![]() |
Out[81]= | ![]() |
But they can be applied to other operators in the Heisenberg picture:
In[82]:= | ![]() |
Out[82]= | ![]() |
In[83]:= | ![]() |
Out[83]= | ![]() |
Finally, circuit operators in the Interaction picture can be applied to both QuantumDiscreteState objects in the Interaction picture:
In[84]:= | ![]() |
Out[85]= | ![]() |
In[86]:= | ![]() |
Out[87]= | ![]() |
And also to other operators in the Interaction picture:
In[88]:= | ![]() |
Out[88]= | ![]() |
In[89]:= | ![]() |
Out[89]= | ![]() |
In general, the quantum mechanical picture of a QuantumCircuitOperator and the object that it is being applied to must match.
QuantumCircuitOperator objects can be composed by application:
In[90]:= | ![]() |
Out[91]= | ![]() |
In[92]:= | ![]() |
Out[93]= | ![]() |
In[94]:= | ![]() |
Out[95]= | ![]() |
Circuits can also be composed by including them as "gates" in the specification of other circuits:
In[96]:= | ![]() |
Out[97]= | ![]() |
Show the circuit diagram for an S-gate (a π/2 phase change gate):
In[98]:= | ![]() |
Out[99]= | ![]() |
Show the circuit diagram for an S-gate with a control qubit:
In[100]:= | ![]() |
Out[101]= | ![]() |
Show the circuit diagram for a T-gate (a π/4 phase change gate):
In[102]:= | ![]() |
Out[103]= | ![]() |
Show the circuit diagram for a T-gate with a control qubit:
In[104]:= | ![]() |
Out[105]= | ![]() |
Show the circuit diagram for a CNOT gate (a controlled NOT gate—equivalent to a controlled Pauli-X gate):
In[106]:= | ![]() |
Out[107]= | ![]() |
Show the circuit diagram for a Pauli-X gate (a π rotation around the x axis of the Bloch sphere):
In[108]:= | ![]() |
Out[109]= | ![]() |
Show the circuit diagram for a Pauli-Y gate (a π rotation around the y axis of the Bloch sphere):
In[110]:= | ![]() |
Out[111]= | ![]() |
Show the circuit diagram for a controlled Pauli-Y gate:
In[112]:= | ![]() |
Out[113]= | ![]() |
Show the circuit diagram for a Pauli-Z gate (a π rotation around the z axis of the Bloch sphere):
In[114]:= | ![]() |
Out[115]= | ![]() |
Show the circuit diagram for a controlled Pauli-Z gate:
In[116]:= | ![]() |
Out[117]= | ![]() |
Show the circuit diagram for a two-qubit QFT gate (quantum Fourier transform):
In[118]:= | ![]() |
Out[119]= | ![]() |
Show the circuit diagram for a two-qubit QFT gate with a control qubit:
In[120]:= | ![]() |
Out[121]= | ![]() |
Show the circuit diagram for a two-qubit IQFT gate (inverse quantum Fourier transform):
In[122]:= | ![]() |
Out[123]= | ![]() |
Show the circuit diagram for a two-qubit IQFT gate with a control qubit:
In[124]:= | ![]() |
Out[125]= | ![]() |
Show the circuit diagram for a SWAP gate:
In[126]:= | ![]() |
Out[127]= | ![]() |
Show the circuit diagram for a SWAP gate with a control qubit:
In[128]:= | ![]() |
Out[129]= | ![]() |
Show the circuit diagram for the square root of a SWAP gate (half swaps two qubits):
In[130]:= | ![]() |
Out[131]= | ![]() |
Show the circuit diagram for the square root of a SWAP gate with a control qubit:
In[132]:= | ![]() |
Out[133]= | ![]() |
Show the circuit diagram for a Hadamard gate (a single-qubit quantum Fourier transform):
In[134]:= | ![]() |
Out[135]= | ![]() |
Show the circuit diagram for a Hadamard gate with a control qubit:
In[136]:= | ![]() |
Out[137]= | ![]() |
Show the circuit diagram for a positive operator-valued discrete quantum measurement:
In[138]:= | ![]() |
Out[139]= | ![]() |
Show the circuit diagram for a Pauli-X measurement gate (a π rotation around the x axis of the Bloch sphere):
In[140]:= | ![]() |
Out[141]= | ![]() |
Show the circuit diagram for a Pauli-Y measurement gate (a π rotation around the y axis of the Bloch sphere):
In[142]:= | ![]() |
Out[143]= | ![]() |
Show the circuit diagram for a Pauli-Z measurement gate (a π rotation around the z axis of the Bloch sphere):
In[144]:= | ![]() |
Out[145]= | ![]() |
Show the circuit diagram for a Hadamard measurement gate (a single-qubit quantum Fourier transform):
In[146]:= | ![]() |
Out[147]= | ![]() |
Show the circuit diagram for a single-qubit computational basis measurement (with default eigenvalues):
In[148]:= | ![]() |
Out[149]= | ![]() |
Show the circuit diagram for a two-qubit computational basis measurement (with default eigenvalues):
In[150]:= | ![]() |
Out[151]= | ![]() |
Show the circuit diagram for a single-qubit Bell basis measurement (with default eigenvalues):
In[152]:= | ![]() |
Out[153]= | ![]() |
Show the circuit diagram for a two-qubit Bell basis measurement (with default eigenvalues):
In[154]:= | ![]() |
Out[155]= | ![]() |
Show the circuit diagram for a single-qubit Fourier basis measurement:
In[156]:= | ![]() |
Out[157]= | ![]() |
Show the circuit diagram for a two-qubit Fourier basis measurement:
In[158]:= | ![]() |
Out[159]= | ![]() |
View a list of properties that can be extracted from a QuantumCircuitOperator object:
In[160]:= | ![]() |
Out[160]= | ![]() |
In[161]:= | ![]() |
Out[161]= | ![]() |
Return the circuit operator association:
In[162]:= | ![]() |
Out[162]= | ![]() |
Return which QuantumBasis the circuit operator is defined with respect to:
In[163]:= | ![]() |
Out[163]= | ![]() |
Return which quantum mechanical picture the circuit operator is defined with respect to:
In[164]:= | ![]() |
Out[164]= | ![]() |
Return the association of names and basis elements:
In[165]:= | ![]() |
Out[165]= | ![]() |
Return the matrix representation:
In[166]:= | ![]() |
Out[166]= | ![]() |
Return the ordered matrix representation (when applied to qubits 2 and 3), assuming a state consisting of 3 qubits:
In[167]:= | ![]() |
Out[167]= | ![]() |
Return the ordered matrix representation (when applied to qubits 2 and 3), assuming a state consisting of 4 qubits:
In[168]:= | ![]() |
Out[168]= | ![]() |
Return the representation as a QuantumDiscreteOperator:
In[169]:= | ![]() |
Out[169]= | ![]() |
Return the arity (number of input subsystems):
In[170]:= | ![]() |
Out[170]= | ![]() |
Return the number of dimensions:
In[171]:= | ![]() |
Out[171]= | ![]() |
Return the order in which the circuit operator is applied to subsystems:
In[172]:= | ![]() |
Out[172]= | ![]() |
Determine whether the circuit operator is Hermitian:
In[173]:= | ![]() |
Out[173]= | ![]() |
Determine whether the circuit operator is unitary:
In[174]:= | ![]() |
Out[174]= | ![]() |
Return the list of eigenvalues:
In[175]:= | ![]() |
Out[175]= | ![]() |
Return the list of eigenvectors:
In[176]:= | ![]() |
Out[176]= | ![]() |
Return the list of gates in the circuit:
In[177]:= | ![]() |
Out[177]= | ![]() |
Return the list of operator associations for each gate:
In[178]:= | ![]() |
Out[178]= | ![]() |
Return the list of QuantumBasis objects for each gate:
In[179]:= | ![]() |
Out[179]= | ![]() |
Return the list of quantum mechanical pictures for each gate:
In[180]:= | ![]() |
Out[180]= | ![]() |
Return the list of associations of names and basis elements for each gate:
In[181]:= | ![]() |
Out[181]= | ![]() |
Return the list of matrix representations for each gate:
In[182]:= | ![]() |
Out[182]= | ![]() |
Return the list of ordered matrix representations for each gate, assuming a state consisting of 3 qubits:
In[183]:= | ![]() |
Out[183]= | ![]() |
Return the list of ordered matrix representations for each gate, assuming a state consisting of 4 qubits:
In[184]:= | ![]() |
Out[184]= | ![]() |
Return the list of arities (number of input subsystems) for each gate:
In[185]:= | ![]() |
Out[185]= | ![]() |
Return the list of numbers of dimensions for each gate:
In[186]:= | ![]() |
Out[186]= | ![]() |
Return the list of orders in which the gates are applied to subsystems:
In[187]:= | ![]() |
Out[187]= | ![]() |
Show the diagrammatic representation of the circuit operator:
In[188]:= | ![]() |
Out[188]= | ![]() |
Represent a three-qubit quantum Fourier transform as a composition of Hadamard gates, controlled S-phase and T-phase gates and a single SWAP operation at the end:
In[189]:= | ![]() |
Out[190]= | ![]() |
Apply the circuit operator to a random three-qubit discrete quantum state:
In[191]:= | ![]() |
Out[192]= | ![]() |
Compare the matrix representation of the circuit operator to the matrix representation of the standard three-qubit quantum Fourier transform:
In[193]:= | ![]() |
Out[193]= | ![]() |
Compare the effect of the standard three-qubit quantum Fourier transform on the random state from a previous example:
In[194]:= | ![]() |
Out[194]= | ![]() |
Represent a Hadamard test circuit (for creating a random variable whose expected value is the expected real part of the observed value of a quantum state with respect to some unitary operator):
In[195]:= | ![]() |
Out[196]= | ![]() |
Apply the circuit operator to a random three-qubit discrete quantum state:
In[197]:= | ![]() |
Out[198]= | ![]() |
Represent a quantum parity check circuit (for determining the expected number of 1s in an arbitrary string of qubits), shown here for the three-qubit case:
In[199]:= | ![]() |
Out[200]= | ![]() |
Apply the circuit operator to a random four-qubit discrete quantum state:
In[201]:= | ![]() |
Out[202]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License