Skip to content

Commit

Permalink
Add code example in Operator docstring. (#12985) (#12991)
Browse files Browse the repository at this point in the history
Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
(cherry picked from commit 393fb59)

Co-authored-by: jschuhmac <74537145+jschuhmac@users.noreply.github.com>
Co-authored-by: Elena Peña Tapia <epenatap@gmail.com>
  • Loading branch information
3 people authored Aug 20, 2024
1 parent 5a246db commit c53c1c8
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 c53c1c8

Please sign in to comment.