Skip to content

Commit

Permalink
Add code example in Operator docstring. (#12985)
Browse files Browse the repository at this point in the history
Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
  • Loading branch information
jschuhmac and ElePT authored Aug 19, 2024
1 parent 66fb6fe commit 393fb59
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions qiskit/quantum_info/operators/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,30 @@ class Operator(LinearOp):
.. math::
\rho \mapsto M \rho M^\dagger.
For example, the following operator :math:`M = X` applied to the zero state
:math:`|\psi\rangle=|0\rangle (\rho = |0\rangle\langle 0|)` changes it to the
one state :math:`|\psi\rangle=|1\rangle (\rho = |1\rangle\langle 1|)`:
.. code-block:: python
>>> import numpy as np
>>> from qiskit.quantum_info import Operator
>>> op = Operator(np.array([[0.0, 1.0], [1.0, 0.0]])) # Represents Pauli X operator
>>> from qiskit.quantum_info import Statevector
>>> sv = Statevector(np.array([1.0, 0.0]))
>>> sv.evolve(op)
Statevector([0.+0.j, 1.+0.j],
dims=(2,))
>>> from qiskit.quantum_info import DensityMatrix
>>> dm = DensityMatrix(np.array([[1.0, 0.0], [0.0, 0.0]]))
>>> dm.evolve(op)
DensityMatrix([[0.+0.j, 0.+0.j],
[0.+0.j, 1.+0.j]],
dims=(2,))
"""

def __init__(
Expand Down

0 comments on commit 393fb59

Please sign in to comment.