Skip to content

Commit 03cd2bd

Browse files
committed
update
1 parent 9201c02 commit 03cd2bd

File tree

8 files changed

+690
-1451
lines changed

8 files changed

+690
-1451
lines changed

doc/pub/week11/ipynb/week11.ipynb

Lines changed: 89 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,9 +1565,34 @@
15651565
"id": "0d59a75a",
15661566
"metadata": {
15671567
"collapsed": false,
1568-
"editable": true
1569-
},
1570-
"outputs": [],
1568+
"editable": true,
1569+
"jupyter": {
1570+
"outputs_hidden": false
1571+
}
1572+
},
1573+
"outputs": [
1574+
{
1575+
"name": "stdout",
1576+
"output_type": "stream",
1577+
"text": [
1578+
"Initial State |5⟩: [0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 1.+0.j 0.+0.j 0.+0.j]\n",
1579+
"\n",
1580+
"State after QFT:\n",
1581+
"[ 0.3536+0.j -0.25 -0.25j 0. +0.3536j 0.25 -0.25j\n",
1582+
" -0.3536+0.j 0.25 +0.25j -0. -0.3536j -0.25 +0.25j ]\n",
1583+
"\n",
1584+
"QFT * QFT† = Identity Matrix (Rounded):\n",
1585+
"[[ 1.+0.j -0.-0.j -0.-0.j -0.-0.j -0.-0.j 0.-0.j 0.-0.j 0.-0.j]\n",
1586+
" [-0.+0.j 1.-0.j -0.-0.j -0.-0.j -0.-0.j -0.-0.j 0.-0.j 0.-0.j]\n",
1587+
" [-0.+0.j -0.+0.j 1.+0.j -0.-0.j -0.-0.j -0.-0.j -0.-0.j 0.-0.j]\n",
1588+
" [-0.+0.j -0.+0.j -0.+0.j 1.+0.j -0.-0.j -0.-0.j -0.-0.j -0.-0.j]\n",
1589+
" [-0.+0.j -0.+0.j -0.+0.j -0.+0.j 1.-0.j -0.-0.j -0.-0.j -0.-0.j]\n",
1590+
" [ 0.+0.j -0.+0.j -0.+0.j -0.+0.j -0.+0.j 1.-0.j -0.-0.j -0.-0.j]\n",
1591+
" [ 0.+0.j 0.+0.j -0.+0.j -0.+0.j -0.+0.j -0.+0.j 1.-0.j -0.-0.j]\n",
1592+
" [ 0.+0.j 0.+0.j 0.+0.j -0.+0.j -0.+0.j -0.+0.j -0.+0.j 1.+0.j]]\n"
1593+
]
1594+
}
1595+
],
15711596
"source": [
15721597
"import numpy as np\n",
15731598
"def qft(n):\n",
@@ -1623,9 +1648,25 @@
16231648
"id": "88d90d78",
16241649
"metadata": {
16251650
"collapsed": false,
1626-
"editable": true
1627-
},
1628-
"outputs": [],
1651+
"editable": true,
1652+
"jupyter": {
1653+
"outputs_hidden": false
1654+
}
1655+
},
1656+
"outputs": [
1657+
{
1658+
"ename": "ImportError",
1659+
"evalue": "Qiskit is installed in an invalid environment that has both Qiskit >=1.0 and an earlier version. You should create a new virtual environment, and ensure that you do not mix dependencies between Qiskit <1.0 and >=1.0. Any packages that depend on 'qiskit-terra' are not compatible with Qiskit 1.0 and will need to be updated. Qiskit unfortunately cannot enforce this requirement during environment resolution. See https://qisk.it/packaging-1-0 for more detail.",
1660+
"output_type": "error",
1661+
"traceback": [
1662+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
1663+
"\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)",
1664+
"Cell \u001b[0;32mIn[2], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mnumpy\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mnp\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mqiskit\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m QuantumCircuit, Aer, execute\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mqft\u001b[39m(circuit, n):\n\u001b[1;32m 4\u001b[0m \u001b[38;5;66;03m# Apply the Quantum Fourier Transform to the first n qubits in the circuit\u001b[39;00m\n\u001b[1;32m 5\u001b[0m \u001b[38;5;66;03m# Apply Hadamard gates and controlled rotations\u001b[39;00m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m j \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(n):\n",
1665+
"File \u001b[0;32m~/miniforge3/envs/myenv/lib/python3.9/site-packages/qiskit/__init__.py:36\u001b[0m\n\u001b[1;32m 34\u001b[0m _suppress_error \u001b[38;5;241m=\u001b[39m os\u001b[38;5;241m.\u001b[39menviron\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mQISKIT_SUPPRESS_1_0_IMPORT_ERROR\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28;01mFalse\u001b[39;00m) \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m1\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 35\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m _suppress_error \u001b[38;5;129;01mand\u001b[39;00m _has_tools:\n\u001b[0;32m---> 36\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mImportError\u001b[39;00m(\n\u001b[1;32m 37\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mQiskit is installed in an invalid environment that has both Qiskit >=1.0\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 38\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m and an earlier version.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 39\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m You should create a new virtual environment, and ensure that you do not mix\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 40\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m dependencies between Qiskit <1.0 and >=1.0.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 41\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m Any packages that depend on \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mqiskit-terra\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m are not compatible with Qiskit 1.0 and\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 42\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m will need to be updated.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 43\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m Qiskit unfortunately cannot enforce this requirement during environment resolution.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 44\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m See https://qisk.it/packaging-1-0 for more detail.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 45\u001b[0m )\n\u001b[1;32m 47\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m _accelerate\n\u001b[1;32m 48\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mqiskit\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01m_numpy_compat\u001b[39;00m\n",
1666+
"\u001b[0;31mImportError\u001b[0m: Qiskit is installed in an invalid environment that has both Qiskit >=1.0 and an earlier version. You should create a new virtual environment, and ensure that you do not mix dependencies between Qiskit <1.0 and >=1.0. Any packages that depend on 'qiskit-terra' are not compatible with Qiskit 1.0 and will need to be updated. Qiskit unfortunately cannot enforce this requirement during environment resolution. See https://qisk.it/packaging-1-0 for more detail."
1667+
]
1668+
}
1669+
],
16291670
"source": [
16301671
"import numpy as np\n",
16311672
"from qiskit import QuantumCircuit, Aer, execute\n",
@@ -1672,9 +1713,21 @@
16721713
"id": "a2e3b094",
16731714
"metadata": {
16741715
"collapsed": false,
1675-
"editable": true
1676-
},
1677-
"outputs": [],
1716+
"editable": true,
1717+
"jupyter": {
1718+
"outputs_hidden": false
1719+
}
1720+
},
1721+
"outputs": [
1722+
{
1723+
"name": "stdout",
1724+
"output_type": "stream",
1725+
"text": [
1726+
"Probabilities after performing QFT:\n",
1727+
"[0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125]\n"
1728+
]
1729+
}
1730+
],
16781731
"source": [
16791732
"import pennylane as qml\n",
16801733
"from pennylane import numpy as np\n",
@@ -1701,9 +1754,35 @@
17011754
"print(\"Probabilities after performing QFT:\")\n",
17021755
"print(probabilities)"
17031756
]
1757+
},
1758+
{
1759+
"cell_type": "code",
1760+
"execution_count": null,
1761+
"id": "19f59372-225e-4b96-8595-fc06edcba2fc",
1762+
"metadata": {},
1763+
"outputs": [],
1764+
"source": []
17041765
}
17051766
],
1706-
"metadata": {},
1767+
"metadata": {
1768+
"kernelspec": {
1769+
"display_name": "Python 3 (ipykernel)",
1770+
"language": "python",
1771+
"name": "python3"
1772+
},
1773+
"language_info": {
1774+
"codemirror_mode": {
1775+
"name": "ipython",
1776+
"version": 3
1777+
},
1778+
"file_extension": ".py",
1779+
"mimetype": "text/x-python",
1780+
"name": "python",
1781+
"nbconvert_exporter": "python",
1782+
"pygments_lexer": "ipython3",
1783+
"version": "3.9.15"
1784+
}
1785+
},
17071786
"nbformat": 4,
17081787
"nbformat_minor": 5
17091788
}
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)