diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 4f9efaa3f..80e88a991 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -18,7 +18,9 @@ jobs: with: command: install args: --debug cargo-make - - name: Run CI + - name: Install poetry + uses: snok/install-poetry@v1 + - name: Run Rust CI uses: actions-rs/cargo@v1 env: CARGO_MAKE_RUN_CHECK_FORMAT: true @@ -27,3 +29,8 @@ jobs: with: command: make args: --cwd crates/lib --makefile Makefile.toml ci-flow + - name: Run Python CI + uses: actions-rs/cargo@v1 + with: + command: make + args: --cwd crates/python --makefile Makefile.toml pytest-flow diff --git a/crates/python/Makefile.toml b/crates/python/Makefile.toml new file mode 100644 index 000000000..f3a9cc1c2 --- /dev/null +++ b/crates/python/Makefile.toml @@ -0,0 +1,31 @@ +[env] +RUST_BACKTRACE = 0 + +[tasks.pre-test-docker-up] +command = "docker-compose" +args = ["up", "-d"] + +[tasks.pre-test-poetry-install] +command = "poetry" +args = ["install"] + +[tasks.pre-test-install-lib] +command = "poetry" +args = ["run", "maturin", "develop"] + +[tasks.post-test] +command = "docker-compose" +args = ["down"] + +[tasks.test] +command = "poetry" +args = ["run", "pytest", "tests"] + +[tasks.pytest-flow] +dependencies = [ + "pre-test-docker-up", + "pre-test-poetry-install", + "pre-test-install-lib", + "test", + "post-test", +] \ No newline at end of file diff --git a/crates/python/poetry.lock b/crates/python/poetry.lock index 5ab7fc93b..388b8c467 100644 --- a/crates/python/poetry.lock +++ b/crates/python/poetry.lock @@ -1,3 +1,85 @@ +[[package]] +name = "attrs" +version = "22.1.0" +description = "Classes Without Boilerplate" +category = "dev" +optional = false +python-versions = ">=3.5" + +[package.extras] +dev = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "mypy (>=0.900,!=0.940)", "pytest-mypy-plugins", "zope.interface", "furo", "sphinx", "sphinx-notfound-page", "pre-commit", "cloudpickle"] +docs = ["furo", "sphinx", "zope.interface", "sphinx-notfound-page"] +tests = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "mypy (>=0.900,!=0.940)", "pytest-mypy-plugins", "zope.interface", "cloudpickle"] +tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "mypy (>=0.900,!=0.940)", "pytest-mypy-plugins", "cloudpickle"] + +[[package]] +name = "black" +version = "22.8.0" +description = "The uncompromising code formatter." +category = "dev" +optional = false +python-versions = ">=3.6.2" + +[package.dependencies] +click = ">=8.0.0" +mypy-extensions = ">=0.4.3" +pathspec = ">=0.9.0" +platformdirs = ">=2" +tomli = {version = ">=1.1.0", markers = "python_full_version < \"3.11.0a7\""} +typed-ast = {version = ">=1.4.2", markers = "python_version < \"3.8\" and implementation_name == \"cpython\""} +typing-extensions = {version = ">=3.10.0.0", markers = "python_version < \"3.10\""} + +[package.extras] +colorama = ["colorama (>=0.4.3)"] +d = ["aiohttp (>=3.7.4)"] +jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"] +uvloop = ["uvloop (>=0.15.2)"] + +[[package]] +name = "click" +version = "8.1.3" +description = "Composable command line interface toolkit" +category = "dev" +optional = false +python-versions = ">=3.7" + +[package.dependencies] +colorama = {version = "*", markers = "platform_system == \"Windows\""} +importlib-metadata = {version = "*", markers = "python_version < \"3.8\""} + +[[package]] +name = "colorama" +version = "0.4.5" +description = "Cross-platform colored terminal text." +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" + +[[package]] +name = "importlib-metadata" +version = "4.12.0" +description = "Read metadata from Python packages" +category = "dev" +optional = false +python-versions = ">=3.7" + +[package.dependencies] +typing-extensions = {version = ">=3.6.4", markers = "python_version < \"3.8\""} +zipp = ">=0.5" + +[package.extras] +docs = ["sphinx", "jaraco.packaging (>=9)", "rst.linker (>=1.9)"] +perf = ["ipython"] +testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.3)", "packaging", "pyfakefs", "flufl.flake8", "pytest-perf (>=0.9.2)", "pytest-black (>=0.3.7)", "pytest-mypy (>=0.9.1)", "importlib-resources (>=1.3)"] + +[[package]] +name = "iniconfig" +version = "1.1.1" +description = "iniconfig: brain-dead simple config-ini parsing" +category = "dev" +optional = false +python-versions = "*" + [[package]] name = "maturin" version = "0.13.3" @@ -13,6 +95,115 @@ tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} zig = ["ziglang (>=0.9.0,<0.10.0)"] patchelf = ["patchelf"] +[[package]] +name = "mypy-extensions" +version = "0.4.3" +description = "Experimental type system extensions for programs checked with the mypy typechecker." +category = "dev" +optional = false +python-versions = "*" + +[[package]] +name = "packaging" +version = "21.3" +description = "Core utilities for Python packages" +category = "dev" +optional = false +python-versions = ">=3.6" + +[package.dependencies] +pyparsing = ">=2.0.2,<3.0.5 || >3.0.5" + +[[package]] +name = "pathspec" +version = "0.10.1" +description = "Utility library for gitignore style pattern matching of file paths." +category = "dev" +optional = false +python-versions = ">=3.7" + +[[package]] +name = "platformdirs" +version = "2.5.2" +description = "A small Python module for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." +category = "dev" +optional = false +python-versions = ">=3.7" + +[package.extras] +docs = ["furo (>=2021.7.5b38)", "proselint (>=0.10.2)", "sphinx-autodoc-typehints (>=1.12)", "sphinx (>=4)"] +test = ["appdirs (==1.4.4)", "pytest-cov (>=2.7)", "pytest-mock (>=3.6)", "pytest (>=6)"] + +[[package]] +name = "pluggy" +version = "1.0.0" +description = "plugin and hook calling mechanisms for python" +category = "dev" +optional = false +python-versions = ">=3.6" + +[package.dependencies] +importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""} + +[package.extras] +dev = ["pre-commit", "tox"] +testing = ["pytest", "pytest-benchmark"] + +[[package]] +name = "py" +version = "1.11.0" +description = "library with cross-python path, ini-parsing, io, code, log facilities" +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" + +[[package]] +name = "pyparsing" +version = "3.0.9" +description = "pyparsing module - Classes and methods to define and execute parsing grammars" +category = "dev" +optional = false +python-versions = ">=3.6.8" + +[package.extras] +diagrams = ["railroad-diagrams", "jinja2"] + +[[package]] +name = "pytest" +version = "7.1.3" +description = "pytest: simple powerful testing with Python" +category = "dev" +optional = false +python-versions = ">=3.7" + +[package.dependencies] +attrs = ">=19.2.0" +colorama = {version = "*", markers = "sys_platform == \"win32\""} +importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""} +iniconfig = "*" +packaging = "*" +pluggy = ">=0.12,<2.0" +py = ">=1.8.2" +tomli = ">=1.0.0" + +[package.extras] +testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "xmlschema"] + +[[package]] +name = "pytest-asyncio" +version = "0.19.0" +description = "Pytest support for asyncio" +category = "dev" +optional = false +python-versions = ">=3.7" + +[package.dependencies] +pytest = ">=6.1.0" +typing-extensions = {version = ">=3.7.2", markers = "python_version < \"3.8\""} + +[package.extras] +testing = ["coverage (>=6.2)", "hypothesis (>=5.7.1)", "flaky (>=3.5.0)", "mypy (>=0.931)", "pytest-trio (>=0.7.0)"] + [[package]] name = "tomli" version = "2.0.1" @@ -21,28 +212,109 @@ category = "dev" optional = false python-versions = ">=3.7" +[[package]] +name = "typed-ast" +version = "1.5.4" +description = "a fork of Python 2 and 3 ast modules with type comment support" +category = "dev" +optional = false +python-versions = ">=3.6" + +[[package]] +name = "typing-extensions" +version = "4.3.0" +description = "Backported and Experimental Type Hints for Python 3.7+" +category = "dev" +optional = false +python-versions = ">=3.7" + +[[package]] +name = "zipp" +version = "3.8.1" +description = "Backport of pathlib-compatible object wrapper for zip files" +category = "dev" +optional = false +python-versions = ">=3.7" + +[package.extras] +docs = ["sphinx", "jaraco.packaging (>=9)", "rst.linker (>=1.9)", "jaraco.tidelift (>=1.4)"] +testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.3)", "jaraco.itertools", "func-timeout", "pytest-black (>=0.3.7)", "pytest-mypy (>=0.9.1)"] + [metadata] lock-version = "1.1" python-versions = "^3.7" -content-hash = "775bd1ad820ad84bbcd5a2ea6687822eeba631d1f88cf6710bb8d8e5881e6630" +content-hash = "d974c959893832d70b661e1805ddc82b886d828edd542b944f11512e6f2a3914" [metadata.files] -maturin = [ - {file = "maturin-0.13.3-py3-none-linux_armv6l.whl", hash = "sha256:4d1c443776a290b26054112bac77c370ffff89ac7b2d9a04ca0536c257f51016"}, - {file = "maturin-0.13.3-py3-none-macosx_10_7_x86_64.whl", hash = "sha256:5b3f1aa0817d30c450a46f6ef14f41e21f4f974cefd395181af9dec06a8b1d16"}, - {file = "maturin-0.13.3-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:0b8c5653c31703523232c602f6e93b76c5aaaf5af66b672155d820702dc63f69"}, - {file = "maturin-0.13.3-py3-none-manylinux_2_12_i686.manylinux2010_i686.musllinux_1_1_i686.whl", hash = "sha256:85abe7eaebd19e74a781a7512138e7dfae1504dc7cf291e7ad03234795c3c7cc"}, - {file = "maturin-0.13.3-py3-none-manylinux_2_12_x86_64.manylinux2010_x86_64.musllinux_1_1_x86_64.whl", hash = "sha256:93e97cce6da48d9c8bd73d864d1ad04728ed28a5594b6b65f1322dfd1520c485"}, - {file = "maturin-0.13.3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.musllinux_1_1_aarch64.whl", hash = "sha256:65cc3e06dd8b9b0dc9cb813f7b61e3bd5fd327a198deabc661a6afb852d4991a"}, - {file = "maturin-0.13.3-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.musllinux_1_1_armv7l.whl", hash = "sha256:d738fd84f661e181893625a609bb89c5c35f2038967aac0deff3a5602fd28058"}, - {file = "maturin-0.13.3-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.musllinux_1_1_ppc64le.whl", hash = "sha256:a0b93434668f868387ba67d6455fc887d502c3528733311c0b7fed612d72b33b"}, - {file = "maturin-0.13.3-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:04a6cb00f125a280a7f2227c3464243d8920ed83ff5523b13fa10220395c3363"}, - {file = "maturin-0.13.3-py3-none-win32.whl", hash = "sha256:2d8a3e43790a96663a10aa53c100a26f05364d76fbd52daddd980f4c2949411f"}, - {file = "maturin-0.13.3-py3-none-win_amd64.whl", hash = "sha256:06ed41bd4771674c6f8359e8ed4f261fbb23a371a1e4f833cc9af7f5e5904fc5"}, - {file = "maturin-0.13.3-py3-none-win_arm64.whl", hash = "sha256:25eb48fc6178079c1399dff7b9ccd401747ecd174c043690f2c40425723b10c5"}, - {file = "maturin-0.13.3.tar.gz", hash = "sha256:edeb8ecaa5cc6e6d2f50a32289798d7ca046c33481ac24f74805ff289af6afe4"}, +attrs = [] +black = [] +click = [ + {file = "click-8.1.3-py3-none-any.whl", hash = "sha256:bb4d8133cb15a609f44e8213d9b391b0809795062913b383c62be0ee95b1db48"}, + {file = "click-8.1.3.tar.gz", hash = "sha256:7682dc8afb30297001674575ea00d1814d808d6a36af415a82bd481d37ba7b8e"}, +] +colorama = [] +importlib-metadata = [] +iniconfig = [ + {file = "iniconfig-1.1.1-py2.py3-none-any.whl", hash = "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3"}, + {file = "iniconfig-1.1.1.tar.gz", hash = "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32"}, ] +maturin = [] +mypy-extensions = [ + {file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"}, + {file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"}, +] +packaging = [ + {file = "packaging-21.3-py3-none-any.whl", hash = "sha256:ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522"}, + {file = "packaging-21.3.tar.gz", hash = "sha256:dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb"}, +] +pathspec = [] +platformdirs = [ + {file = "platformdirs-2.5.2-py3-none-any.whl", hash = "sha256:027d8e83a2d7de06bbac4e5ef7e023c02b863d7ea5d079477e722bb41ab25788"}, + {file = "platformdirs-2.5.2.tar.gz", hash = "sha256:58c8abb07dcb441e6ee4b11d8df0ac856038f944ab98b7be6b27b2a3c7feef19"}, +] +pluggy = [ + {file = "pluggy-1.0.0-py2.py3-none-any.whl", hash = "sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3"}, + {file = "pluggy-1.0.0.tar.gz", hash = "sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159"}, +] +py = [ + {file = "py-1.11.0-py2.py3-none-any.whl", hash = "sha256:607c53218732647dff4acdfcd50cb62615cedf612e72d1724fb1a0cc6405b378"}, + {file = "py-1.11.0.tar.gz", hash = "sha256:51c75c4126074b472f746a24399ad32f6053d1b34b68d2fa41e558e6f4a98719"}, +] +pyparsing = [ + {file = "pyparsing-3.0.9-py3-none-any.whl", hash = "sha256:5026bae9a10eeaefb61dab2f09052b9f4307d44aee4eda64b309723d8d206bbc"}, + {file = "pyparsing-3.0.9.tar.gz", hash = "sha256:2b020ecf7d21b687f219b71ecad3631f644a47f01403fa1d1036b0c6416d70fb"}, +] +pytest = [] +pytest-asyncio = [] tomli = [ {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, ] +typed-ast = [ + {file = "typed_ast-1.5.4-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:669dd0c4167f6f2cd9f57041e03c3c2ebf9063d0757dc89f79ba1daa2bfca9d4"}, + {file = "typed_ast-1.5.4-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:211260621ab1cd7324e0798d6be953d00b74e0428382991adfddb352252f1d62"}, + {file = "typed_ast-1.5.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:267e3f78697a6c00c689c03db4876dd1efdfea2f251a5ad6555e82a26847b4ac"}, + {file = "typed_ast-1.5.4-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:c542eeda69212fa10a7ada75e668876fdec5f856cd3d06829e6aa64ad17c8dfe"}, + {file = "typed_ast-1.5.4-cp310-cp310-win_amd64.whl", hash = "sha256:a9916d2bb8865f973824fb47436fa45e1ebf2efd920f2b9f99342cb7fab93f72"}, + {file = "typed_ast-1.5.4-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:79b1e0869db7c830ba6a981d58711c88b6677506e648496b1f64ac7d15633aec"}, + {file = "typed_ast-1.5.4-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a94d55d142c9265f4ea46fab70977a1944ecae359ae867397757d836ea5a3f47"}, + {file = "typed_ast-1.5.4-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:183afdf0ec5b1b211724dfef3d2cad2d767cbefac291f24d69b00546c1837fb6"}, + {file = "typed_ast-1.5.4-cp36-cp36m-win_amd64.whl", hash = "sha256:639c5f0b21776605dd6c9dbe592d5228f021404dafd377e2b7ac046b0349b1a1"}, + {file = "typed_ast-1.5.4-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:cf4afcfac006ece570e32d6fa90ab74a17245b83dfd6655a6f68568098345ff6"}, + {file = "typed_ast-1.5.4-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ed855bbe3eb3715fca349c80174cfcfd699c2f9de574d40527b8429acae23a66"}, + {file = "typed_ast-1.5.4-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:6778e1b2f81dfc7bc58e4b259363b83d2e509a65198e85d5700dfae4c6c8ff1c"}, + {file = "typed_ast-1.5.4-cp37-cp37m-win_amd64.whl", hash = "sha256:0261195c2062caf107831e92a76764c81227dae162c4f75192c0d489faf751a2"}, + {file = "typed_ast-1.5.4-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:2efae9db7a8c05ad5547d522e7dbe62c83d838d3906a3716d1478b6c1d61388d"}, + {file = "typed_ast-1.5.4-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:7d5d014b7daa8b0bf2eaef684295acae12b036d79f54178b92a2b6a56f92278f"}, + {file = "typed_ast-1.5.4-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:370788a63915e82fd6f212865a596a0fefcbb7d408bbbb13dea723d971ed8bdc"}, + {file = "typed_ast-1.5.4-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:4e964b4ff86550a7a7d56345c7864b18f403f5bd7380edf44a3c1fb4ee7ac6c6"}, + {file = "typed_ast-1.5.4-cp38-cp38-win_amd64.whl", hash = "sha256:683407d92dc953c8a7347119596f0b0e6c55eb98ebebd9b23437501b28dcbb8e"}, + {file = "typed_ast-1.5.4-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:4879da6c9b73443f97e731b617184a596ac1235fe91f98d279a7af36c796da35"}, + {file = "typed_ast-1.5.4-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:3e123d878ba170397916557d31c8f589951e353cc95fb7f24f6bb69adc1a8a97"}, + {file = "typed_ast-1.5.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ebd9d7f80ccf7a82ac5f88c521115cc55d84e35bf8b446fcd7836eb6b98929a3"}, + {file = "typed_ast-1.5.4-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:98f80dee3c03455e92796b58b98ff6ca0b2a6f652120c263efdba4d6c5e58f72"}, + {file = "typed_ast-1.5.4-cp39-cp39-win_amd64.whl", hash = "sha256:0fdbcf2fef0ca421a3f5912555804296f0b0960f0418c440f5d6d3abb549f3e1"}, + {file = "typed_ast-1.5.4.tar.gz", hash = "sha256:39e21ceb7388e4bb37f4c679d72707ed46c2fbf2a5609b8b8ebc4b067d977df2"}, +] +typing-extensions = [] +zipp = [] diff --git a/crates/python/pyproject.toml b/crates/python/pyproject.toml index fd0e5952e..4b7274829 100644 --- a/crates/python/pyproject.toml +++ b/crates/python/pyproject.toml @@ -44,6 +44,9 @@ python = "^3.7" [tool.poetry.dev-dependencies] maturin = "^0.13.2" +pytest = "^7.1.3" +pytest-asyncio = "^0.19.0" +black = "^22.8.0" [build-system] requires = ["maturin>=0.13,<0.14"] diff --git a/crates/python/tests/conftest.py b/crates/python/tests/conftest.py new file mode 100644 index 000000000..ce3ce3798 --- /dev/null +++ b/crates/python/tests/conftest.py @@ -0,0 +1,189 @@ +import pytest + + +@pytest.fixture +def device_2q() -> str: + import json + + return json.dumps( + { + "isa": { + "1Q": { + "0": { + "id": 0, + "gates": [ + { + "operator": "RX", + "duration": 50.0, + "fidelity": 1.0, + "parameters": [0.0], + "arguments": [0], + "operator_type": "gate", + }, + { + "operator": "RX", + "duration": 50.0, + "fidelity": 0.9909074679565163, + "parameters": [3.141592653589793], + "arguments": [0], + "operator_type": "gate", + }, + { + "operator": "RX", + "duration": 50.0, + "fidelity": 0.9909074679565163, + "parameters": [-3.141592653589793], + "arguments": [0], + "operator_type": "gate", + }, + { + "operator": "RX", + "duration": 50.0, + "fidelity": 0.9909074679565163, + "parameters": [1.5707963267948966], + "arguments": [0], + "operator_type": "gate", + }, + { + "operator": "RX", + "duration": 50.0, + "fidelity": 0.9909074679565163, + "parameters": [-1.5707963267948966], + "arguments": [0], + "operator_type": "gate", + }, + { + "operator": "RZ", + "duration": 0.01, + "fidelity": 1.0, + "parameters": ["_"], + "arguments": [0], + "operator_type": "gate", + }, + { + "operator": "MEASURE", + "duration": 2000.0, + "fidelity": 0.977, + "qubit": 0, + "target": "_", + "operator_type": "measure", + }, + { + "operator": "MEASURE", + "duration": 2000.0, + "fidelity": 0.977, + "qubit": 0, + "target": None, + "operator_type": "measure", + }, + ], + }, + "1": { + "id": 1, + "gates": [ + { + "operator": "RX", + "duration": 50.0, + "fidelity": 1.0, + "parameters": [0.0], + "arguments": [1], + "operator_type": "gate", + }, + { + "operator": "RX", + "duration": 50.0, + "fidelity": 0.9967034552975036, + "parameters": [3.141592653589793], + "arguments": [1], + "operator_type": "gate", + }, + { + "operator": "RX", + "duration": 50.0, + "fidelity": 0.9967034552975036, + "parameters": [-3.141592653589793], + "arguments": [1], + "operator_type": "gate", + }, + { + "operator": "RX", + "duration": 50.0, + "fidelity": 0.9967034552975036, + "parameters": [1.5707963267948966], + "arguments": [1], + "operator_type": "gate", + }, + { + "operator": "RX", + "duration": 50.0, + "fidelity": 0.9967034552975036, + "parameters": [-1.5707963267948966], + "arguments": [1], + "operator_type": "gate", + }, + { + "operator": "RZ", + "duration": 0.01, + "fidelity": 1.0, + "parameters": ["_"], + "arguments": [1], + "operator_type": "gate", + }, + { + "operator": "MEASURE", + "duration": 2000.0, + "fidelity": 0.9450000000000001, + "qubit": 1, + "target": "_", + "operator_type": "measure", + }, + { + "operator": "MEASURE", + "duration": 2000.0, + "fidelity": 0.9450000000000001, + "qubit": 1, + "target": None, + "operator_type": "measure", + }, + ], + }, + }, + "2Q": { + "0-1": { + "ids": [0, 1], + "gates": [ + { + "operator": "CZ", + "duration": 200.0, + "fidelity": 0.95, + "parameters": [], + "arguments": ["_", "_"], + "operator_type": "gate", + }, + ], + }, + }, + }, + "specs": {}, + } + ) + + +@pytest.fixture +def native_bitflip_program() -> str: + return """ +DECLARE ro BIT[0] +RX(pi) 0 +MEASURE 0 ro[0] +""" + + +@pytest.fixture +def bell_program() -> str: + return """ +DECLARE ro BIT[2] +X 0 +CNOT 0 1 +MEASURE 0 ro[0] +MEASURE 1 ro[1] +""" diff --git a/crates/python/tests/test_api.py b/crates/python/tests/test_api.py new file mode 100644 index 000000000..efa798656 --- /dev/null +++ b/crates/python/tests/test_api.py @@ -0,0 +1,43 @@ +from unittest.mock import patch +import pytest + +import qcs_sdk + + +@pytest.mark.asyncio +@pytest.mark.skip +async def test_compile(native_bitflip_program: str, device_2q: str): + await qcs_sdk.compile(native_bitflip_program, device_2q) + + +@pytest.mark.asyncio +@pytest.mark.skip +async def test_translate(native_bitflip_program: str, device_2q: str): + await qcs_sdk.translate(native_bitflip_program, 1, "Aspen-11") + + +@pytest.mark.asyncio +@pytest.mark.skip +async def test_execute(bell_program: str, device_2q): + compiled_program = await qcs_sdk.compile(bell_program, device_2q) + translation_result = await qcs_sdk.translate(compiled_program, 1, "Aspen-11") + job_id = await qcs_sdk.submit(translation_result["program"], {}, "Aspen-11") + await qcs_sdk.retrieve_results(job_id, "Aspen-11") + + +def test_rewrite_arithmetic(): + native_quil = "RX(2*theta[0]) 0" + rewritten_arithmetic = qcs_sdk.rewrite_arithmetic(native_quil) + expected = { + "program": "DECLARE __SUBST REAL[1]\nRX(__SUBST[0]) 0\n", + "recalculation_table": ['((2*theta[0])/6.283185307179586)'], + } + assert rewritten_arithmetic == expected + + +def test_build_patch_values(): + memory = {"theta": [2.0]} + recalculation_table = ["0.5*theta[0]"] + expected = {"theta": [2.0], "__SUBST": [1.0]} + patch_values = qcs_sdk.build_patch_values(recalculation_table, memory) + assert patch_values == expected \ No newline at end of file