דלג לתוכן הראשי
פרויקט זה בשלב בטא. מצאת באג? פתח issue ב-GitHub. יש שאלה או רעיון? שאל ב-Discussions — נשמח לשמוע ממך!
מה איכות התרגום בדף זה?

מדידת Qubits

Package versions

הקוד בעמוד הזה פותח באמצעות הדרישות הבאות. אנחנו ממליצים להשתמש בגרסאות האלה או חדשות יותר.

qiskit[all]~=2.5.2

כדי לקבל מידע על מצב ה-Qubit, אפשר למדוד אותו לתוך סיבית קלאסית. ב-Qiskit, מדידות מבוצעות בבסיס החישובי, כלומר בסיס Pauli-ZZ חד-Qubit. לכן, מדידה מניבה 0 או 1, בהתאם לחפיפה עם המצבים העצמיים של Pauli-ZZ, שהם ∣0⟩|0\rangle ו-∣1⟩|1\rangle:

∣q⟩→measure{0(outcome+1),with probability p0=∣⟨q∣0⟩∣2,1(outcome−1),with probability p1=∣⟨q∣1⟩∣2.|q\rangle \xrightarrow{measure}\begin{cases} 0 (\text{outcome}+1), \text{with probability } p_0=|\langle q|0\rangle|^{2}\text{,} \\ 1 (\text{outcome}-1), \text{with probability } p_1=|\langle q|1\rangle|^{2}\text{.} \end{cases}

החלת מדידה על Circuit​

ישנן מספר דרכים להחיל מדידות על מעגל:

מתודת QuantumCircuit.measure​

השתמש במתודת measure כדי למדוד QuantumCircuit.

דוגמאות:

# Added by doQumentation — installs the packages this notebook needs if they are missing
import importlib.util

_needed = {"qiskit": "qiskit"}
_missing = [pip for module, pip in _needed.items()
if importlib.util.find_spec(module) is None]
# One at a time, so a package that fails to install does not block the others
for _pip in _missing:
%pip install -q {_pip}
if not _missing:
print("\u2713 All required packages are installed")
from qiskit import QuantumCircuit

qc = QuantumCircuit(5, 5)
qc.x(0)
qc.x(1)
qc.x(4)
qc.measure(
range(5), range(5)
) # Measures all qubits into the corresponding clbit.
<qiskit.circuit.instructionset.InstructionSet at 0x1068db370>
from qiskit import QuantumCircuit

qc = QuantumCircuit(3, 1)
qc.x([0, 2])
qc.measure(1, 0) # Measure qubit 1 into the classical bit 0.
<qiskit.circuit.instructionset.InstructionSet at 0x1068da4a0>

מחלקת Measure​

מחלקת Measure של Qiskit מודדת את ה-Qubits שצוינו.

from qiskit.circuit import Measure

qc = QuantumCircuit(3, 1)
qc.x([0, 1])
qc.append(Measure(), [0], [0]) # measure qubit 0 into clbit 0
<qiskit.circuit.instructionset.InstructionSet at 0x1068daef0>

מתודת QuantumCircuit.measure_all​

כדי למדוד את כל ה-Qubits לתוך הסיביות הקלאסיות המתאימות, השתמש במתודת measure_all. כברירת מחדל, מתודה זו מוסיפה סיביות קלאסיות חדשות ב-ClassicalRegister כדי לאחסן מדידות אלה.

from qiskit import QuantumCircuit

qc = QuantumCircuit(3, 1)
qc.x([0, 2])
qc.measure_all() # Measure all qubits.

מתודת QuantumCircuit.measure_active​

כדי למדוד את כל ה-Qubits שאינם במצב סרק, השתמש במתודת measure_active. מתודה זו יוצרת ClassicalRegister חדש בגודל השווה למספר ה-Qubits הפעילים הנמדדים.

from qiskit import QuantumCircuit

qc = QuantumCircuit(3, 1)
qc.x([0, 2])
qc.measure_active() # Measure qubits that are not idle, that is, qubits 0 and 2.

הצעדים הבאים​

המלצות