From c370ad180de77c0b816dc025dd719806112f753a Mon Sep 17 00:00:00 2001
From: Shraddha Aangiras <63237790+shraddha-aangiras@users.noreply.github.com>
Date: Thu, 27 Jun 2024 17:43:04 +0530
Subject: [PATCH] Added explanation of methods on Circuits & Registers
---
docs/build/circuit-construction.ipynb | 211 +++++++++++++++++++++++---
1 file changed, 186 insertions(+), 25 deletions(-)
diff --git a/docs/build/circuit-construction.ipynb b/docs/build/circuit-construction.ipynb
index 0f588c12c0b..57aedf26a9e 100644
--- a/docs/build/circuit-construction.ipynb
+++ b/docs/build/circuit-construction.ipynb
@@ -23,12 +23,12 @@
"source": [
"## What is a quantum circuit?\n",
"\n",
- "A simple quantum circuit is a collection of qubits and a list of instructions that act on those qubits. To demonstrate, the following cell creates a new circuit with two new qubits, then displays the circuit's [`qubits`](/api/qiskit/qiskit.circuit.QuantumCircuit#qubits) attribute."
+ "A simple quantum circuit is a collection of qubits and a list of instructions that act on those qubits. To demonstrate, the following cell creates a new circuit with two new qubits, then displays the circuit's [`qubits`](/api/qiskit/qiskit.circuit.QuantumCircuit#qubits) attribute, which returns a list of [`Qubits`](/api/qiskit/circuit#qiskit.circuit.Qubit) in order."
]
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 15,
"id": "b410d397-b67d-4f31-90cf-9c1c34c157c5",
"metadata": {},
"outputs": [
@@ -38,7 +38,7 @@
"[Qubit(QuantumRegister(2, 'q'), 0), Qubit(QuantumRegister(2, 'q'), 1)]"
]
},
- "execution_count": 1,
+ "execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
@@ -50,6 +50,74 @@
"qc.qubits"
]
},
+ {
+ "cell_type": "markdown",
+ "id": "392e3d6c",
+ "metadata": {},
+ "source": [
+ "Multiple QuantumRegisters and ClassicalRegisters can be combined to create a circuit. Every [`QuantumRegister`](/api/qiskit/circuit#qiskit.circuit.QuantumRegister) and [`ClassicalRegister`](/api/qiskit/circuit#qiskit.circuit.ClassicalRegister) can also be named."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "id": "6160e3f7",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[Qubit(QuantumRegister(2, 'qreg1'), 0),\n",
+ " Qubit(QuantumRegister(2, 'qreg1'), 1),\n",
+ " Qubit(QuantumRegister(1, 'qreg2'), 0)]"
+ ]
+ },
+ "execution_count": 3,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "from qiskit.circuit import QuantumRegister, ClassicalRegister\n",
+ "\n",
+ "qr1 = QuantumRegister(2, 'qreg1') # Create a QuantumRegister with 2 qubits \n",
+ "qr2 = QuantumRegister(1, 'qreg2') # Create a QuantumRegister with 1 qubit\n",
+ "cr1 = ClassicalRegister(3, 'creg1') # Create a ClassicalRegister with 3 cbits \n",
+ "\n",
+ "combined_circ = QuantumCircuit(qr1, qr2, cr1) # Create a quantum circuit with 2 QuantumRegisters and 1 ClassicalRegister\n",
+ "combined_circ.qubits"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "6e7b212f",
+ "metadata": {},
+ "source": [
+ "The index and register of a qubit can be obtained using the circuit's [`find_bit`](/api/qiskit/qiskit.circuit.QuantumCircuit#qiskit.circuit.QuantumCircuit.find_bit) method and its attributes. "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "id": "faeb3fbc",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Index: 2\n",
+ "Register: [(QuantumRegister(1, 'qreg2'), 0)]\n"
+ ]
+ }
+ ],
+ "source": [
+ "qb = qr2[0] # Setting qb as the first qubit of register 'qreg2'\n",
+ "\n",
+ "print(\"Index:\", combined_circ.find_bit(qb).index)\n",
+ "print(\"Register:\", combined_circ.find_bit(qb).registers)"
+ ]
+ },
{
"cell_type": "markdown",
"id": "f5c95cb2-a94f-48f3-b2a6-8ec6c25da5cd",
@@ -60,7 +128,7 @@
},
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": 16,
"id": "f7b5573c-b2b2-4cbf-ba55-c53c9221ce71",
"metadata": {},
"outputs": [
@@ -70,13 +138,13 @@
"[CircuitInstruction(operation=Instruction(name='x', num_qubits=1, num_clbits=0, params=[]), qubits=(Qubit(QuantumRegister(2, 'q'), 0),), clbits=())]"
]
},
- "execution_count": 2,
+ "execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "qc.x(0) # Add X-gate to qubit 0\n",
+ "qc.x(0) # Add X-gate to qubit 0\n",
"qc.data"
]
},
@@ -90,20 +158,18 @@
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": 17,
"id": "43a57258-3e33-4071-8a48-2bf127c8a5be",
"metadata": {},
"outputs": [
{
"data": {
- "image/svg+xml": [
- ""
- ],
+ "image/png": "iVBORw0KGgoAAAANSUhEUgAAALAAAACuCAYAAACWa4e1AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy80BEi2AAAACXBIWXMAAA9hAAAPYQGoP6dpAAAKL0lEQVR4nO3df0zU9x3H8eed2oKKrSddzw5/QAELyI9NpGJbVwxm6fwRk8XY1ind7PxjQ1nGvD8Wt9k2DWG6ZXGmjSZtXbOMsLR/zEKT/UMzKbEMQm2pYKlMjCCXeoqKV1xlfPdHUxYG/jrgzvfX1+M/7vO97/eteXL3ve/B4XEcx0HEKG+sBxAZDwUspilgMU0Bi2kKWExTwGKaAhbTFLCYpoDFNAUspilgMU0Bi2kKWExTwGKaAhbTFLCYpoDFNAUspilgMU0Bi2kKWExTwGKaAhbTFLCYpoDFNAUspilgMU0Bi2kKWExTwGKaAhbTFLCYpoDFNAUspilgMU0Bi2kKWEybGusBZDTHcfhiYDDWY9yW6fFT8Xg8UT+uAr4DfTEwyMxlb8Z6jNty5YMtzJg+LerH1SmEmKaAxTQFLKYpYDFNAYtpClhMU8BimgIW0xSwmKaA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