Die Seite is noch nich übersetzt. Se kieken die englische Originalversion.
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
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.
The Operator class also has a tensor method (as well as a from_label method), as we see in the following examples.
H = Operator.from_label("H") Id = Operator.from_label("I") X = Operator.from_label("X") display(H.tensor(Id).draw("latex")) display(H.tensor(Id).tensor(X).draw("latex"))
In the previous lesson, we used the measure method to simulate a measurement of a quantum state vector.
This method returns two items: the simulated measurement result, and the new Statevector given this measurement.
By default, measure measures all qubits in the state vector.
We can, alternatively, provide a list of integers as an argument, which causes only those qubit indices to be measured.
To demonstrate this, the code below creates the state
and measures qubit number 0, which is the rightmost qubit.
(Qiskit numbers qubits starting from 0, from right to left. We'll return to this numbering convention in the next lesson.)
w = Statevector([0,1,1,0,1,0,0,0]/ sqrt(3)) display(w.draw("latex")) result, state = w.measure([0]) print(f"Measured: {result}\nState after measurement:") display(state.draw("latex")) result, state = w.measure([0,1]) print(f"Measured: {result}\nState after measurement:") display(state.draw("latex"))