From 1149e21e31e1d8bc242114dcdfdce80edf0b7145 Mon Sep 17 00:00:00 2001 From: //va Date: Sun, 8 Sep 2024 18:09:10 -0400 Subject: [PATCH] Update 3sat.ipynb --- 3sat.ipynb | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/3sat.ipynb b/3sat.ipynb index ef0da49..01c3d4e 100644 --- a/3sat.ipynb +++ b/3sat.ipynb @@ -149,11 +149,10 @@ "source": [ "# import Qiskit quantum libraries\n", "from qiskit.visualization import plot_histogram\n", - "from qiskit.utils import QuantumInstance\n", - "from qiskit.algorithms import Grover\n", + "from qiskit_algorithms import Grover\n", "from qiskit.circuit.library import PhaseOracle\n", - "from qiskit import Aer\n", - "from qiskit.algorithms import AmplificationProblem" + "from qiskit_aer import Aer\n", + "from qiskit_algorithms import AmplificationProblem" ] }, { @@ -169,17 +168,17 @@ }, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "c This is an example DIMACS 3-sat file with 3 satisfying solutions: 1 -2 3 0, -1 -2 -3 0, 1 2 -3 0\n", - "p cnf 3 5\n", - "-1 -2 -3 0\n", - "1 -2 3 0\n", - "1 2 -3 0\n", - "1 -2 -3 0\n", - "-1 2 3 0\n", - "\n" + "ename": "MissingOptionalLibraryError", + "evalue": "\"The 'tweedledum' library is required to use 'BooleanExpression'. You can install it with 'pip install tweedledum'.\"", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mMissingOptionalLibraryError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[2], line 8\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mopen\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m3sat3-5.cnf\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mr\u001b[39m\u001b[38;5;124m'\u001b[39m) \u001b[38;5;28;01mas\u001b[39;00m f:\n\u001b[1;32m 7\u001b[0m sat_cnf \u001b[38;5;241m=\u001b[39m f\u001b[38;5;241m.\u001b[39mread()\n\u001b[0;32m----> 8\u001b[0m oracle \u001b[38;5;241m=\u001b[39m \u001b[43mPhaseOracle\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfrom_dimacs_file\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m3sat3-5.cnf\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 9\u001b[0m \u001b[38;5;28mprint\u001b[39m(sat_cnf)\n", + "File \u001b[0;32m~/blue/tools/miniforge3/envs/Qiskitenv/lib/python3.11/site-packages/qiskit/circuit/library/phase_oracle.py:152\u001b[0m, in \u001b[0;36mPhaseOracle.from_dimacs_file\u001b[0;34m(cls, filename)\u001b[0m\n\u001b[1;32m 107\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124mr\u001b[39m\u001b[38;5;124;03m\"\"\"Create a PhaseOracle from the string in the DIMACS format.\u001b[39;00m\n\u001b[1;32m 108\u001b[0m \n\u001b[1;32m 109\u001b[0m \u001b[38;5;124;03mIt is possible to build a PhaseOracle from a file in `DIMACS CNF format\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 148\u001b[0m \u001b[38;5;124;03m PhaseOracle: A quantum circuit with a phase oracle.\u001b[39;00m\n\u001b[1;32m 149\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 150\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mqiskit\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mcircuit\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mclassicalfunction\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mboolean_expression\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m BooleanExpression\n\u001b[0;32m--> 152\u001b[0m expr \u001b[38;5;241m=\u001b[39m \u001b[43mBooleanExpression\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfrom_dimacs_file\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfilename\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 153\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mcls\u001b[39m(expr)\n", + "File \u001b[0;32m~/blue/tools/miniforge3/envs/Qiskitenv/lib/python3.11/site-packages/qiskit/circuit/classicalfunction/boolean_expression.py:113\u001b[0m, in \u001b[0;36mBooleanExpression.from_dimacs_file\u001b[0;34m(cls, filename)\u001b[0m\n\u001b[1;32m 101\u001b[0m \u001b[38;5;129m@classmethod\u001b[39m\n\u001b[1;32m 102\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mfrom_dimacs_file\u001b[39m(\u001b[38;5;28mcls\u001b[39m, filename: \u001b[38;5;28mstr\u001b[39m):\n\u001b[1;32m 103\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Create a BooleanExpression from the string in the DIMACS format.\u001b[39;00m\n\u001b[1;32m 104\u001b[0m \u001b[38;5;124;03m Args:\u001b[39;00m\n\u001b[1;32m 105\u001b[0m \u001b[38;5;124;03m filename: A file in DIMACS format.\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 111\u001b[0m \u001b[38;5;124;03m FileNotFoundError: If filename is not found.\u001b[39;00m\n\u001b[1;32m 112\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 113\u001b[0m \u001b[43mHAS_TWEEDLEDUM\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrequire_now\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mBooleanExpression\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 115\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mtweedledum\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m BoolFunction \u001b[38;5;66;03m# pylint: disable=import-error\u001b[39;00m\n\u001b[1;32m 117\u001b[0m expr_obj \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mcls\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;21m__new__\u001b[39m(\u001b[38;5;28mcls\u001b[39m)\n", + "File \u001b[0;32m~/blue/tools/miniforge3/envs/Qiskitenv/lib/python3.11/site-packages/qiskit/utils/lazy_tester.py:221\u001b[0m, in \u001b[0;36mLazyDependencyManager.require_now\u001b[0;34m(self, feature)\u001b[0m\n\u001b[1;32m 219\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m:\n\u001b[1;32m 220\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m\n\u001b[0;32m--> 221\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m MissingOptionalLibraryError(\n\u001b[1;32m 222\u001b[0m libname\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_name, name\u001b[38;5;241m=\u001b[39mfeature, pip_install\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_install, msg\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_msg\n\u001b[1;32m 223\u001b[0m )\n", + "\u001b[0;31mMissingOptionalLibraryError\u001b[0m: \"The 'tweedledum' library is required to use 'BooleanExpression'. You can install it with 'pip install tweedledum'.\"" ] } ], @@ -279,7 +278,6 @@ "pycharm": { "name": "#%%\n" }, - "scrolled": false, "slideshow": { "slide_type": "subslide" } @@ -369,7 +367,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.11.9" }, "latex_envs": { "bibliofile": "biblio.bib", @@ -393,5 +391,5 @@ } }, "nbformat": 4, - "nbformat_minor": 1 + "nbformat_minor": 4 }