Qiskit implementation
이 페이지는 아직 한국어로 번역되지 않았습니다. 영어 원본을 보고 있습니다.
In the previous lesson, we took a first look at the Statevector and Operator classes in Qiskit, and used them to simulate operations and measurements on single qubits.
In this section, we'll use these classes to explore the behavior of multiple qubits.
# Added by doQumentation — required packages for this notebook
!pip install -q numpy qiskit
from qiskit import __version__
print(__version__)
2.1.1
We'll start by importing the Statevector and Operator classes, as well as the square root function from NumPy.
Hereafter, generally speaking, we'll take care of all of our required imports first within each lesson.
from qiskit.quantum_info import Statevector, Operator
from numpy import sqrt
Tensor products
The Statevector class has a tensor method, which returns the tensor product of that Statevector with another, given as an argument.
The argument is interpreted as the tensor factor on the right.
For example, below we create two state vectors representing and and use the tensor method to create a new vector,
Notice here that we're using the from_label method to define the states and rather than defining them ourselves.
zero = Statevector.from_label("0")
one = Statevector.from_label("1")
psi = zero.tensor(one)
display(psi.draw("latex"))
Other allowed labels include "+" and "-" for the plus and minus states, as well as "r" and "l" (short for "right" and "left") for the states
Here, "+", "-" or "right" and "left" come from the context of quantum mechanical spin, in which a component of spin may point to the left or the right in an experiment; it is not referring to the right-most or left-most qubit in systems of multiple qubits. Here's an example of the tensor product of and
plus = Statevector.from_label("+")
minus_i = Statevector.from_label("l")
phi = plus.tensor(minus_i)
display(phi.draw("latex"))
An alternative is to use the ^ operation for tensor products, which naturally gives the same results.
display((plus ^ minus_i).draw("latex"))