From cc1131449fa633ff0e7da32e72b6563c036f63c7 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 13 Aug 2024 16:14:00 +0400 Subject: [PATCH] add requirements and example code --- .gitignore | 259 +++++++++++++++++++ .idea/misc.xml | 7 +- .idea/modules.xml | 2 +- .idea/{showcase.iml => quantum-showcase.iml} | 2 +- main.ipynb | 83 ++++++ readme.md | 7 + requirements.txt | 4 + run.bat | 7 + 8 files changed, 367 insertions(+), 4 deletions(-) create mode 100644 .gitignore rename .idea/{showcase.iml => quantum-showcase.iml} (79%) create mode 100644 main.ipynb create mode 100644 readme.md create mode 100644 requirements.txt create mode 100644 run.bat diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..259965b --- /dev/null +++ b/.gitignore @@ -0,0 +1,259 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/python,pycharm+all +# Edit at https://www.toptal.com/developers/gitignore?templates=python,pycharm+all + +### PyCharm+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/** +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### PyCharm+all Patch ### +# Ignores the whole .idea folder and all .iml files +# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 + +.idea/* + +# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 + +*.iml +modules.xml +.idea/misc.xml +*.ipr + +# Sonarlint plugin +.idea/sonarlint + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintainted in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +# End of https://www.toptal.com/developers/gitignore/api/python,pycharm+all + +temp/ +data/ +darts_logs/ diff --git a/.idea/misc.xml b/.idea/misc.xml index 812ab5a..ee99274 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,7 +1,10 @@ - + + + - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index 456b54b..e7fd9b4 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/.idea/showcase.iml b/.idea/quantum-showcase.iml similarity index 79% rename from .idea/showcase.iml rename to .idea/quantum-showcase.iml index 27487ca..2c80e12 100644 --- a/.idea/showcase.iml +++ b/.idea/quantum-showcase.iml @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/main.ipynb b/main.ipynb new file mode 100644 index 0000000..b4cbdb0 --- /dev/null +++ b/main.ipynb @@ -0,0 +1,83 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "fc7fe56b-71b4-498c-955d-e5e56af8f08e", + "metadata": {}, + "outputs": [ + { + "ename": "ImportError", + "evalue": "DLL load failed while importing spinq_backends: Не найден указанный модуль.", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mImportError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[1], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mspinqit\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m get_basic_simulator, get_compiler, Circuit, BasicSimulatorConfig\n\u001b[0;32m 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mspinqit\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m H, CX, Rx\n\u001b[0;32m 3\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mmath\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m pi\n", + "File \u001b[1;32m~\\YandexDisk\\Кафедра\\Лаборатория Квантовые вычисления\\projects\\quantum-showcase\\.venv\\lib\\site-packages\\spinqit\\__init__.py:16\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# Copyright 2021 SpinQ Technology Co., Ltd.\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;66;03m#\u001b[39;00m\n\u001b[0;32m 3\u001b[0m \u001b[38;5;66;03m# Licensed under the Apache License, Version 2.0 (the \"License\");\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 12\u001b[0m \u001b[38;5;66;03m# See the License for the specific language governing permissions and\u001b[39;00m\n\u001b[0;32m 13\u001b[0m \u001b[38;5;66;03m# limitations under the License.\u001b[39;00m\n\u001b[0;32m 15\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mmodel\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n\u001b[1;32m---> 16\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mbackend\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n\u001b[0;32m 17\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mcompiler\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m get_compiler\n\u001b[0;32m 18\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mprimitive\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n", + "File \u001b[1;32m~\\YandexDisk\\Кафедра\\Лаборатория Квантовые вычисления\\projects\\quantum-showcase\\.venv\\lib\\site-packages\\spinqit\\backend\\__init__.py:15\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# Copyright 2021 SpinQ Technology Co., Ltd.\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;66;03m#\u001b[39;00m\n\u001b[0;32m 3\u001b[0m \u001b[38;5;66;03m# Licensed under the Apache License, Version 2.0 (the \"License\");\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 12\u001b[0m \u001b[38;5;66;03m# See the License for the specific language governing permissions and\u001b[39;00m\n\u001b[0;32m 13\u001b[0m \u001b[38;5;66;03m# limitations under the License.\u001b[39;00m\n\u001b[1;32m---> 15\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mbackend\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n\u001b[0;32m 16\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mbasic_simulator_backend\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m BasicSimulatorConfig\n\u001b[0;32m 17\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mnmr_backend\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m NMRConfig\n", + "File \u001b[1;32m~\\YandexDisk\\Кафедра\\Лаборатория Квантовые вычисления\\projects\\quantum-showcase\\.venv\\lib\\site-packages\\spinqit\\backend\\backend.py:15\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# Copyright 2022 SpinQ Technology Co., Ltd.\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;66;03m#\u001b[39;00m\n\u001b[0;32m 3\u001b[0m \u001b[38;5;66;03m# Licensed under the Apache License, Version 2.0 (the \"License\");\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 12\u001b[0m \u001b[38;5;66;03m# See the License for the specific language governing permissions and\u001b[39;00m\n\u001b[0;32m 13\u001b[0m \u001b[38;5;66;03m# limitations under the License.\u001b[39;00m\n\u001b[0;32m 14\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mspinqit\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mmodel\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mexceptions\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m InappropriateBackendError\n\u001b[1;32m---> 15\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mbasic_simulator_backend\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m BasicSimulatorBackend\n\u001b[0;32m 16\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mnmr_backend\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m NMRBackend\n\u001b[0;32m 17\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mspinq_cloud_backend\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m SpinQCloudBackend\n", + "File \u001b[1;32m~\\YandexDisk\\Кафедра\\Лаборатория Квантовые вычисления\\projects\\quantum-showcase\\.venv\\lib\\site-packages\\spinqit\\backend\\basic_simulator_backend.py:26\u001b[0m\n\u001b[0;32m 24\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mspinqit\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mmodel\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m Instruction\n\u001b[0;32m 25\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mspinqit\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mmodel\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m I, H, X, Y, Z, Rx, Ry, Rz, T, Td, S, Sd, P, CX, CY, CZ, SWAP, CCX, U\n\u001b[1;32m---> 26\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mspinqit\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mspinq_backends\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m BasicSimulator\n\u001b[0;32m 28\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mspinqit\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mmodel\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mparameter\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m Parameter, LazyParameter\n\u001b[0;32m 29\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mbasebackend\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m BaseBackend\n", + "\u001b[1;31mImportError\u001b[0m: DLL load failed while importing spinq_backends: Не найден указанный модуль." + ] + } + ], + "source": [ + "from spinqit import get_basic_simulator, get_compiler, Circuit, BasicSimulatorConfig\n", + "from spinqit import H, CX, Rx\n", + "from math import pi\n", + "\n", + "# Write the program\n", + "circ = Circuit()\n", + "q = circ.allocateQubits(2)\n", + "circ << (Rx, q[0], pi)\n", + "circ << (H, q[1])\n", + "circ << (CX, (q[0], q[1]))\n", + "\n", + "# Choose the compiler and backend\n", + "comp = get_compiler(\"native\")\n", + "engine = get_basic_simulator()\n", + "\n", + "# Compile\n", + "optimization_level = 0\n", + "exe = comp.compile(circ, optimization_level)\n", + "\n", + "# Run\n", + "config = BasicSimulatorConfig()\n", + "config.configure_shots(1024)\n", + "result = engine.execute(exe, config)\n", + "\n", + "print(result.counts)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1743de14-4e3c-4634-a9af-667745eac7be", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..859e03d --- /dev/null +++ b/readme.md @@ -0,0 +1,7 @@ +# Описание + +Проект для демонстрации квантовых вычислений при помощи библиотеки [SpinQit] (https://github.com/SpinQTech/SpinQit) + +# Зависимости + +Используется Python 3.9.13 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..87228f7 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +jupyter==1.0.0 +JupyterLab== 3.1.0 +spinqit==0.2.3 +numpy==1.26.4 \ No newline at end of file diff --git a/run.bat b/run.bat new file mode 100644 index 0000000..4ebb394 --- /dev/null +++ b/run.bat @@ -0,0 +1,7 @@ +python -m venv .venv + +call .venv\Scripts\activate.bat + +pip install -r requirements.txt +call jupyter lab +