Skip to main content
added 125 characters in body
Source Link
SimoneGasperini
  • 1.6k
  • 1
  • 3
  • 18

Qiskit provides the qiskit.quantum_info.Operator class to get the unitary matrix operator from the corresponding quantum circuit, as in the following example:

from qiskit import QuantumCircuit
from qiskit.quantum_info import Operator
from qiskit.visualization import array_to_latex

qc = QuantumCircuit(2)
qc.h(0)

op = Operator(qc)
array_to_latex(op)

\begin{bmatrix} \frac{1}{\sqrt2} & \frac{1}{\sqrt2} & 0 & 0\\ \frac{1}{\sqrt2} & -\frac{1}{\sqrt2} & 0 & 0\\ 0 & 0 & \frac{1}{\sqrt2} & \frac{1}{\sqrt2} \\ 0 & 0 & \frac{1}{\sqrt2} & -\frac{1}{\sqrt2} \end{bmatrix}

However, Operator(QuantumCircuit) raises an error in the case of a parametric quantum circuit:

from qiskit.circuit import Parameter

qc = QuantumCircuit(2)
theta = Parameter(name='$\\theta$')
qc.ry(theta, 0)

op = Operator(qc)  # ERROR!

This brings me to the question: is there a way in Qiskit to get the matrix operator symbolic representation from a given arbitrary PQC? For instance, in this case I would like to get a sympy.matrices.dense.Matrix object (with just one parameter $\theta$) like this:

\begin{bmatrix} \cos\left(\frac{\theta}{2}\right) & -\sin\left(\frac{\theta}{2}\right) & 0 & 0\\ \sin\left(\frac{\theta}{2}\right) & \cos\left(\frac{\theta}{2}\right) & 0 & 0\\ 0 & 0 & \cos\left(\frac{\theta}{2}\right) & -\sin\left(\frac{\theta}{2}\right)\\ 0 & 0 & \sin\left(\frac{\theta}{2}\right) & \cos\left(\frac{\theta}{2}\right) \end{bmatrix}

EDIT: this is now possible by using the new qiskit-symb package

Qiskit provides the qiskit.quantum_info.Operator class to get the unitary matrix operator from the corresponding quantum circuit, as in the following example:

from qiskit import QuantumCircuit
from qiskit.quantum_info import Operator
from qiskit.visualization import array_to_latex

qc = QuantumCircuit(2)
qc.h(0)

op = Operator(qc)
array_to_latex(op)

\begin{bmatrix} \frac{1}{\sqrt2} & \frac{1}{\sqrt2} & 0 & 0\\ \frac{1}{\sqrt2} & -\frac{1}{\sqrt2} & 0 & 0\\ 0 & 0 & \frac{1}{\sqrt2} & \frac{1}{\sqrt2} \\ 0 & 0 & \frac{1}{\sqrt2} & -\frac{1}{\sqrt2} \end{bmatrix}

However, Operator(QuantumCircuit) raises an error in the case of a parametric quantum circuit:

from qiskit.circuit import Parameter

qc = QuantumCircuit(2)
theta = Parameter(name='$\\theta$')
qc.ry(theta, 0)

op = Operator(qc)  # ERROR!

This brings me to the question: is there a way in Qiskit to get the matrix operator symbolic representation from a given arbitrary PQC? For instance, in this case I would like to get a sympy.matrices.dense.Matrix object (with just one parameter $\theta$) like this:

\begin{bmatrix} \cos\left(\frac{\theta}{2}\right) & -\sin\left(\frac{\theta}{2}\right) & 0 & 0\\ \sin\left(\frac{\theta}{2}\right) & \cos\left(\frac{\theta}{2}\right) & 0 & 0\\ 0 & 0 & \cos\left(\frac{\theta}{2}\right) & -\sin\left(\frac{\theta}{2}\right)\\ 0 & 0 & \sin\left(\frac{\theta}{2}\right) & \cos\left(\frac{\theta}{2}\right) \end{bmatrix}

Qiskit provides the qiskit.quantum_info.Operator class to get the unitary matrix operator from the corresponding quantum circuit, as in the following example:

from qiskit import QuantumCircuit
from qiskit.quantum_info import Operator
from qiskit.visualization import array_to_latex

qc = QuantumCircuit(2)
qc.h(0)

op = Operator(qc)
array_to_latex(op)

\begin{bmatrix} \frac{1}{\sqrt2} & \frac{1}{\sqrt2} & 0 & 0\\ \frac{1}{\sqrt2} & -\frac{1}{\sqrt2} & 0 & 0\\ 0 & 0 & \frac{1}{\sqrt2} & \frac{1}{\sqrt2} \\ 0 & 0 & \frac{1}{\sqrt2} & -\frac{1}{\sqrt2} \end{bmatrix}

However, Operator(QuantumCircuit) raises an error in the case of a parametric quantum circuit:

from qiskit.circuit import Parameter

qc = QuantumCircuit(2)
theta = Parameter(name='$\\theta$')
qc.ry(theta, 0)

op = Operator(qc)  # ERROR!

This brings me to the question: is there a way in Qiskit to get the matrix operator symbolic representation from a given arbitrary PQC? For instance, in this case I would like to get a sympy.matrices.dense.Matrix object (with just one parameter $\theta$) like this:

\begin{bmatrix} \cos\left(\frac{\theta}{2}\right) & -\sin\left(\frac{\theta}{2}\right) & 0 & 0\\ \sin\left(\frac{\theta}{2}\right) & \cos\left(\frac{\theta}{2}\right) & 0 & 0\\ 0 & 0 & \cos\left(\frac{\theta}{2}\right) & -\sin\left(\frac{\theta}{2}\right)\\ 0 & 0 & \sin\left(\frac{\theta}{2}\right) & \cos\left(\frac{\theta}{2}\right) \end{bmatrix}

EDIT: this is now possible by using the new qiskit-symb package

deleted 9 characters in body; edited tags
Source Link
SimoneGasperini
  • 1.6k
  • 1
  • 3
  • 18

Qiskit provides the qiskit.quantum_info.Operator class to get the unitary matrix operator from the corresponding quantum circuit, as in the following example:

from qiskit import QuantumCircuit
from qiskit.quantum_info import Operator
from qiskit.visualization import array_to_latex

qc = QuantumCircuit(2)
qc.h(0)

op = Operator(qc)
array_to_latex(op)

\begin{bmatrix} \frac{1}{\sqrt2} & \frac{1}{\sqrt2} & 0 & 0\\ \frac{1}{\sqrt2} & -\frac{1}{\sqrt2} & 0 & 0\\ 0 & 0 & \frac{1}{\sqrt2} & \frac{1}{\sqrt2} \\ 0 & 0 & \frac{1}{\sqrt2} & -\frac{1}{\sqrt2} \end{bmatrix}

However, using Operator(QuantumCircuit) throwsraises an error in the case of a parameterizedparametric quantum circuit (PQC):

from qiskit.circuit import Parameter

qc = QuantumCircuit(2)
theta = Parameter(name='$\\theta$')
qc.ry(theta, 0)

op = Operator(qc)  # ERROR!

This brings me to the question: is there a way in Qiskit to get the matrix operator symbolic representation from a given arbitrary PQC? For instance, in this case I would like to get a sympy.matrices.dense.Matrix object (with just one parameter $\theta$) like this:

\begin{bmatrix} \cos\left(\frac{\theta}{2}\right) & -\sin\left(\frac{\theta}{2}\right) & 0 & 0\\ \sin\left(\frac{\theta}{2}\right) & \cos\left(\frac{\theta}{2}\right) & 0 & 0\\ 0 & 0 & \cos\left(\frac{\theta}{2}\right) & -\sin\left(\frac{\theta}{2}\right)\\ 0 & 0 & \sin\left(\frac{\theta}{2}\right) & \cos\left(\frac{\theta}{2}\right) \end{bmatrix}

Qiskit provides the qiskit.quantum_info.Operator class to get the unitary matrix operator from the corresponding quantum circuit, as in the following example:

from qiskit import QuantumCircuit
from qiskit.quantum_info import Operator
from qiskit.visualization import array_to_latex

qc = QuantumCircuit(2)
qc.h(0)

op = Operator(qc)
array_to_latex(op)

\begin{bmatrix} \frac{1}{\sqrt2} & \frac{1}{\sqrt2} & 0 & 0\\ \frac{1}{\sqrt2} & -\frac{1}{\sqrt2} & 0 & 0\\ 0 & 0 & \frac{1}{\sqrt2} & \frac{1}{\sqrt2} \\ 0 & 0 & \frac{1}{\sqrt2} & -\frac{1}{\sqrt2} \end{bmatrix}

However, using Operator(QuantumCircuit) throws an error in the case of a parameterized quantum circuit (PQC):

from qiskit.circuit import Parameter

qc = QuantumCircuit(2)
theta = Parameter(name='$\\theta$')
qc.ry(theta, 0)

op = Operator(qc)  # ERROR!

This brings me to the question: is there a way in Qiskit to get the matrix operator symbolic representation from a given arbitrary PQC? For instance, in this case I would like to get a sympy.matrices.dense.Matrix object (with just one parameter $\theta$) like this:

\begin{bmatrix} \cos\left(\frac{\theta}{2}\right) & -\sin\left(\frac{\theta}{2}\right) & 0 & 0\\ \sin\left(\frac{\theta}{2}\right) & \cos\left(\frac{\theta}{2}\right) & 0 & 0\\ 0 & 0 & \cos\left(\frac{\theta}{2}\right) & -\sin\left(\frac{\theta}{2}\right)\\ 0 & 0 & \sin\left(\frac{\theta}{2}\right) & \cos\left(\frac{\theta}{2}\right) \end{bmatrix}

Qiskit provides the qiskit.quantum_info.Operator class to get the unitary matrix operator from the corresponding quantum circuit, as in the following example:

from qiskit import QuantumCircuit
from qiskit.quantum_info import Operator
from qiskit.visualization import array_to_latex

qc = QuantumCircuit(2)
qc.h(0)

op = Operator(qc)
array_to_latex(op)

\begin{bmatrix} \frac{1}{\sqrt2} & \frac{1}{\sqrt2} & 0 & 0\\ \frac{1}{\sqrt2} & -\frac{1}{\sqrt2} & 0 & 0\\ 0 & 0 & \frac{1}{\sqrt2} & \frac{1}{\sqrt2} \\ 0 & 0 & \frac{1}{\sqrt2} & -\frac{1}{\sqrt2} \end{bmatrix}

However, Operator(QuantumCircuit) raises an error in the case of a parametric quantum circuit:

from qiskit.circuit import Parameter

qc = QuantumCircuit(2)
theta = Parameter(name='$\\theta$')
qc.ry(theta, 0)

op = Operator(qc)  # ERROR!

This brings me to the question: is there a way in Qiskit to get the matrix operator symbolic representation from a given arbitrary PQC? For instance, in this case I would like to get a sympy.matrices.dense.Matrix object (with just one parameter $\theta$) like this:

\begin{bmatrix} \cos\left(\frac{\theta}{2}\right) & -\sin\left(\frac{\theta}{2}\right) & 0 & 0\\ \sin\left(\frac{\theta}{2}\right) & \cos\left(\frac{\theta}{2}\right) & 0 & 0\\ 0 & 0 & \cos\left(\frac{\theta}{2}\right) & -\sin\left(\frac{\theta}{2}\right)\\ 0 & 0 & \sin\left(\frac{\theta}{2}\right) & \cos\left(\frac{\theta}{2}\right) \end{bmatrix}

deleted 44 characters in body; edited tags
Source Link
SimoneGasperini
  • 1.6k
  • 1
  • 3
  • 18

Qiskit provides the qiskit.quantum_info.Operator class to get the unitary matrix operator from the corresponding quantum circuit, as in the following example (here, op wraps a numpy.ndarray object):

from qiskit import QuantumCircuit
from qiskit.quantum_info import Operator
from qiskit.visualization import array_to_latex

qc = QuantumCircuit(2)
qc.h(0)

op = Operator(qc)
array_to_latex(op)

\begin{bmatrix} \frac{1}{\sqrt2} & \frac{1}{\sqrt2} & 0 & 0\\ \frac{1}{\sqrt2} & -\frac{1}{\sqrt2} & 0 & 0\\ 0 & 0 & \frac{1}{\sqrt2} & \frac{1}{\sqrt2} \\ 0 & 0 & \frac{1}{\sqrt2} & -\frac{1}{\sqrt2} \end{bmatrix}

However, using Operator(QuantumCircuit) throws an error in the case of a parameterized quantum circuit (PQC):

from qiskit.circuit import Parameter

qc = QuantumCircuit(2)
theta = Parameter(name='$\\theta$')
qc.ry(theta, 0)

op = Operator(qc)  # ERROR!

This brings me to the question: is there a way in Qiskit to get the matrix operator symbolic representation from a given arbitrary PQC? For instance, in this case I would like to get a sympy.matrices.dense.Matrix object (with just one parameter $\theta$) like this:

\begin{bmatrix} \cos\left(\frac{\theta}{2}\right) & -\sin\left(\frac{\theta}{2}\right) & 0 & 0\\ \sin\left(\frac{\theta}{2}\right) & \cos\left(\frac{\theta}{2}\right) & 0 & 0\\ 0 & 0 & \cos\left(\frac{\theta}{2}\right) & -\sin\left(\frac{\theta}{2}\right)\\ 0 & 0 & \sin\left(\frac{\theta}{2}\right) & \cos\left(\frac{\theta}{2}\right) \end{bmatrix}

Qiskit provides the qiskit.quantum_info.Operator class to get the unitary matrix operator from the corresponding quantum circuit, as in the following example (here, op wraps a numpy.ndarray object):

from qiskit import QuantumCircuit
from qiskit.quantum_info import Operator
from qiskit.visualization import array_to_latex

qc = QuantumCircuit(2)
qc.h(0)

op = Operator(qc)
array_to_latex(op)

\begin{bmatrix} \frac{1}{\sqrt2} & \frac{1}{\sqrt2} & 0 & 0\\ \frac{1}{\sqrt2} & -\frac{1}{\sqrt2} & 0 & 0\\ 0 & 0 & \frac{1}{\sqrt2} & \frac{1}{\sqrt2} \\ 0 & 0 & \frac{1}{\sqrt2} & -\frac{1}{\sqrt2} \end{bmatrix}

However, using Operator(QuantumCircuit) throws an error in the case of a parameterized quantum circuit (PQC):

from qiskit.circuit import Parameter

qc = QuantumCircuit(2)
theta = Parameter(name='$\\theta$')
qc.ry(theta, 0)

op = Operator(qc)  # ERROR!

This brings me to the question: is there a way in Qiskit to get the matrix operator symbolic representation from a given arbitrary PQC? For instance, in this case I would like to get a sympy.matrices.dense.Matrix object (with just one parameter $\theta$) like this:

\begin{bmatrix} \cos\left(\frac{\theta}{2}\right) & -\sin\left(\frac{\theta}{2}\right) & 0 & 0\\ \sin\left(\frac{\theta}{2}\right) & \cos\left(\frac{\theta}{2}\right) & 0 & 0\\ 0 & 0 & \cos\left(\frac{\theta}{2}\right) & -\sin\left(\frac{\theta}{2}\right)\\ 0 & 0 & \sin\left(\frac{\theta}{2}\right) & \cos\left(\frac{\theta}{2}\right) \end{bmatrix}

Qiskit provides the qiskit.quantum_info.Operator class to get the unitary matrix operator from the corresponding quantum circuit, as in the following example:

from qiskit import QuantumCircuit
from qiskit.quantum_info import Operator
from qiskit.visualization import array_to_latex

qc = QuantumCircuit(2)
qc.h(0)

op = Operator(qc)
array_to_latex(op)

\begin{bmatrix} \frac{1}{\sqrt2} & \frac{1}{\sqrt2} & 0 & 0\\ \frac{1}{\sqrt2} & -\frac{1}{\sqrt2} & 0 & 0\\ 0 & 0 & \frac{1}{\sqrt2} & \frac{1}{\sqrt2} \\ 0 & 0 & \frac{1}{\sqrt2} & -\frac{1}{\sqrt2} \end{bmatrix}

However, using Operator(QuantumCircuit) throws an error in the case of a parameterized quantum circuit (PQC):

from qiskit.circuit import Parameter

qc = QuantumCircuit(2)
theta = Parameter(name='$\\theta$')
qc.ry(theta, 0)

op = Operator(qc)  # ERROR!

This brings me to the question: is there a way in Qiskit to get the matrix operator symbolic representation from a given arbitrary PQC? For instance, in this case I would like to get a sympy.matrices.dense.Matrix object (with just one parameter $\theta$) like this:

\begin{bmatrix} \cos\left(\frac{\theta}{2}\right) & -\sin\left(\frac{\theta}{2}\right) & 0 & 0\\ \sin\left(\frac{\theta}{2}\right) & \cos\left(\frac{\theta}{2}\right) & 0 & 0\\ 0 & 0 & \cos\left(\frac{\theta}{2}\right) & -\sin\left(\frac{\theta}{2}\right)\\ 0 & 0 & \sin\left(\frac{\theta}{2}\right) & \cos\left(\frac{\theta}{2}\right) \end{bmatrix}

deleted 2 characters in body
Source Link
SimoneGasperini
  • 1.6k
  • 1
  • 3
  • 18
Loading
Source Link
SimoneGasperini
  • 1.6k
  • 1
  • 3
  • 18
Loading