├── test ├── __init__.py ├── benchmarks │ ├── __init__.py │ ├── pulse │ │ ├── __init__.py │ │ ├── schedule_lowering.py │ │ └── schedule_construction.py │ ├── qasm │ │ ├── __init__.py │ │ ├── depth_4mod5-v0_19.qasm │ │ ├── pea_3_pi_8.qasm │ │ ├── 20QBT_45CYC_.0D1_.1D2_3.qasm │ │ ├── depth_4gt10-v1_81.qasm │ │ ├── time_cnt3-5_179.qasm │ │ ├── depth_mod8-10_178.qasm │ │ └── time_cnt3-5_180.qasm │ ├── import.py │ ├── isometry.py │ ├── assembler.py │ ├── converters.py │ ├── ripple_adder.py │ ├── state_tomography.py │ ├── circuit_construction.py │ ├── transpiler_benchmarks.py │ ├── scheduling_passes.py │ ├── randomized_benchmarking.py │ ├── random_circuit_hex.py │ ├── qft.py │ ├── transpiler_qualitative.py │ ├── quantum_volume.py │ ├── utils.py │ ├── quantum_info.py │ ├── transpiler_levels.py │ ├── passes.py │ ├── mapping_passes.py │ └── queko.py ├── test_metapackage.py └── base.py ├── CITATION.md ├── docs ├── images │ ├── logo.png │ ├── binary.png │ ├── favicon.ico │ ├── noise_cancel.png │ ├── system_error.png │ ├── system_one.jpeg │ ├── qiskit_nutshell.png │ ├── quantum_interference.png │ └── teleportation_detailed.png ├── _static │ └── images │ │ ├── ibm_qlab.png │ │ └── strangeworks.png ├── README.md ├── tutorials.rst ├── Makefile ├── maintainers_guide.rst ├── index.rst ├── faq.rst ├── custom_extensions.py ├── configuration.rst ├── conf.py └── intro_tutorial1.rst ├── tools ├── rclone.conf.enc ├── github_poBranch_update_key.enc ├── other-builds.txt ├── deploy_documentation.sh ├── deploy_documentation_tag.sh └── deploy_translatable_strings.sh ├── images └── qiskit_header.png ├── .github ├── dependabot.yml ├── ISSUE_TEMPLATE │ ├── feature_request.md │ ├── bug_report.md │ └── documentation.md ├── PULL_REQUEST_TEMPLATE.md ├── CODEOWNERS └── workflows │ ├── release.yml │ ├── docs_tag.yml │ ├── docs.yml │ └── main.yml ├── constraints.txt ├── pyproject.toml ├── requirements-dev.txt ├── .mergify.yml ├── CONTRIBUTING.md ├── tox.ini ├── .gitignore ├── .mailmap ├── README.md ├── setup.py ├── CODE_OF_CONDUCT.md └── asv.conf.json /test/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/benchmarks/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/benchmarks/pulse/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/benchmarks/qasm/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /CITATION.md: -------------------------------------------------------------------------------- 1 | See https://github.com/Qiskit/qiskit-terra/blob/main/CITATION.bib 2 | -------------------------------------------------------------------------------- /docs/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qiskit/qiskit-metapackage/HEAD/docs/images/logo.png -------------------------------------------------------------------------------- /tools/rclone.conf.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qiskit/qiskit-metapackage/HEAD/tools/rclone.conf.enc -------------------------------------------------------------------------------- /docs/images/binary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qiskit/qiskit-metapackage/HEAD/docs/images/binary.png -------------------------------------------------------------------------------- /docs/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qiskit/qiskit-metapackage/HEAD/docs/images/favicon.ico -------------------------------------------------------------------------------- /images/qiskit_header.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qiskit/qiskit-metapackage/HEAD/images/qiskit_header.png -------------------------------------------------------------------------------- /docs/images/noise_cancel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qiskit/qiskit-metapackage/HEAD/docs/images/noise_cancel.png -------------------------------------------------------------------------------- /docs/images/system_error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qiskit/qiskit-metapackage/HEAD/docs/images/system_error.png -------------------------------------------------------------------------------- /docs/images/system_one.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qiskit/qiskit-metapackage/HEAD/docs/images/system_one.jpeg -------------------------------------------------------------------------------- /docs/images/qiskit_nutshell.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qiskit/qiskit-metapackage/HEAD/docs/images/qiskit_nutshell.png -------------------------------------------------------------------------------- /docs/_static/images/ibm_qlab.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qiskit/qiskit-metapackage/HEAD/docs/_static/images/ibm_qlab.png -------------------------------------------------------------------------------- /docs/_static/images/strangeworks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qiskit/qiskit-metapackage/HEAD/docs/_static/images/strangeworks.png -------------------------------------------------------------------------------- /docs/images/quantum_interference.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qiskit/qiskit-metapackage/HEAD/docs/images/quantum_interference.png -------------------------------------------------------------------------------- /tools/github_poBranch_update_key.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qiskit/qiskit-metapackage/HEAD/tools/github_poBranch_update_key.enc -------------------------------------------------------------------------------- /docs/images/teleportation_detailed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qiskit/qiskit-metapackage/HEAD/docs/images/teleportation_detailed.png -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Qiskit Documentation 2 | 3 | Please refer to [Contributing to Documentation](https://qiskit.org/documentation/contributing_to_qiskit.html#contributing-to-documentation). 4 | -------------------------------------------------------------------------------- /constraints.txt: -------------------------------------------------------------------------------- 1 | astroid==2.14.2 2 | pylint==2.16.2 3 | cryptography==39.0.1 4 | decorator==4.4.2 5 | 6 | # importlib_metadata 5.0 is broken with stevedore, so pin to the last 7 | # functional version in the 4.x series. 8 | importlib_metadata<5.0 9 | -------------------------------------------------------------------------------- /tools/other-builds.txt: -------------------------------------------------------------------------------- 1 | /locale/** 2 | /metal/** 3 | /optimization/** 4 | /machine-learning/** 5 | /partners/** 6 | /nature/** 7 | /finance/** 8 | /experiments/** 9 | /retworkx/** 10 | /rustworkx/** 11 | /stable/** 12 | /dynamics/** 13 | /neko/** 14 | /aer/** 15 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools"] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [tool.black] 6 | line-length = 100 7 | target-version = ["py37", "py38", "py39", "py310", "py311"] 8 | extend-exclude = "['test/benchmarks/', 'docs/plot_directive/']" 9 | 10 | [tool.isort] 11 | profile = "black" 12 | extend_skip_glob = ["test/benchmarks/**", "docs/plot_directive/**"] 13 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F680 Feature request" 3 | about: "Suggest an idea for this project \U0001F4A1!" 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | 12 | 13 | ### What is the expected behavior? 14 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 11 | 12 | ### Summary 13 | 14 | 15 | 16 | ### Details and comments 17 | 18 | 19 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F41B Bug report" 3 | about: "Create a report to help us improve \U0001F914." 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | 12 | 13 | ### Informations 14 | 15 | - **Qiskit version**: 16 | - **Python version**: 17 | - **Operating system**: 18 | 19 | ### What is the current behavior? 20 | 21 | 22 | 23 | ### Steps to reproduce the problem 24 | 25 | 26 | 27 | ### What is the expected behavior? 28 | 29 | 30 | 31 | ### Suggested solutions 32 | -------------------------------------------------------------------------------- /test/benchmarks/qasm/depth_4mod5-v0_19.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 2.0; 2 | include "qelib1.inc"; 3 | qreg q[16]; 4 | creg c[16]; 5 | x q[3]; 6 | cx q[1],q[3]; 7 | cx q[3],q[4]; 8 | h q[4]; 9 | t q[3]; 10 | t q[2]; 11 | t q[4]; 12 | cx q[2],q[3]; 13 | cx q[4],q[2]; 14 | cx q[3],q[4]; 15 | tdg q[2]; 16 | cx q[3],q[2]; 17 | tdg q[3]; 18 | tdg q[2]; 19 | t q[4]; 20 | cx q[4],q[2]; 21 | cx q[3],q[4]; 22 | cx q[2],q[3]; 23 | h q[4]; 24 | h q[4]; 25 | t q[3]; 26 | t q[0]; 27 | t q[4]; 28 | cx q[0],q[3]; 29 | cx q[4],q[0]; 30 | cx q[3],q[4]; 31 | tdg q[0]; 32 | cx q[3],q[0]; 33 | tdg q[3]; 34 | tdg q[0]; 35 | t q[4]; 36 | cx q[4],q[0]; 37 | cx q[3],q[4]; 38 | cx q[0],q[3]; 39 | h q[4]; 40 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # This file defines the set of people who are responsible for different parts of 2 | # the Qiskit metapackage code. 3 | # 4 | # Those assigned as owners of the whole repository are the core maintainers, who 5 | # (using privileges granted by other means) also have the power to make releases 6 | # of the metapackage. These people can approve all pull requests. 7 | * @mtreinish @jakelishman @kevinhartman 8 | 9 | # More specialised rules override the global rule, so the core team need to be 10 | # respecified. 11 | 12 | /README.md @mtreinish @jakelishman @kevinhartman @javabster @Eric-Arellano 13 | /docs @mtreinish @jakelishman @kevinhartman @javabster @Eric-Arellano 14 | -------------------------------------------------------------------------------- /requirements-dev.txt: -------------------------------------------------------------------------------- 1 | qiskit-ibmq-provider[visualization] 2 | qiskit-aer 3 | numpy>=1.17 4 | Sphinx>=6.0 5 | qiskit-sphinx-theme~=1.14.0 6 | pylatexenc>=1.4 7 | sphinx-automodapi 8 | jupyter 9 | sphinx-design 10 | matplotlib>=3.3.0 11 | pydot 12 | ipywidgets>=7.3 13 | pillow>=4.2.1 14 | seaborn>=0.9.0 15 | nbsphinx 16 | cvxpy 17 | # Tweedledum is still used by qiskit-tutorials: 07_grover_examples.ipynb. While we won't eagerly 18 | # error if Tweedledum is missing, the tutorial output will be empty. 19 | tweedledum>=1.0.0,<2.0.0; python_version < '3.11' and platform_system != "Darwin" 20 | networkx>=2.3 21 | qiskit-qasm3-import; python_version>'3.7' 22 | 23 | # Dev tooling 24 | black==23.7.0 25 | isort~=5.11 26 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/documentation.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Documentation 3 | about: 'Create an issue for documentation' 4 | title: '' 5 | labels: documentation 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Did you find a doc bug or broken link that needs to be fixed? 11 | 12 | - What is the file name(s) where you found the bug? 13 | 14 | - What is the current text that needs to be fixed or removed? (You can copy and paste) 15 | 16 | - What should the documentation say instead? 17 | 18 | - Are there other related issues or pull requests about this bug? 19 | 20 | ## Does existing documentation need to be updated with new content? 21 | 22 | - Which files need to be updated? 23 | 24 | - What content needs to be updated or replaced? (You can copy and paste) 25 | 26 | - What new content needs to be added? 27 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Publish PyPI 2 | on: 3 | push: 4 | tags: 5 | - '*' 6 | 7 | jobs: 8 | wheel-build: 9 | name: Build and Publish Release Artifacts 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v3 13 | - name: Set up Python 14 | uses: actions/setup-python@v4 15 | with: 16 | python-version: '3.8' 17 | - name: Install dependencies 18 | run: pip install -U twine wheel 19 | - name: Build and publish 20 | run: | 21 | python setup.py sdist 22 | shell: bash 23 | - uses: actions/upload-artifact@v3 24 | with: 25 | path: ./dist/qiskit* 26 | - name: Publish to PyPi 27 | env: 28 | TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }} 29 | TWINE_USERNAME: qiskit 30 | run: twine upload dist/qiskit* 31 | -------------------------------------------------------------------------------- /test/test_metapackage.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # This code is part of Qiskit. 4 | # 5 | # (C) Copyright IBM 2018. 6 | # 7 | # This code is licensed under the Apache License, Version 2.0. You may 8 | # obtain a copy of this license in the LICENSE.txt file in the root directory 9 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 10 | # 11 | # Any modifications or derivative works of this code must retain this 12 | # copyright notice, and modified files need to carry a notice indicating 13 | # that they have been altered from the originals. 14 | 15 | """Tests for metapackage""" 16 | 17 | import qiskit 18 | 19 | from .base import QiskitTestCase 20 | 21 | 22 | class TestMetaPackage(QiskitTestCase): 23 | """Tests for metapackage""" 24 | 25 | def test_aer_import_works(self): 26 | """Test importing Aer""" 27 | self.assertIsNotNone(qiskit.Aer) 28 | -------------------------------------------------------------------------------- /.github/workflows/docs_tag.yml: -------------------------------------------------------------------------------- 1 | name: Stable Docs Publish 2 | on: 3 | push: 4 | tags: 5 | - '*' 6 | 7 | jobs: 8 | deploy: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v3 12 | with: 13 | fetch-depth: 0 14 | - name: Set up Python 15 | uses: actions/setup-python@v4 16 | with: 17 | python-version: '3.8' 18 | - name: Install dependencies 19 | run: | 20 | python -m pip install --upgrade pip 21 | pip install -U virtualenv setuptools wheel 'tox<4' 22 | sudo apt-get install graphviz pandoc 23 | - name: Build and publish 24 | env: 25 | encrypted_rclone_key: ${{ secrets.encrypted_rclone_key }} 26 | encrypted_rclone_iv: ${{ secrets.encrypted_rclone_iv }} 27 | QISKIT_DOCS_BUILD_TUTORIALS: 'always' 28 | shell: bash 29 | run: | 30 | tools/deploy_documentation_tag.sh ${GITHUB_REF#refs/tags/} 31 | -------------------------------------------------------------------------------- /docs/tutorials.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | .. _tutorials: 4 | 5 | ========= 6 | Tutorials 7 | ========= 8 | 9 | Introductory 10 | ============ 11 | 12 | .. qiskit-card:: 13 | :header: Qiskit warmup 14 | :card_description: An introduction to Qiskit and the primary user workflow. 15 | :image: _static/images/logo.png 16 | :link: intro_tutorial1.html 17 | 18 | Quantum circuits 19 | ================ 20 | 21 | .. nbgallery:: 22 | :glob: 23 | 24 | tutorials/circuits/* 25 | 26 | Advanced circuits 27 | ================= 28 | 29 | .. nbgallery:: 30 | :glob: 31 | 32 | tutorials/circuits_advanced/* 33 | 34 | Algorithms 35 | ========== 36 | 37 | .. nbgallery:: 38 | :glob: 39 | 40 | tutorials/algorithms/* 41 | 42 | Operators 43 | ========= 44 | 45 | .. nbgallery:: 46 | :glob: 47 | 48 | tutorials/operators/* 49 | 50 | .. Hiding - Indices and tables 51 | :ref:`genindex` 52 | :ref:`modindex` 53 | :ref:`search` 54 | -------------------------------------------------------------------------------- /test/benchmarks/qasm/pea_3_pi_8.qasm: -------------------------------------------------------------------------------- 1 | // Name of Experiment: pea_3*pi/8 v3 2 | 3 | OPENQASM 2.0; 4 | include "qelib1.inc"; 5 | 6 | 7 | qreg q[5]; 8 | creg c[4]; 9 | gate cu1fixed (a) c,t { 10 | u1 (-a) t; 11 | cx c,t; 12 | u1 (a) t; 13 | cx c,t; 14 | } 15 | gate cu c,t { 16 | cu1fixed (3*pi/8) c,t; 17 | } 18 | 19 | h q[0]; 20 | h q[1]; 21 | h q[2]; 22 | h q[3]; 23 | cu q[3],q[4]; 24 | cu q[2],q[4]; 25 | cu q[2],q[4]; 26 | cu q[1],q[4]; 27 | cu q[1],q[4]; 28 | cu q[1],q[4]; 29 | cu q[1],q[4]; 30 | cu q[0],q[4]; 31 | cu q[0],q[4]; 32 | cu q[0],q[4]; 33 | cu q[0],q[4]; 34 | cu q[0],q[4]; 35 | cu q[0],q[4]; 36 | cu q[0],q[4]; 37 | cu q[0],q[4]; 38 | h q[0]; 39 | cu1(-pi/2) q[0],q[1]; 40 | h q[1]; 41 | cu1(-pi/4) q[0],q[2]; 42 | cu1(-pi/2) q[1],q[2]; 43 | h q[2]; 44 | cu1(-pi/8) q[0],q[3]; 45 | cu1(-pi/4) q[1],q[3]; 46 | cu1(-pi/2) q[2],q[3]; 47 | h q[3]; 48 | measure q[0] -> c[0]; 49 | measure q[1] -> c[1]; 50 | measure q[2] -> c[2]; 51 | measure q[3] -> c[3]; 52 | -------------------------------------------------------------------------------- /test/benchmarks/import.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # This code is part of Qiskit. 4 | # 5 | # (C) Copyright IBM 2019. 6 | # 7 | # This code is licensed under the Apache License, Version 2.0. You may 8 | # obtain a copy of this license in the LICENSE.txt file in the root directory 9 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 10 | # 11 | # Any modifications or derivative works of this code must retain this 12 | # copyright notice, and modified files need to carry a notice indicating 13 | # that they have been altered from the originals. 14 | 15 | # pylint: disable=no-member,invalid-name,missing-docstring,no-name-in-module 16 | # pylint: disable=attribute-defined-outside-init,unsubscriptable-object 17 | 18 | """Module for estimating import times.""" 19 | 20 | from sys import executable 21 | from subprocess import call 22 | 23 | 24 | class QiskitImport: 25 | def time_qiskit_import(self): 26 | call((executable, '-c', 'import qiskit')) 27 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # This code is part of Qiskit. 2 | # 3 | # (C) Copyright IBM 2018. 4 | # 5 | # This code is licensed under the Apache License, Version 2.0. You may 6 | # obtain a copy of this license in the LICENSE.txt file in the root directory 7 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # Any modifications or derivative works of this code must retain this 10 | # copyright notice, and modified files need to carry a notice indicating 11 | # that they have been altered from the originals. 12 | 13 | # You can set these variables from the command line. 14 | SPHINXOPTS = 15 | SPHINXBUILD = sphinx-build 16 | SOURCEDIR = . 17 | BUILDDIR = _build 18 | 19 | # Put it first so that "make" without argument is like "make help". 20 | help: 21 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 22 | 23 | .PHONY: help Makefile 24 | 25 | # Catch-all target: route all unknown targets to Sphinx using the new 26 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 27 | %: Makefile 28 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 29 | -------------------------------------------------------------------------------- /test/benchmarks/qasm/20QBT_45CYC_.0D1_.1D2_3.qasm: -------------------------------------------------------------------------------- 1 | // Originally source from the QUEKO benchmark suite 2 | // https://github.com/UCLA-VAST/QUEKO-benchmark 3 | // A benchmark of the impact of gate density for IBMQ Tokyo with a depth of 45 4 | OPENQASM 2.0; 5 | include "qelib1.inc"; 6 | qreg q[20]; 7 | cx q[12], q[9]; 8 | cx q[6], q[12]; 9 | cx q[8], q[6]; 10 | cx q[6], q[10]; 11 | cx q[7], q[6]; 12 | cx q[6], q[10]; 13 | cx q[6], q[10]; 14 | cx q[6], q[10]; 15 | cx q[11], q[6]; 16 | cx q[11], q[6]; 17 | cx q[11], q[6]; 18 | cx q[8], q[11]; 19 | cx q[8], q[7]; 20 | cx q[7], q[6]; 21 | cx q[15], q[7]; 22 | cx q[7], q[13]; 23 | cx q[13], q[9]; 24 | cx q[12], q[9]; 25 | cx q[12], q[10]; 26 | cx q[12], q[10]; 27 | cx q[12], q[10]; 28 | cx q[6], q[10]; 29 | cx q[6], q[10]; 30 | cx q[9], q[10]; 31 | cx q[6], q[10]; 32 | cx q[6], q[9]; 33 | cx q[6], q[9]; 34 | cx q[6], q[12]; 35 | cx q[6], q[12]; 36 | cx q[12], q[9]; 37 | cx q[12], q[9]; 38 | cx q[9], q[10]; 39 | cx q[6], q[10]; 40 | cx q[11], q[6]; 41 | cx q[11], q[6]; 42 | cx q[6], q[9]; 43 | cx q[6], q[10]; 44 | cx q[9], q[10]; 45 | cx q[9], q[10]; 46 | cx q[12], q[10]; 47 | cx q[12], q[10]; 48 | cx q[12], q[10]; 49 | cx q[6], q[10]; 50 | cx q[6], q[10]; 51 | cx q[9], q[10]; 52 | -------------------------------------------------------------------------------- /.mergify.yml: -------------------------------------------------------------------------------- 1 | queue_rules: 2 | - name: automerge 3 | conditions: [] # No additional rules, because branch-protection does them. 4 | 5 | pull_request_rules: 6 | - name: automatic merge on CI success and review 7 | conditions: 8 | - base=master 9 | - "#approved-reviews-by>=1" 10 | - label=automerge 11 | - label!=on hold 12 | # GitHub branch-protection rules are automatically applied by mergify, so 13 | # the queue can't actually merge things unless _all_ statuses are passed. 14 | # This section is just a sanity check before the PR can enter the main 15 | # queue. 16 | - or: 17 | - check-success=tests-python3.10-ubuntu-latest 18 | - check-neutral=tests-python3.10-ubuntu-latest 19 | - check-skipped=tests-python3.10-ubuntu-latest 20 | - or: 21 | - check-success=docs 22 | - check-neutral=docs 23 | - check-skipped=docs 24 | - or: 25 | - check-success=lint 26 | - check-neutral=lint 27 | - check-skipped=lint 28 | - or: 29 | - check-success=tutorials 30 | - check-neutral=tutorials 31 | - check-skipped=tutorials 32 | actions: 33 | queue: 34 | name: automerge 35 | method: squash 36 | -------------------------------------------------------------------------------- /tools/deploy_documentation.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This code is part of Qiskit. 4 | # 5 | # (C) Copyright IBM 2018, 2019. 6 | # 7 | # This code is licensed under the Apache License, Version 2.0. You may 8 | # obtain a copy of this license in the LICENSE.txt file in the root directory 9 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 10 | # 11 | # Any modifications or derivative works of this code must retain this 12 | # copyright notice, and modified files need to carry a notice indicating 13 | # that they have been altered from the originals. 14 | 15 | # Script for pushing the documentation to the qiskit.org repository. 16 | set -e 17 | 18 | curl https://downloads.rclone.org/rclone-current-linux-amd64.deb -o rclone.deb 19 | sudo apt-get install -y ./rclone.deb 20 | 21 | RCLONE_CONFIG_PATH=$(rclone config file | tail -1) 22 | 23 | # Build the documentation. 24 | tox -edocs -- -j auto 25 | 26 | echo "show current dir: " 27 | pwd 28 | 29 | # Push to qiskit.org website 30 | openssl aes-256-cbc -K $encrypted_rclone_key -iv $encrypted_rclone_iv -in tools/rclone.conf.enc -out $RCLONE_CONFIG_PATH -d 31 | echo "Pushing built docs to website" 32 | rclone sync --progress --exclude-from ./tools/other-builds.txt ./docs/_build/html IBMCOS:qiskit-org-web-resources/documentation 33 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | The documentation and benchmarking of Qiskit is contained in this repository. To contribute 4 | to this project or any of the elements of qiskit we recommend you start by reading the 5 | [contributing guide](https://qiskit.org/documentation/contributing_to_qiskit.html). 6 | 7 | ## Contributor License Agreement 8 | 9 | Before you can submit any code we need all contributors to sign a 10 | contributor license agreement. By signing a contributor license 11 | agreement (CLA) you're basically just attesting to the fact 12 | that you are the author of the contribution and that you're freely 13 | contributing it under the terms of the Apache-2.0 license. 14 | 15 | When you contribute to the Qiskit project with a new pull request, 16 | a bot will evaluate whether you have signed the CLA. If required, the 17 | bot will comment on the pull request, including a link to accept the 18 | agreement. The [individual CLA](https://qiskit.org/license/qiskit-cla.pdf) 19 | document is available for review as a PDF. 20 | 21 | **Note**: 22 | > If your contribution is part of your employment or your contribution 23 | > is the property of your employer, then you will likely need to sign a 24 | > [corporate CLA](https://qiskit.org/license/qiskit-corporate-cla.pdf) too and 25 | > email it to us at . 26 | -------------------------------------------------------------------------------- /tools/deploy_documentation_tag.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This code is part of Qiskit. 4 | # 5 | # (C) Copyright IBM 2018, 2019. 6 | # 7 | # This code is licensed under the Apache License, Version 2.0. You may 8 | # obtain a copy of this license in the LICENSE.txt file in the root directory 9 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 10 | # 11 | # Any modifications or derivative works of this code must retain this 12 | # copyright notice, and modified files need to carry a notice indicating 13 | # that they have been altered from the originals. 14 | 15 | # Script for pushing the stable documentation. 16 | set -e 17 | 18 | if [ $# -ne 1 ]; then 19 | echo "Usage: $(basename "$0") " >&2 && exit 1 20 | fi 21 | 22 | curl https://downloads.rclone.org/rclone-current-linux-amd64.deb -o rclone.deb 23 | sudo apt-get install -y ./rclone.deb 24 | 25 | RCLONE_CONFIG_PATH=$(rclone config file | tail -1) 26 | 27 | echo "show current dir: " 28 | pwd 29 | CURRENT_TAG=$1 30 | echo "Got tag $CURRENT_TAG" 31 | IFS=. read -ra VERSION <<< "$CURRENT_TAG" 32 | STABLE_VERSION="${VERSION[0]}.${VERSION[1]}" 33 | echo "Building for stable version $STABLE_VERSION" 34 | 35 | # Build the documentation. 36 | tox -edocs -- -D docs_url_prefix=documentation/stable/"$STABLE_VERSION" -j auto 37 | 38 | # Push to qiskit.org website 39 | openssl aes-256-cbc -K $encrypted_rclone_key -iv $encrypted_rclone_iv -in tools/rclone.conf.enc -out $RCLONE_CONFIG_PATH -d 40 | echo "Pushing built docs to stable site" 41 | rclone sync --progress ./docs/_build/html IBMCOS:qiskit-org-web-resources/documentation/stable/"$STABLE_VERSION" 42 | -------------------------------------------------------------------------------- /.github/workflows/docs.yml: -------------------------------------------------------------------------------- 1 | name: Docs Publish 2 | on: 3 | workflow_dispatch: 4 | push: 5 | branches: [ master ] 6 | 7 | jobs: 8 | deploy: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v3 12 | with: 13 | fetch-depth: 0 14 | - name: Set up Python 15 | uses: actions/setup-python@v4 16 | with: 17 | python-version: '3.8' 18 | - name: Install dependencies 19 | run: | 20 | python -m pip install --upgrade pip 21 | pip install -U virtualenv setuptools wheel 'tox<4' 22 | sudo apt-get install graphviz pandoc 23 | - name: Build and publish 24 | env: 25 | encrypted_rclone_key: ${{ secrets.encrypted_rclone_key }} 26 | encrypted_rclone_iv: ${{ secrets.encrypted_rclone_iv }} 27 | QISKIT_DOCS_BUILD_TUTORIALS: 'always' 28 | QISKIT_ENABLE_ANALYTICS: True 29 | run: | 30 | tools/deploy_documentation.sh 31 | deploy-translatable-strings: 32 | runs-on: ubuntu-latest 33 | steps: 34 | - uses: actions/checkout@v3 35 | with: 36 | fetch-depth: 0 37 | - name: Set up Python 38 | uses: actions/setup-python@v4 39 | with: 40 | python-version: '3.8' 41 | - name: Install dependencies 42 | run: | 43 | python -m pip install --upgrade pip 44 | pip install -U virtualenv setuptools wheel 'tox<4' 45 | sudo apt-get install graphviz pandoc 46 | - name: Build and publish 47 | env: 48 | encrypted_deploy_po_branch_key: ${{ secrets.encrypted_deploy_po_branch_key }} 49 | encrypted_deploy_po_branch_iv: ${{ secrets.encrypted_deploy_po_branch_iv }} 50 | QISKIT_DOCS_BUILD_TUTORIALS: 'always' 51 | run: | 52 | tools/deploy_translatable_strings.sh 53 | -------------------------------------------------------------------------------- /test/benchmarks/isometry.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # This code is part of Qiskit. 4 | # 5 | # (C) Copyright IBM 2019. 6 | # 7 | # This code is licensed under the Apache License, Version 2.0. You may 8 | # obtain a copy of this license in the LICENSE.txt file in the root directory 9 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 10 | # 11 | # Any modifications or derivative works of this code must retain this 12 | # copyright notice, and modified files need to carry a notice indicating 13 | # that they have been altered from the originals. 14 | 15 | # pylint: disable=missing-docstring,invalid-name,no-member 16 | # pylint: disable=attribute-defined-outside-init 17 | # pylint: disable=unused-argument 18 | 19 | from qiskit import QuantumRegister, QuantumCircuit 20 | from qiskit.compiler import transpile 21 | from qiskit.quantum_info.random import random_unitary 22 | 23 | 24 | class IsometryTranspileBench: 25 | params = ([0, 1, 2, 3], [3, 4, 5, 6]) 26 | param_names = ['number of input qubits', 'number of output qubits'] 27 | 28 | def setup(self, m, n): 29 | q = QuantumRegister(n) 30 | qc = QuantumCircuit(q) 31 | if not hasattr(qc, 'iso'): 32 | raise NotImplementedError 33 | iso = random_unitary(2 ** n, seed=0).data[:, 0:2 ** m] 34 | if len(iso.shape) == 1: 35 | iso = iso.reshape((len(iso), 1)) 36 | qc.iso(iso, q[:m], q[m:]) 37 | self.circuit = qc 38 | 39 | def track_cnot_counts_after_mapping_to_ibmq_16_melbourne(self, *unused): 40 | coupling = [[1, 0], [1, 2], [2, 3], [4, 3], [4, 10], [5, 4], 41 | [5, 6], [5, 9], [6, 8], [7, 8], [9, 8], [9, 10], 42 | [11, 3], [11, 10], [11, 12], [12, 2], [13, 1], [13, 12]] 43 | circuit = transpile(self.circuit, basis_gates=['u1', 'u3', 'u2', 'cx'], 44 | coupling_map=coupling, seed_transpiler=0) 45 | counts = circuit.count_ops() 46 | cnot_count = counts.get('cx', 0) 47 | return cnot_count 48 | -------------------------------------------------------------------------------- /test/benchmarks/assembler.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # This code is part of Qiskit. 4 | # 5 | # (C) Copyright IBM 2019. 6 | # 7 | # This code is licensed under the Apache License, Version 2.0. You may 8 | # obtain a copy of this license in the LICENSE.txt file in the root directory 9 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 10 | # 11 | # Any modifications or derivative works of this code must retain this 12 | # copyright notice, and modified files need to carry a notice indicating 13 | # that they have been altered from the originals. 14 | 15 | # pylint: disable=no-member,invalid-name,missing-docstring,no-name-in-module 16 | # pylint: disable=attribute-defined-outside-init,unsubscriptable-object 17 | 18 | from qiskit.compiler import assemble 19 | from qiskit.assembler import disassemble 20 | 21 | from .utils import random_circuit 22 | 23 | 24 | class AssemblerBenchmarks: 25 | params = ([8], 26 | [4096], 27 | [1, 100]) 28 | param_names = ['n_qubits', 'depth', 'number of circuits'] 29 | timeout = 600 30 | version = 2 31 | 32 | def setup(self, n_qubits, depth, number_of_circuits): 33 | seed = 42 34 | self.circuit = random_circuit(n_qubits, depth, measure=True, 35 | conditional=True, seed=seed) 36 | self.circuits = [self.circuit] * number_of_circuits 37 | 38 | def time_assemble_circuit(self, _, __, ___): 39 | assemble(self.circuits) 40 | 41 | 42 | class DisassemblerBenchmarks: 43 | params = ([8], 44 | [4096], 45 | [1, 100]) 46 | param_names = ['n_qubits', 'depth', 'number of circuits'] 47 | timeout = 600 48 | 49 | def setup(self, n_qubits, depth, number_of_circuits): 50 | seed = 424242 51 | self.circuit = random_circuit(n_qubits, depth, measure=True, 52 | conditional=True, seed=seed) 53 | self.circuits = [self.circuit] * number_of_circuits 54 | self.qobj = assemble(self.circuits) 55 | 56 | def time_disassemble_circuit(self, _, __, ___): 57 | disassemble(self.qobj) 58 | -------------------------------------------------------------------------------- /test/benchmarks/converters.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # This code is part of Qiskit. 4 | # 5 | # (C) Copyright IBM 2019. 6 | # 7 | # This code is licensed under the Apache License, Version 2.0. You may 8 | # obtain a copy of this license in the LICENSE.txt file in the root directory 9 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 10 | # 11 | # Any modifications or derivative works of this code must retain this 12 | # copyright notice, and modified files need to carry a notice indicating 13 | # that they have been altered from the originals. 14 | 15 | # pylint: disable=no-member,invalid-name,missing-docstring,no-name-in-module 16 | # pylint: disable=attribute-defined-outside-init,unsubscriptable-object 17 | 18 | from qiskit import converters 19 | from qiskit import qasm 20 | 21 | from .utils import random_circuit 22 | 23 | 24 | class ConverterBenchmarks: 25 | params = ([1, 2, 5, 8, 14, 20, 32, 53], [8, 128, 2048, 8192]) 26 | param_names = ['n_qubits', 'depth'] 27 | timeout = 600 28 | 29 | def setup(self, n_qubits, depth): 30 | seed = 42 31 | # NOTE: Remove the benchmarks larger than 20x2048 and 14x8192, this is 32 | # a tradeoff for speed of benchmarking, creating circuits this size 33 | # takes more time than is worth it for benchmarks that take a couple 34 | # seconds 35 | if n_qubits >= 20: 36 | if depth >= 2048: 37 | raise NotImplementedError 38 | elif n_qubits == 14: 39 | if depth > 2048: 40 | raise NotImplementedError 41 | self.qc = random_circuit(n_qubits, depth, measure=True, 42 | conditional=True, seed=seed) 43 | self.dag = converters.circuit_to_dag(self.qc) 44 | self.qasm = qasm.Qasm(data=self.qc.qasm()).parse() 45 | 46 | def time_circuit_to_dag(self, *_): 47 | converters.circuit_to_dag(self.qc) 48 | 49 | def time_circuit_to_instruction(self, *_): 50 | converters.circuit_to_instruction(self.qc) 51 | 52 | def time_dag_to_circuit(self, *_): 53 | converters.dag_to_circuit(self.dag) 54 | 55 | def time_ast_to_circuit(self, *_): 56 | converters.ast_to_dag(self.qasm) 57 | -------------------------------------------------------------------------------- /test/benchmarks/ripple_adder.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # This code is part of Qiskit. 4 | # 5 | # (C) Copyright IBM 2019. 6 | # 7 | # This code is licensed under the Apache License, Version 2.0. You may 8 | # obtain a copy of this license in the LICENSE.txt file in the root directory 9 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 10 | # 11 | # Any modifications or derivative works of this code must retain this 12 | # copyright notice, and modified files need to carry a notice indicating 13 | # that they have been altered from the originals. 14 | 15 | # pylint: disable=no-member,invalid-name,missing-docstring,no-name-in-module 16 | # pylint: disable=attribute-defined-outside-init,unsubscriptable-object 17 | 18 | from qiskit import transpile 19 | from qiskit.transpiler import CouplingMap 20 | 21 | from .utils import build_ripple_adder_circuit 22 | 23 | 24 | class RippleAdderConstruction: 25 | params = ([10, 50, 100, 200, 500],) 26 | param_names = ['size'] 27 | version = 1 28 | timeout = 600 29 | 30 | def time_build_ripple_adder(self, size): 31 | build_ripple_adder_circuit(size) 32 | 33 | 34 | class RippleAdderTranspile: 35 | params = ([10, 20], 36 | [0, 1, 2, 3]) 37 | param_names = ['size', 'level'] 38 | version = 1 39 | timeout = 600 40 | 41 | def setup(self, size, _): 42 | edge_len = int((2*size + 2)**0.5)+1 43 | self.coupling_map = CouplingMap.from_grid(edge_len, edge_len) 44 | self.circuit = build_ripple_adder_circuit(size) 45 | 46 | def time_transpile_square_grid_ripple_adder(self, _, level): 47 | transpile(self.circuit, 48 | coupling_map=self.coupling_map, 49 | basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], 50 | optimization_level=level, 51 | seed_transpiler=20220125) 52 | 53 | def track_depth_transpile_square_grid_ripple_adder(self, _, level): 54 | return transpile(self.circuit, 55 | coupling_map=self.coupling_map, 56 | basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], 57 | optimization_level=level, 58 | seed_transpiler=20220125).depth() 59 | -------------------------------------------------------------------------------- /test/benchmarks/state_tomography.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # This code is part of Qiskit. 4 | # 5 | # (C) Copyright IBM 2017, 2019. 6 | # 7 | # This code is licensed under the Apache License, Version 2.0. You may 8 | # obtain a copy of this license in the LICENSE.txt file in the root directory 9 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 10 | # 11 | # Any modifications or derivative works of this code must retain this 12 | # copyright notice, and modified files need to carry a notice indicating 13 | # that they have been altered from the originals. 14 | 15 | # pylint: disable=missing-docstring,invalid-name,no-member,broad-except 16 | # pylint: disable=no-else-return, attribute-defined-outside-init 17 | # pylint: disable=import-error 18 | 19 | import qiskit 20 | from qiskit_experiments.library import StateTomography 21 | 22 | 23 | class StateTomographyBench: 24 | params = [2, 3, 4, 5] 25 | param_names = ['n_qubits'] 26 | version = '0.3.0' 27 | timeout = 120.0 28 | 29 | def setup(self, _): 30 | self.qasm_backend = qiskit.BasicAer.get_backend('qasm_simulator') 31 | 32 | def time_state_tomography_bell(self, n_qubits): 33 | meas_qubits = [n_qubits - 2, n_qubits - 1] 34 | qr_full = qiskit.QuantumRegister(n_qubits) 35 | bell = qiskit.QuantumCircuit(qr_full) 36 | bell.h(qr_full[meas_qubits[0]]) 37 | bell.cx(qr_full[meas_qubits[0]], qr_full[meas_qubits[1]]) 38 | 39 | qst_exp = StateTomography(bell, measurement_qubits=meas_qubits) 40 | expdata = qst_exp.run( 41 | self.qasm_backend, shots=5000).block_for_results() 42 | expdata.analysis_results("state") 43 | expdata.analysis_results("state_fidelity") 44 | 45 | def time_state_tomography_cat(self, n_qubits): 46 | qr = qiskit.QuantumRegister(n_qubits, 'qr') 47 | circ = qiskit.QuantumCircuit(qr, name='cat') 48 | circ.h(qr[0]) 49 | for i in range(1, n_qubits): 50 | circ.cx(qr[0], qr[i]) 51 | qst_exp = StateTomography(circ) 52 | expdata = qst_exp.run( 53 | self.qasm_backend, shots=5000).block_for_results() 54 | expdata.analysis_results("state") 55 | expdata.analysis_results("state_fidelity") 56 | -------------------------------------------------------------------------------- /docs/maintainers_guide.rst: -------------------------------------------------------------------------------- 1 | ################# 2 | Maintainers Guide 3 | ################# 4 | 5 | This document defines a *maintainer* as a contributor with merge privileges. 6 | The information detailed here is mostly related to Qiskit releases and other internal processes. 7 | 8 | .. _stable_branch_policy: 9 | 10 | Stable Branch Policy 11 | ==================== 12 | 13 | The stable branch is intended to be a safe source of fixes for high-impact 14 | bugs and security issues that have been fixed on master since a 15 | release. When reviewing a stable branch PR, we must balance the risk 16 | of any given patch with the value that it will provide to users of the 17 | stable branch. Only a limited class of changes are appropriate for 18 | inclusion on the stable branch. A large, risky patch for a major issue 19 | might make sense, as might a trivial fix for a fairly obscure error-handling 20 | case. A number of factors must be weighed when considering a 21 | change: 22 | 23 | - The risk of regression: even the tiniest changes carry some risk of 24 | breaking something, and we really want to avoid regressions on the 25 | stable branch. 26 | - The user visibility benefit: are we fixing something that users might 27 | actually notice, and if so, how important is it? 28 | - How self-contained the fix is: if it fixes a significant issue but 29 | also refactors a lot of code, it's probably worth thinking about 30 | what a less risky fix might look like. 31 | - Whether the fix is already on ``main``: a change must be a backport of 32 | a change already merged onto master, unless the change simply does 33 | not make sense on master. 34 | 35 | 36 | Backporting 37 | ----------- 38 | 39 | When a PR tagged with ``stable backport potential`` is merged, or when a 40 | merged PR is given that tag, the `Mergify bot `__ will 41 | open a PR to the current stable branch. You can review and merge this PR 42 | like normal. 43 | 44 | 45 | Documentation Structure 46 | ======================= 47 | 48 | The way documentation is structured in Qiskit is to push as much of the actual 49 | documentation into the docstrings as possible. This makes it easier for 50 | additions and corrections to be made during development, because the majority 51 | of the documentation lives near the code being changed. 52 | 53 | Refer to https://qiskit.github.io/qiskit_sphinx_theme/apidocs/index.html for how to create and 54 | write effective API documentation, such as setting up the RST files and docstrings. 55 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | minversion = 3.15.0 3 | envlist = py36, py37, py38, py39, py310, lint, docs 4 | skipsdist = True 5 | 6 | [testenv] 7 | usedevelop = true 8 | install_command = pip install -c{toxinidir}/constraints.txt -U {opts} {packages} 9 | setenv = 10 | VIRTUAL_ENV={envdir} 11 | LANGUAGE=en_US 12 | LC_ALL=en_US.utf-8 13 | commands = 14 | pip check 15 | python -m unittest -v 16 | 17 | [testenv:fmt] 18 | deps = 19 | -r requirements-dev.txt 20 | commands = 21 | black docs/ test/ tools/ setup.py 22 | isort docs/ test/ tools/ setup.py 23 | [testenv:lint] 24 | deps = 25 | -r requirements-dev.txt 26 | pylint 27 | doc8 28 | ipython 29 | commands = 30 | black --check docs/ test/ tools/ setup.py 31 | isort --check docs/ test/ tools/ setup.py 32 | pylint -rn --rcfile={toxinidir}/.pylintrc test 33 | doc8 docs --ignore-path docs/_templates --ignore-path docs/stubs 34 | 35 | [testenv:asv] 36 | deps = 37 | asv 38 | virtualenv 39 | commands = 40 | asv run {posargs} 41 | 42 | [testenv:docs] 43 | # Editable mode breaks macOS: https://github.com/sphinx-doc/sphinx/issues/10943 44 | usedevelop = false 45 | envdir = .tox/docs 46 | passenv = 47 | QISKIT_DOCS_BUILD_TUTORIALS 48 | QISKIT_ENABLE_ANALYTICS 49 | extras = 50 | all 51 | deps = 52 | -r requirements-dev.txt 53 | sphinx-intl 54 | # On macOS Tox 3.28, setting `extras` resulted in the package not being installed at all. 55 | # It does not hurt to also install the package in the `deps` stage. 56 | .[all] 57 | commands = 58 | sphinx-build -W --keep-going -j auto -b html {posargs} -d {toxinidir}/docs/.doctrees {toxinidir}/docs/ {toxinidir}/docs/_build/html 59 | 60 | [testenv:docs-clean] 61 | skip_install = true 62 | deps = 63 | allowlist_externals = 64 | rm 65 | commands = 66 | rm -rf \ 67 | {toxinidir}/stubs/ \ 68 | {toxinidir}/docs/_build \ 69 | {toxinidir}/docs/stubs \ 70 | {toxinidir}/docs/apidoc \ 71 | {toxinidir}/docs/tutorials \ 72 | {toxinidir}/docs/migration_guides \ 73 | {toxinidir}/docs/source_images \ 74 | {toxinidir}/docs/_templates \ 75 | {toxinidir}/docs/plot_directive \ 76 | {toxinidir}/docs/jupyter_execute \ 77 | {toxinidir}/docs/.doctrees 78 | 79 | [testenv:gettext] 80 | envdir = .tox/docs 81 | deps = 82 | -r requirements-dev.txt 83 | sphinx-intl 84 | commands = 85 | sphinx-build -b gettext docs/ docs/_build/gettext {posargs} 86 | sphinx-intl -c docs/conf.py update -p docs/_build/gettext -l en -d docs/locale 87 | 88 | [doc8] 89 | max-line-length=200 90 | ignore-path=docs/_build 91 | -------------------------------------------------------------------------------- /test/benchmarks/qasm/depth_4gt10-v1_81.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 2.0; 2 | include "qelib1.inc"; 3 | qreg q[16]; 4 | creg c[16]; 5 | x q[0]; 6 | h q[1]; 7 | t q[2]; 8 | t q[3]; 9 | t q[1]; 10 | cx q[3],q[2]; 11 | cx q[1],q[3]; 12 | cx q[2],q[1]; 13 | tdg q[3]; 14 | cx q[2],q[3]; 15 | tdg q[2]; 16 | tdg q[3]; 17 | t q[1]; 18 | cx q[1],q[3]; 19 | cx q[2],q[1]; 20 | cx q[3],q[2]; 21 | h q[1]; 22 | h q[3]; 23 | t q[0]; 24 | t q[4]; 25 | t q[3]; 26 | cx q[4],q[0]; 27 | cx q[3],q[4]; 28 | cx q[0],q[3]; 29 | tdg q[4]; 30 | cx q[0],q[4]; 31 | tdg q[0]; 32 | tdg q[4]; 33 | t q[3]; 34 | cx q[3],q[4]; 35 | cx q[0],q[3]; 36 | cx q[4],q[0]; 37 | h q[3]; 38 | h q[1]; 39 | t q[2]; 40 | t q[3]; 41 | t q[1]; 42 | cx q[3],q[2]; 43 | cx q[1],q[3]; 44 | cx q[2],q[1]; 45 | tdg q[3]; 46 | cx q[2],q[3]; 47 | tdg q[2]; 48 | tdg q[3]; 49 | t q[1]; 50 | cx q[1],q[3]; 51 | cx q[2],q[1]; 52 | cx q[3],q[2]; 53 | h q[1]; 54 | h q[3]; 55 | t q[0]; 56 | t q[4]; 57 | t q[3]; 58 | cx q[4],q[0]; 59 | cx q[3],q[4]; 60 | cx q[0],q[3]; 61 | tdg q[4]; 62 | cx q[0],q[4]; 63 | tdg q[0]; 64 | tdg q[4]; 65 | t q[3]; 66 | cx q[3],q[4]; 67 | cx q[0],q[3]; 68 | cx q[4],q[0]; 69 | h q[3]; 70 | cx q[2],q[0]; 71 | h q[2]; 72 | t q[3]; 73 | t q[0]; 74 | t q[2]; 75 | cx q[0],q[3]; 76 | cx q[2],q[0]; 77 | cx q[3],q[2]; 78 | tdg q[0]; 79 | cx q[3],q[0]; 80 | tdg q[3]; 81 | tdg q[0]; 82 | t q[2]; 83 | cx q[2],q[0]; 84 | cx q[3],q[2]; 85 | cx q[0],q[3]; 86 | h q[2]; 87 | h q[0]; 88 | t q[1]; 89 | t q[4]; 90 | t q[0]; 91 | cx q[4],q[1]; 92 | cx q[0],q[4]; 93 | cx q[1],q[0]; 94 | tdg q[4]; 95 | cx q[1],q[4]; 96 | tdg q[1]; 97 | tdg q[4]; 98 | t q[0]; 99 | cx q[0],q[4]; 100 | cx q[1],q[0]; 101 | cx q[4],q[1]; 102 | h q[0]; 103 | h q[2]; 104 | t q[3]; 105 | t q[0]; 106 | t q[2]; 107 | cx q[0],q[3]; 108 | cx q[2],q[0]; 109 | cx q[3],q[2]; 110 | tdg q[0]; 111 | cx q[3],q[0]; 112 | tdg q[3]; 113 | tdg q[0]; 114 | t q[2]; 115 | cx q[2],q[0]; 116 | cx q[3],q[2]; 117 | cx q[0],q[3]; 118 | h q[2]; 119 | h q[0]; 120 | t q[1]; 121 | t q[4]; 122 | t q[0]; 123 | cx q[4],q[1]; 124 | cx q[0],q[4]; 125 | cx q[1],q[0]; 126 | tdg q[4]; 127 | cx q[1],q[4]; 128 | tdg q[1]; 129 | tdg q[4]; 130 | t q[0]; 131 | cx q[0],q[4]; 132 | cx q[1],q[0]; 133 | cx q[4],q[1]; 134 | h q[0]; 135 | cx q[1],q[4]; 136 | cx q[4],q[2]; 137 | h q[4]; 138 | t q[2]; 139 | t q[0]; 140 | t q[4]; 141 | cx q[0],q[2]; 142 | cx q[4],q[0]; 143 | cx q[2],q[4]; 144 | tdg q[0]; 145 | cx q[2],q[0]; 146 | tdg q[2]; 147 | tdg q[0]; 148 | t q[4]; 149 | cx q[4],q[0]; 150 | cx q[2],q[4]; 151 | cx q[0],q[2]; 152 | h q[4]; 153 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # editor files 2 | .vscode/ 3 | .idea/ 4 | 5 | #standard python ignores follow 6 | 7 | # Byte-compiled / optimized / DLL files 8 | __pycache__/ 9 | .pytest_cache/ 10 | *.py[cod] 11 | *$py.class 12 | 13 | # C extensions 14 | *.so 15 | 16 | # Distribution / packaging 17 | .Python 18 | env/ 19 | build/ 20 | develop-eggs/ 21 | dist/ 22 | downloads/ 23 | eggs/ 24 | .eggs/ 25 | parts/ 26 | sdist/ 27 | var/ 28 | wheels/ 29 | *.egg-info/ 30 | .installed.cfg 31 | *.egg 32 | 33 | # PyInstaller 34 | # Usually these files are written by a python script from a template 35 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 36 | *.manifest 37 | *.spec 38 | 39 | # Installer logs 40 | pip-log.txt 41 | pip-delete-this-directory.txt 42 | 43 | # Unit test / coverage reports 44 | htmlcov/ 45 | .tox/ 46 | .coverage 47 | .coverage.* 48 | .cache 49 | nosetests.xml 50 | coverage.xml 51 | *,cover 52 | .hypothesis/ 53 | test/python/*.log 54 | test/python/*.pdf 55 | test/python/*.prof 56 | .stestr/ 57 | 58 | # Translations 59 | *.mo 60 | *.pot 61 | 62 | # Django stuff: 63 | *.log 64 | local_settings.py 65 | 66 | # Flask stuff: 67 | instance/ 68 | .webassets-cache 69 | 70 | # Scrapy stuff: 71 | .scrapy 72 | 73 | # Sphinx documentation 74 | docs/_build/ 75 | docs/apidoc 76 | docs/tutorials 77 | docs/stubs 78 | docs/plot_directive 79 | docs/jupyter_execute/ 80 | docs/migration_guides 81 | docs/_templates 82 | docs/source_images 83 | docs/.doctrees/ 84 | stubs/ 85 | 86 | # PyBuilder 87 | target/ 88 | 89 | # Jupyter Notebook 90 | .ipynb_checkpoints 91 | 92 | # pyenv 93 | .python-version 94 | 95 | # celery beat schedule file 96 | celerybeat-schedule 97 | 98 | # SageMath parsed files 99 | *.sage.py 100 | 101 | # dotenv 102 | .env 103 | 104 | # virtualenv 105 | .venv 106 | venv/ 107 | ENV/ 108 | 109 | # Spyder project settings 110 | .spyderproject 111 | 112 | # Rope project settings 113 | .ropeproject 114 | 115 | .DS_Store 116 | 117 | dummyscripts/* 118 | 119 | token.json 120 | 121 | tutorial/rst/_build/* 122 | 123 | test/python/test_qasm_python_simulator.pdf 124 | 125 | qiskit/terra/bin/* 126 | 127 | test/python/test_save.json 128 | 129 | test/python/*.tex 130 | 131 | out/* 132 | 133 | # CMake generates this file on the fly 134 | qiskit/terra/backends/local/qasm_simulator_cpp 135 | qiskit/terra/backends/aer/qasm_simulator_cpp 136 | 137 | src/qasm-simulator-cpp/test/qubit_vector_tests 138 | 139 | *.o 140 | 141 | # ASV Tests 142 | .asv/ 143 | html/ 144 | qiskit-terra/ 145 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | # Entries in this file are made for two reasons: 2 | # 1) to merge multiple git commit authors that correspond to a single author 3 | # 2) to change the canonical name and/or email address of an author. 4 | # 5 | # Format is: 6 | # Canonical Name commit name 7 | # \--------------+---------------/ \----------+-------------/ 8 | # replace find 9 | # See also: 'git shortlog --help' and 'git check-mailmap --help'. 10 | # 11 | # If you don't like the way your name is cited by qiskit, please feel free to 12 | # open a pull request against this file to set your preferred naming. 13 | # 14 | # Note that each qiskit element uses its own mailmap so it may be necessary to 15 | # propagate changes in other repos for consistency. 16 | 17 | Albert Frisch 18 | Alejandro Pozas-Kerstjens 19 | Ali Javadi-Abhari 20 | Ali Javadi-Abhari 21 | Carlos Azaustre 22 | Christa Zoufal <40824883+Zoufalc@users.noreply.github.com> 23 | Christian Claus 24 | Christopher J. Wood 25 | David McKay 26 | Diego M. Rodriguez 27 | gadial 28 | Hassi Norlen 29 | James R. Garrison 30 | James R. Garrison 31 | Jay M. Gambetta 32 | Juan Cruz-Benito 33 | Juan Gomez 34 | Laura Zdanski 35 | Leron Gil 36 | Maddy Tod <40489777+maddy-tod@users.noreply.github.com> 37 | Marco Pistoia 38 | Matthew Treinish 39 | Matthieu Dartiailh 40 | Paul Kassebaum 41 | Paul Nation 42 | Richard Chen 43 | Rohit Midha <38888530+RohitMidha23@users.noreply.github.com> 44 | Ryan Woo 45 | Salvador de la Puente González 46 | Salvador de la Puente González 47 | Shaohan Hu 48 | Shelly Garion <46566946+ShellyGarion@users.noreply.github.com> 49 | Simone Perriello 50 | Soolu Thomas 51 | Steven Oud 52 | Travis L. Scholten 53 | Travis L. Scholten 54 | Yael Ben-Haim 55 | Yehuda Naveh 56 | Zlatko Minev 57 | -------------------------------------------------------------------------------- /test/benchmarks/qasm/time_cnt3-5_179.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 2.0; 2 | include "qelib1.inc"; 3 | qreg q[16]; 4 | creg c[16]; 5 | cx q[12],q[15]; 6 | h q[12]; 7 | t q[14]; 8 | t q[13]; 9 | t q[12]; 10 | cx q[13],q[14]; 11 | cx q[12],q[13]; 12 | cx q[14],q[12]; 13 | tdg q[13]; 14 | cx q[14],q[13]; 15 | tdg q[14]; 16 | tdg q[13]; 17 | t q[12]; 18 | cx q[12],q[13]; 19 | cx q[14],q[12]; 20 | cx q[13],q[14]; 21 | h q[12]; 22 | cx q[12],q[15]; 23 | h q[14]; 24 | t q[15]; 25 | t q[13]; 26 | t q[14]; 27 | cx q[13],q[15]; 28 | cx q[14],q[13]; 29 | cx q[15],q[14]; 30 | tdg q[13]; 31 | cx q[15],q[13]; 32 | tdg q[15]; 33 | tdg q[13]; 34 | t q[14]; 35 | cx q[14],q[13]; 36 | cx q[15],q[14]; 37 | cx q[13],q[15]; 38 | h q[14]; 39 | cx q[13],q[15]; 40 | cx q[9],q[11]; 41 | h q[9]; 42 | t q[10]; 43 | t q[12]; 44 | t q[9]; 45 | cx q[12],q[10]; 46 | cx q[9],q[12]; 47 | cx q[10],q[9]; 48 | tdg q[12]; 49 | cx q[10],q[12]; 50 | tdg q[10]; 51 | tdg q[12]; 52 | t q[9]; 53 | cx q[9],q[12]; 54 | cx q[10],q[9]; 55 | cx q[12],q[10]; 56 | h q[9]; 57 | cx q[9],q[11]; 58 | h q[10]; 59 | t q[11]; 60 | t q[12]; 61 | t q[10]; 62 | cx q[12],q[11]; 63 | cx q[10],q[12]; 64 | cx q[11],q[10]; 65 | tdg q[12]; 66 | cx q[11],q[12]; 67 | tdg q[11]; 68 | tdg q[12]; 69 | t q[10]; 70 | cx q[10],q[12]; 71 | cx q[11],q[10]; 72 | cx q[12],q[11]; 73 | h q[10]; 74 | cx q[12],q[11]; 75 | cx q[6],q[8]; 76 | h q[6]; 77 | t q[7]; 78 | t q[9]; 79 | t q[6]; 80 | cx q[9],q[7]; 81 | cx q[6],q[9]; 82 | cx q[7],q[6]; 83 | tdg q[9]; 84 | cx q[7],q[9]; 85 | tdg q[7]; 86 | tdg q[9]; 87 | t q[6]; 88 | cx q[6],q[9]; 89 | cx q[7],q[6]; 90 | cx q[9],q[7]; 91 | h q[6]; 92 | cx q[6],q[8]; 93 | h q[7]; 94 | t q[8]; 95 | t q[9]; 96 | t q[7]; 97 | cx q[9],q[8]; 98 | cx q[7],q[9]; 99 | cx q[8],q[7]; 100 | tdg q[9]; 101 | cx q[8],q[9]; 102 | tdg q[8]; 103 | tdg q[9]; 104 | t q[7]; 105 | cx q[7],q[9]; 106 | cx q[8],q[7]; 107 | cx q[9],q[8]; 108 | h q[7]; 109 | cx q[9],q[8]; 110 | cx q[3],q[5]; 111 | h q[3]; 112 | t q[4]; 113 | t q[6]; 114 | t q[3]; 115 | cx q[6],q[4]; 116 | cx q[3],q[6]; 117 | cx q[4],q[3]; 118 | tdg q[6]; 119 | cx q[4],q[6]; 120 | tdg q[4]; 121 | tdg q[6]; 122 | t q[3]; 123 | cx q[3],q[6]; 124 | cx q[4],q[3]; 125 | cx q[6],q[4]; 126 | h q[3]; 127 | cx q[3],q[5]; 128 | h q[4]; 129 | t q[5]; 130 | t q[6]; 131 | t q[4]; 132 | cx q[6],q[5]; 133 | cx q[4],q[6]; 134 | cx q[5],q[4]; 135 | tdg q[6]; 136 | cx q[5],q[6]; 137 | tdg q[5]; 138 | tdg q[6]; 139 | t q[4]; 140 | cx q[4],q[6]; 141 | cx q[5],q[4]; 142 | cx q[6],q[5]; 143 | h q[4]; 144 | cx q[6],q[5]; 145 | cx q[0],q[2]; 146 | h q[0]; 147 | t q[1]; 148 | t q[3]; 149 | t q[0]; 150 | cx q[3],q[1]; 151 | cx q[0],q[3]; 152 | cx q[1],q[0]; 153 | tdg q[3]; 154 | cx q[1],q[3]; 155 | tdg q[1]; 156 | tdg q[3]; 157 | t q[0]; 158 | cx q[0],q[3]; 159 | cx q[1],q[0]; 160 | cx q[3],q[1]; 161 | h q[0]; 162 | cx q[0],q[2]; 163 | h q[1]; 164 | t q[2]; 165 | t q[3]; 166 | t q[1]; 167 | cx q[3],q[2]; 168 | cx q[1],q[3]; 169 | cx q[2],q[1]; 170 | tdg q[3]; 171 | cx q[2],q[3]; 172 | tdg q[2]; 173 | tdg q[3]; 174 | t q[1]; 175 | cx q[1],q[3]; 176 | cx q[2],q[1]; 177 | cx q[3],q[2]; 178 | h q[1]; 179 | cx q[3],q[2]; 180 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | ############################## 2 | Qiskit |version| documentation 3 | ############################## 4 | 5 | Qiskit is open-source software for working with quantum computers 6 | at the level of circuits, pulses, and algorithms. 7 | 8 | The central goal of Qiskit is to build a software stack 9 | that makes it easy for anyone to use quantum computers, regardless of their skill level or 10 | area of interest; Qiskit allows one to easily design experiments and applications and run 11 | them on real quantum computers or classical simulators. Qiskit is already in use 12 | around the world by beginners, hobbyists, educators, researchers, and commercial companies. 13 | 14 | 15 | .. qiskit-call-to-action-grid:: 16 | 17 | .. qiskit-call-to-action-item:: 18 | :header: Access to quantum systems 19 | :description: Find out which Qiskit providers support execution on real quantum services. 20 | :button_link: https://qiskit.org/providers 21 | :button_text: Quantum providers 22 | 23 | .. qiskit-call-to-action-item:: 24 | :header: Qiskit ecosystem 25 | :description: The Qiskit ecosystem consists of projects, tools, utilities, libraries and tutorials from a broad community of developers and researchers. 26 | :button_link: https://qiskit.org/ecosystem/ 27 | :button_text: Explore the Qiskit ecosystem 28 | 29 | 30 | Main Qiskit-related projects 31 | ############################ 32 | 33 | .. qiskit-call-to-action-grid:: 34 | 35 | .. qiskit-call-to-action-item:: 36 | :header: Qiskit Experiments 37 | :description: Run characterization, calibration, and verification experiments 38 | :button_link: https://qiskit.org/ecosystem/experiments/ 39 | :button_text: Qiskit Experiments documentation 40 | 41 | .. qiskit-call-to-action-item:: 42 | :header: Qiskit Dynamics 43 | :description: Tools for building and solving models of quantum systems in Qiskit 44 | :button_link: https://qiskit.org/ecosystem/dynamics/ 45 | :button_text: Qiskit Dynamics documentation 46 | 47 | .. qiskit-call-to-action-item:: 48 | :header: Qiskit IBM Runtime 49 | :description: Qiskit Runtime is a cloud base implementation of the Qiskit primitives to effectively execute workloads on IBM Quantum systems. 50 | :button_link: https://qiskit.org/ecosystem/ibm-runtime/ 51 | :button_text: Qiskit Runtime documentation 52 | 53 | .. qiskit-call-to-action-item:: 54 | :header: IBM Quantum Provider 55 | :description: A Qiskit provider that allows accessing the IBM Quantum systems and cloud simulators. 56 | :button_link: https://qiskit.org/ecosystem/ibm-runtime/ 57 | :button_text: Qiskit IBM provider documentation 58 | 59 | 60 | .. toctree:: 61 | :hidden: 62 | 63 | Documentation Home 64 | qc_intro 65 | getting_started 66 | intro_tutorial1 67 | tutorials 68 | API Reference 69 | Migration Guides 70 | release_notes 71 | configuration 72 | GitHub 73 | faq 74 | 75 | .. toctree:: 76 | :caption: Contributing 77 | :hidden: 78 | 79 | contributing_to_qiskit 80 | deprecation_policy 81 | maintainers_guide 82 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Qiskit Metapackage (_ARCHIVED_) 2 | 3 | 4 | | ⚠️ NOTE ⚠️ | 5 | |------------------------------------------| 6 | | Since August 2023, this repository is archived as all the `qiskit` PyPI metapackage infrastructure and documentation was moved to [Qiskit/qiskit](https://github.com/Qiskit/qiskit) (formerly [Qiskit/qiskit-terra](https://github.com/Qiskit/qiskit-terra)). See [RFC0011 for details](https://github.com/Qiskit/RFCs/blob/master/0011-repo-rename.md).| 7 | 8 | [![License](https://img.shields.io/github/license/Qiskit/qiskit-metapackage.svg?)](https://opensource.org/licenses/Apache-2.0) 9 | ![Build Status](https://github.com/Qiskit/qiskit-metapackage/actions/workflows/main.yml/badge.svg?branch=master) 10 | [![](https://img.shields.io/github/release/Qiskit/qiskit-metapackage.svg)](https://github.com/Qiskit/qiskit-metapackage/releases) 11 | [![Downloads](https://static.pepy.tech/badge/qiskit)](https://pepy.tech/project/qiskit) 12 | [![DOI](https://zenodo.org/badge/161550823.svg)](https://zenodo.org/badge/latestdoi/161550823) 13 | 14 | **Qiskit** is an open-source SDK for working with quantum computers at the level of circuits, algorithms, and application modules. 15 | 16 | ## Installation 17 | 18 | The best way of installing `qiskit` is by using `pip`: 19 | 20 | ```bash 21 | $ pip install qiskit 22 | ``` 23 | 24 | See [install](https://qiskit.org/documentation/getting_started.html) Qiskit for detailed instructions, how to use virtual environments, and 25 | build from source standalone versions of the individual Qiskit elements and components. 26 | 27 | ## Qiskit Packaging 28 | 29 | The Qiskit project used to be made up of many components. However, it is now only comprised of the [**Qiskit Terra**](https://github.com/Qiskit/qiskit-terra) 30 | project and the Qiskit meta-package contained in this repository only installs that. 31 | 32 | ### Using quantum services 33 | 34 | If you are interested in using quantum services, you can check out [the Providers page](https://qiskit.org/providers/) for the list of available providers that Qiskit supports. 35 | 36 | ## Contribution Guidelines 37 | 38 | If you'd like to contribute to Qiskit, please take a look at our 39 | [contribution guidelines](https://qiskit.org/documentation/contributing_to_qiskit.html). This project adheres to Qiskit's [code of conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. 40 | 41 | We use [GitHub issues](https://github.com/Qiskit/qiskit-metapackage/issues) for tracking requests and bugs. Please use our [Slack](https://qisk.it/join-slack) for discussion and simple questions. For questions that are more suited for a forum we use the Qiskit tag in the [Stack Exchange](https://quantumcomputing.stackexchange.com/questions/tagged/qiskit). 42 | 43 | ## Next Steps 44 | 45 | Now you're set up and ready to check out our 46 | [Qiskit Tutorials](https://github.com/Qiskit/qiskit-tutorials) repository. 47 | 48 | ## Authors and Citation 49 | 50 | Qiskit is the work of [many people who contribute to the project](https://github.com/Qiskit/qiskit-terra/graphs/contributors) at 51 | different levels. If you use Qiskit, please cite as per the included 52 | [BibTeX file](https://github.com/Qiskit/qiskit-terra/blob/main/CITATION.bib). 53 | 54 | ## License 55 | 56 | [Apache License 2.0](LICENSE.txt) 57 | -------------------------------------------------------------------------------- /test/benchmarks/pulse/schedule_lowering.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -* 2 | 3 | # This code is part of Qiskit. 4 | # 5 | # (C) Copyright IBM 2020. 6 | # 7 | # This code is licensed under the Apache License, Version 2.0. You may 8 | # obtain a copy of this license in the LICENSE.txt file in the root directory 9 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 10 | # 11 | # Any modifications or derivative works of this code must retain this 12 | # copyright notice, and modified files need to carry a notice indicating 13 | # that they have been altered from the originals. 14 | 15 | # pylint: disable=missing-docstring,invalid-name,no-member 16 | # pylint: disable=attribute-defined-outside-init 17 | 18 | import numpy as np 19 | 20 | from qiskit.pulse import builder, library, channels 21 | from qiskit.pulse.transforms import target_qobj_transform 22 | 23 | 24 | def build_complicated_schedule(): 25 | 26 | with builder.build() as schedule: 27 | with builder.align_sequential(): 28 | with builder.align_right(): 29 | with builder.phase_offset(np.pi, channels.ControlChannel(2)): 30 | with builder.align_sequential(): 31 | for _ in range(5): 32 | builder.play( 33 | library.GaussianSquare(640, 0.1, 64, 384), 34 | channels.ControlChannel(2), 35 | ) 36 | builder.play( 37 | library.Constant(1920, 0.1), 38 | channels.DriveChannel(1), 39 | ) 40 | builder.barrier( 41 | channels.DriveChannel(0), 42 | channels.DriveChannel(1), 43 | channels.DriveChannel(2), 44 | ) 45 | builder.delay(800, channels.DriveChannel(1)) 46 | with builder.align_left(): 47 | builder.play( 48 | library.Drag(160, 0.3, 40, 1.5), 49 | channels.DriveChannel(0), 50 | ) 51 | builder.play( 52 | library.Drag(320, 0.2, 80, 1.5), 53 | channels.DriveChannel(1), 54 | ) 55 | builder.play( 56 | library.Drag(480, 0.1, 120, 1.5), 57 | channels.DriveChannel(2), 58 | ) 59 | builder.reference("sub") 60 | with builder.align_left(): 61 | for i in range(3): 62 | builder.play( 63 | library.GaussianSquare(1600, 0.1, 64, 1344), 64 | channels.MeasureChannel(i), 65 | ) 66 | builder.acquire( 67 | 1600, 68 | channels.AcquireChannel(i), 69 | channels.MemorySlot(i), 70 | ) 71 | 72 | with builder.build() as subroutine: 73 | for i in range(3): 74 | samples = np.random.random(160) 75 | builder.play(samples, channels.DriveChannel(i)) 76 | schedule.assign_references({("sub", ): subroutine}, inplace=True) 77 | 78 | return schedule 79 | 80 | 81 | class ScheduleLoweringBench: 82 | 83 | def setup(self): 84 | self.schedule_block = build_complicated_schedule() 85 | 86 | def time_lowering(self): 87 | # Lower schedule block to generate job payload 88 | target_qobj_transform(self.schedule_block) 89 | -------------------------------------------------------------------------------- /tools/deploy_translatable_strings.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This code is part of Qiskit. 4 | # 5 | # (C) Copyright IBM 2018, 2019. 6 | # 7 | # This code is licensed under the Apache License, Version 2.0. You may 8 | # obtain a copy of this license in the LICENSE.txt file in the root directory 9 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 10 | # 11 | # Any modifications or derivative works of this code must retain this 12 | # copyright notice, and modified files need to carry a notice indicating 13 | # that they have been altered from the originals. 14 | 15 | # Script for pushing the translatable messages to poBranch. 16 | 17 | 18 | # Non-travis variables used by this script. 19 | TARGET_REPOSITORY="git@github.com:qiskit-community/qiskit-translations.git" 20 | SOURCE_DOC_DIR="docs/_build/html" 21 | SOURCE_DIR=`pwd` 22 | SOURCE_LANG='en' 23 | 24 | SOURCE_REPOSITORY="git@github.com:Qiskit/qiskit.git" 25 | TARGET_BRANCH_PO="master" 26 | DOC_DIR_PO="docs/locale" 27 | 28 | echo "show current dir: " 29 | pwd 30 | 31 | pushd docs 32 | 33 | # Extract document's translatable messages into pot files 34 | # https://sphinx-intl.readthedocs.io/en/master/quickstart.html 35 | echo "Extract document's translatable messages into pot files and generate po files" 36 | tox -egettext -- -D language=$SOURCE_LANG 37 | 38 | echo "Setup ssh keys" 39 | pwd 40 | set -e 41 | # Add poBranch push key to ssh-agent 42 | openssl enc -aes-256-cbc -d -in ../tools/github_poBranch_update_key.enc -out github_poBranch_deploy_key -K $encrypted_deploy_po_branch_key -iv $encrypted_deploy_po_branch_iv 43 | chmod 600 github_poBranch_deploy_key 44 | eval $(ssh-agent -s) 45 | ssh-add github_poBranch_deploy_key 46 | 47 | # Clone to the working repository for .po and pot files 48 | popd 49 | pwd 50 | echo "git clone for working repo" 51 | git clone --depth 1 $TARGET_REPOSITORY temp --single-branch --branch $TARGET_BRANCH_PO 52 | pushd temp 53 | 54 | git config user.name "Qiskit Autodeploy" 55 | git config user.email "qiskit@qiskit.org" 56 | 57 | echo "git rm -rf for the translation po files" 58 | git rm -rf --ignore-unmatch $DOC_DIR_PO/$SOURCE_LANG/LC_MESSAGES/*.po \ 59 | $DOC_DIR_PO/$SOURCE_LANG/LC_MESSAGES/api \ 60 | $DOC_DIR_PO/$SOURCE_LANG/LC_MESSAGES/apidoc \ 61 | $DOC_DIR_PO/$SOURCE_LANG/LC_MESSAGES/apidoc_legacy \ 62 | $DOC_DIR_PO/$SOURCE_LANG/LC_MESSAGES/theme \ 63 | $DOC_DIR_PO/$SOURCE_LANG/LC_MESSAGES/_* 64 | 65 | # Remove api/ and apidoc/ to avoid confusion while translating 66 | rm -rf $SOURCE_DIR/$DOC_DIR_PO/en/LC_MESSAGES/api/ \ 67 | $SOURCE_DIR/$DOC_DIR_PO/en/LC_MESSAGES/apidoc/ \ 68 | $SOURCE_DIR/$DOC_DIR_PO/en/LC_MESSAGES/apidoc_legacy/ \ 69 | $SOURCE_DIR/$DOC_DIR_PO/en/LC_MESSAGES/stubs/ \ 70 | $SOURCE_DIR/$DOC_DIR_PO/en/LC_MESSAGES/theme/ 71 | 72 | # Copy the new rendered files and add them to the commit. 73 | echo "copy directory" 74 | cp -r $SOURCE_DIR/$DOC_DIR_PO/ docs/ 75 | cp $SOURCE_DIR/setup.py . 76 | cp $SOURCE_DIR/requirements-dev.txt . 77 | cp $SOURCE_DIR/constraints.txt . 78 | 79 | # git checkout translationDocs 80 | echo "add to po files to target dir" 81 | git add $DOC_DIR_PO 82 | git add setup.py 83 | git add requirements-dev.txt constraints.txt 84 | 85 | # Commit and push the changes. 86 | git commit -m "Automated documentation update to add .po files from meta-qiskit" -m "skip ci" -m "Commit: $GITHUB_SHA" -m "Github Actions Run: https://github.com/Qiskit/qiskit/runs/$GITHUB_RUN_NUMBER" 87 | echo "git push" 88 | git push --quiet origin $TARGET_BRANCH_PO 89 | echo "********** End of pushing po to working repo! *************" 90 | popd 91 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | on: 3 | push: 4 | branches: [ master ] 5 | pull_request: 6 | branches: [ master ] 7 | jobs: 8 | tests: 9 | name: tests-python${{ matrix.python-version }}-${{ matrix.os }} 10 | runs-on: ${{ matrix.os }} 11 | strategy: 12 | matrix: 13 | python-version: [3.8, 3.9, "3.10", "3.11"] 14 | os: ["ubuntu-latest"] 15 | steps: 16 | - uses: actions/checkout@v3 17 | - name: Set up Python ${{ matrix.python-version }} 18 | uses: actions/setup-python@v4 19 | with: 20 | python-version: ${{ matrix.python-version }} 21 | - name: Install Deps 22 | run: python -m pip install -U 'tox<4' setuptools virtualenv wheel pip 23 | - name: Install and Run Tests 24 | run: tox -e py 25 | lint: 26 | name: lint 27 | runs-on: ubuntu-latest 28 | steps: 29 | - uses: actions/checkout@v3 30 | - name: Set up Python 3.8 31 | uses: actions/setup-python@v4 32 | with: 33 | python-version: 3.8 34 | - name: Install Deps 35 | run: python -m pip install -U 'tox<4' 36 | - name: Run lint 37 | run: tox -elint 38 | docs: 39 | name: docs 40 | runs-on: ubuntu-latest 41 | steps: 42 | - uses: actions/checkout@v3 43 | with: 44 | fetch-depth: 0 45 | - name: Set up Python 3.8 46 | uses: actions/setup-python@v4 47 | with: 48 | python-version: 3.8 49 | - name: Install ubuntu Deps 50 | run: sudo apt-get install -y pandoc graphviz 51 | - name: Install python Deps 52 | run: | 53 | python -m pip install -U 'tox<4' 54 | python -m pip install -r requirements-dev.txt 55 | - name: Build Docs 56 | run: tox -edocs 57 | - name: Compress Artifacts 58 | run: | 59 | mkdir artifacts 60 | tar -zcvf html_docs.tar.gz docs/_build/html 61 | mv html_docs.tar.gz artifacts/. 62 | - uses: actions/upload-artifact@v3 63 | with: 64 | name: html_docs 65 | path: artifacts 66 | tutorials: 67 | name: tutorials 68 | runs-on: ubuntu-latest 69 | steps: 70 | - uses: actions/checkout@v3 71 | with: 72 | fetch-depth: 0 73 | - name: Set up Python 3.8 74 | uses: actions/setup-python@v4 75 | with: 76 | python-version: 3.8 77 | - name: Install python Deps 78 | run: python -m pip install -U 'tox<4' 79 | - name: Setup tutorials 80 | run: | 81 | set -e 82 | git clone https://github.com/Qiskit/qiskit-tutorials 83 | pip install -c constraints.txt -U jupyter sphinx nbsphinx networkx qiskit_sphinx_theme 'matplotlib>=3.3.0' qiskit-terra[visualization] cvxpy 'pyscf<1.7.4' scikit-learn qiskit-aer 84 | pip install -c constraints.txt -U . 85 | sudo apt-get install -y pandoc graphviz 86 | - name: Run tutorials 87 | run: | 88 | set -e 89 | cd qiskit-tutorials 90 | sphinx-build -b html . _build/html 91 | env: 92 | QISKIT_CELL_TIMEOUT: 300 93 | - name: Compress Artifacts 94 | run: | 95 | mkdir artifacts 96 | tar -zcvf tutorial_docs.tar.gz qiskit-tutorials/_build/html 97 | mv tutorial_docs.tar.gz artifacts/. 98 | - uses: actions/upload-artifact@v3 99 | with: 100 | name: tutorial_docs 101 | path: artifacts 102 | -------------------------------------------------------------------------------- /test/benchmarks/circuit_construction.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -* 2 | 3 | # This code is part of Qiskit. 4 | # 5 | # (C) Copyright IBM 2018, 2019. 6 | # 7 | # This code is licensed under the Apache License, Version 2.0. You may 8 | # obtain a copy of this license in the LICENSE.txt file in the root directory 9 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 10 | # 11 | # Any modifications or derivative works of this code must retain this 12 | # copyright notice, and modified files need to carry a notice indicating 13 | # that they have been altered from the originals. 14 | 15 | # pylint: disable=missing-docstring,invalid-name,no-member 16 | # pylint: disable=attribute-defined-outside-init 17 | 18 | import itertools 19 | 20 | from qiskit import QuantumRegister, QuantumCircuit 21 | from qiskit.circuit import Parameter 22 | 23 | 24 | def build_circuit(width, gates): 25 | qr = QuantumRegister(width) 26 | qc = QuantumCircuit(qr) 27 | 28 | while len(qc) < gates: 29 | for k in range(width): 30 | qc.h(qr[k]) 31 | for k in range(width-1): 32 | qc.cx(qr[k], qr[k+1]) 33 | 34 | return qc 35 | 36 | 37 | class CircuitConstructionBench: 38 | params = ([1, 2, 5, 8, 14, 20], [8, 128, 2048, 8192, 32768, 131072]) 39 | param_names = ['width', 'gates'] 40 | timeout = 600 41 | 42 | def setup(self, width, gates): 43 | self.empty_circuit = build_circuit(width, 0) 44 | self.sample_circuit = build_circuit(width, gates) 45 | 46 | def time_circuit_construction(self, width, gates): 47 | build_circuit(width, gates) 48 | 49 | def time_circuit_extend(self, _, __): 50 | self.empty_circuit.extend(self.sample_circuit) 51 | 52 | def time_circuit_copy(self, _, __): 53 | self.sample_circuit.copy() 54 | 55 | 56 | def build_parameterized_circuit(width, gates, param_count): 57 | params = [Parameter('param-%s' % x) for x in range(param_count)] 58 | param_iter = itertools.cycle(params) 59 | 60 | qr = QuantumRegister(width) 61 | qc = QuantumCircuit(qr) 62 | 63 | while len(qc) < gates: 64 | for k in range(width): 65 | param = next(param_iter) 66 | qc.u2(0, param, qr[k]) 67 | for k in range(width-1): 68 | param = next(param_iter) 69 | qc.crx(param, qr[k], qr[k+1]) 70 | 71 | return qc, params 72 | 73 | 74 | class ParameterizedCircuitConstructionBench: 75 | params = ([20], [8, 128, 2048, 8192, 32768, 131072], 76 | [8, 128, 2048, 8192, 32768, 131072]) 77 | param_names = ['width', 'gates', 'number of params'] 78 | timeout = 600 79 | 80 | def setup(self, _, gates, params): 81 | if params > gates: 82 | raise NotImplementedError 83 | 84 | def time_build_parameterized_circuit(self, width, gates, params): 85 | build_parameterized_circuit(width, gates, params) 86 | 87 | 88 | class ParameterizedCircuitBindBench: 89 | params = ([20], [8, 128, 2048, 8192, 32768, 131072], 90 | [8, 128, 2048, 8192, 32768, 131072]) 91 | param_names = ['width', 'gates', 'number of params'] 92 | timeout = 600 93 | 94 | def setup(self, width, gates, params): 95 | if params > gates: 96 | raise NotImplementedError 97 | self.circuit, self.params = build_parameterized_circuit(width, 98 | gates, 99 | params) 100 | 101 | def time_bind_params(self, _, __, ___): 102 | self.circuit.bind_parameters({x: 3.14 for x in self.params}) 103 | -------------------------------------------------------------------------------- /docs/faq.rst: -------------------------------------------------------------------------------- 1 | .. _faq: 2 | 3 | ========================== 4 | Frequently Asked Questions 5 | ========================== 6 | 7 | **Q: How should I cite Qiskit in my research?** 8 | 9 | **A:** Please cite Qiskit by using the included `BibTeX file 10 | `__. 11 | 12 | | 13 | 14 | **Q: Why do I receive the error message** ``AttributeError: QuantumCircuit object has no attribute save_state`` 15 | **when using ``save_*``method on a circuit?** 16 | 17 | **A:** The ``save_*`` instructions are part of Qiskit Aer project, 18 | a high performance simulator for quantum circuits. These instructions do not 19 | exist outside of Qiskit Aer and are added dynamically to the 20 | :class:`~.QuantumCircuit` class by Qiskit Aer on import. If you would like to 21 | use these instructions you must first ensure that you have imported 22 | ``qiskit_aer`` in your program before trying to call these methods. You 23 | can refer to :mod:`qiskit_aer.library` for the details of these custom 24 | instructions included with Qiskit Aer. 25 | 26 | **Q: Why do my results from real devices differ from my results from the simulator?** 27 | 28 | **A:** The simulator runs jobs as though is was in an ideal environment; one 29 | without noise or decoherence. However, when jobs are run on the real devices 30 | there is noise from the environment and decoherence, which causes the qubits 31 | to behave differently than what is intended. 32 | 33 | | 34 | 35 | **Q: Why do I receive the error message,** ``No Module 'qiskit'`` **when using Jupyter Notebook?** 36 | 37 | **A:** If you used ``pip install qiskit`` and set up your virtual environment in 38 | Anaconda, then you may experience this error when you run a tutorial 39 | in Jupyter Notebook. If you have not installed Qiskit or set up your 40 | virtual environment, you can follow the :ref:`installation` steps. 41 | 42 | The error is caused when trying to import the Qiskit package in an 43 | environment where Qiskit is not installed. If you launched Jupyter Notebook 44 | from the Anaconda-Navigator, it is possible that Jupyter Notebook is running 45 | in the base (root) environment, instead of in your virtual 46 | environment. Choose a virtual environment in the Anaconda-Navigator from the 47 | **Applications on** dropdown menu. In this menu, you can see 48 | all of the virtual environments within Anaconda, and you can 49 | select the environment where you have Qiskit installed to launch Jupyter 50 | Notebook. 51 | 52 | | 53 | 54 | **Q: Why am I getting a compilation error while installing ``qiskit``?** 55 | 56 | **A:** Qiskit depends on a number of other open source Python packages, which 57 | are automatically installed when doing ``pip install qiskit``. Depending on 58 | your system's platform and Python version, it is possible that a particular 59 | package does not provide pre-built binaries for your system. You can refer 60 | to :ref:`platform_support` for a list of platforms supported by Qiskit, some 61 | of which may need an extra compiler. In cases where there are 62 | no precompiled binaries available ``pip`` will attempt to compile the package 63 | from source, which in turn might require some extra dependencies that need to 64 | be installed manually. 65 | 66 | If the output of ``pip install qiskit`` contains similar lines to: 67 | 68 | .. code:: sh 69 | 70 | Failed building wheel for SOME_PACKAGE 71 | ... 72 | build/temp.linux-x86_64-3.5/_openssl.c:498:30: fatal error 73 | compilation terminated. 74 | error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 75 | 76 | please check the documentation of the package that failed to install (in the 77 | example code, ``SOME_PACKAGE``) for information on how to install the libraries 78 | needed for compiling from source. 79 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # This code is part of Qiskit. 4 | # 5 | # (C) Copyright IBM 2018. 6 | # 7 | # This code is licensed under the Apache License, Version 2.0. You may 8 | # obtain a copy of this license in the LICENSE.txt file in the root directory 9 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 10 | # 11 | # Any modifications or derivative works of this code must retain this 12 | # copyright notice, and modified files need to carry a notice indicating 13 | # that they have been altered from the originals. 14 | 15 | import os 16 | 17 | from setuptools import setup 18 | 19 | README_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)), "README.md") 20 | with open(README_PATH) as readme_file: 21 | README = readme_file.read() 22 | 23 | # NOTE: The lists below require each requirement on a separate line, 24 | # putting multiple requirements on the same line will prevent qiskit-bot 25 | # from correctly updating the versions for the qiskit packages. 26 | requirements = [ 27 | "qiskit-terra==0.25.0", 28 | ] 29 | 30 | 31 | optimization_extra = [ 32 | "qiskit-optimization>=0.4.0", 33 | ] 34 | 35 | 36 | finance_extra = [ 37 | "qiskit-finance>=0.3.3", 38 | ] 39 | 40 | 41 | machine_learning_extra = [ 42 | "qiskit-machine-learning>=0.4.0", 43 | ] 44 | 45 | 46 | nature_extra = [ 47 | "qiskit-nature>=0.4.1", 48 | ] 49 | 50 | experiments_extra = [ 51 | "qiskit-experiments>=0.2.0", 52 | ] 53 | 54 | visualization_extra = [ 55 | "matplotlib>=2.1", 56 | "ipywidgets>=7.3.0", 57 | "pydot", 58 | "pillow>=4.2.1", 59 | "pylatexenc>=1.4", 60 | "seaborn>=0.9.0", 61 | "pygments>=2.4", 62 | ] 63 | 64 | 65 | setup( 66 | name="qiskit", 67 | version="0.44.0", 68 | description="Software for developing quantum computing programs", 69 | long_description=README, 70 | long_description_content_type="text/markdown", 71 | url="https://qiskit.org/", 72 | author="Qiskit Development Team", 73 | author_email="hello@qiskit.org", 74 | license="Apache 2.0", 75 | py_modules=[], 76 | packages=[], 77 | classifiers=[ 78 | "Environment :: Console", 79 | "License :: OSI Approved :: Apache Software License", 80 | "Intended Audience :: Developers", 81 | "Intended Audience :: Science/Research", 82 | "Operating System :: Microsoft :: Windows", 83 | "Operating System :: MacOS", 84 | "Operating System :: POSIX :: Linux", 85 | "Programming Language :: Python :: 3.7", 86 | "Programming Language :: Python :: 3.8", 87 | "Programming Language :: Python :: 3.9", 88 | "Programming Language :: Python :: 3.10", 89 | "Topic :: Scientific/Engineering", 90 | ], 91 | keywords="qiskit sdk quantum", 92 | install_requires=requirements, 93 | project_urls={ 94 | "Bug Tracker": "https://github.com/Qiskit/qiskit/issues", 95 | "Documentation": "https://qiskit.org/documentation/", 96 | "Source Code": "https://github.com/Qiskit/qiskit", 97 | }, 98 | include_package_data=True, 99 | python_requires=">=3.7", 100 | extras_require={ 101 | "visualization": visualization_extra, 102 | "all": optimization_extra 103 | + finance_extra 104 | + machine_learning_extra 105 | + nature_extra 106 | + experiments_extra 107 | + visualization_extra, 108 | "experiments": experiments_extra, 109 | "optimization": optimization_extra, 110 | "finance": finance_extra, 111 | "machine-learning": machine_learning_extra, 112 | "nature": nature_extra, 113 | }, 114 | ) 115 | -------------------------------------------------------------------------------- /test/benchmarks/transpiler_benchmarks.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -* 2 | 3 | # This code is part of Qiskit. 4 | # 5 | # (C) Copyright IBM 2018. 6 | # 7 | # This code is licensed under the Apache License, Version 2.0. You may 8 | # obtain a copy of this license in the LICENSE.txt file in the root directory 9 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 10 | # 11 | # Any modifications or derivative works of this code must retain this 12 | # copyright notice, and modified files need to carry a notice indicating 13 | # that they have been altered from the originals. 14 | 15 | # pylint: disable=missing-docstring,invalid-name,no-member 16 | # pylint: disable=attribute-defined-outside-init 17 | 18 | import os 19 | 20 | import qiskit 21 | 22 | 23 | class TranspilerBenchSuite: 24 | 25 | def _build_cx_circuit(self): 26 | cx_register = qiskit.QuantumRegister(2) 27 | cx_circuit = qiskit.QuantumCircuit(cx_register) 28 | cx_circuit.h(cx_register[0]) 29 | cx_circuit.h(cx_register[0]) 30 | cx_circuit.cx(cx_register[0], cx_register[1]) 31 | cx_circuit.cx(cx_register[0], cx_register[1]) 32 | cx_circuit.cx(cx_register[0], cx_register[1]) 33 | cx_circuit.cx(cx_register[0], cx_register[1]) 34 | return cx_circuit 35 | 36 | def _build_single_gate_circuit(self): 37 | single_register = qiskit.QuantumRegister(1) 38 | single_gate_circuit = qiskit.QuantumCircuit(single_register) 39 | single_gate_circuit.h(single_register[0]) 40 | return single_gate_circuit 41 | 42 | def setup(self): 43 | self.single_gate_circuit = self._build_single_gate_circuit() 44 | self.cx_circuit = self._build_cx_circuit() 45 | self.qasm_path = os.path.abspath( 46 | os.path.join(os.path.dirname(__file__), 'qasm')) 47 | large_qasm_path = os.path.join(self.qasm_path, 'test_eoh_qasm.qasm') 48 | self.large_qasm = qiskit.QuantumCircuit.from_qasm_file(large_qasm_path) 49 | self.coupling_map = [ 50 | [0, 1], [1, 0], [1, 2], [1, 4], [2, 1], [2, 3], [3, 2], [3, 5], 51 | [4, 1], [4, 7], [5, 3], [5, 8], [6, 7], [7, 4], [7, 6], [7, 10], 52 | [8, 5], [8, 9], [8, 11], [9, 8], [10, 7], [10, 12], [11, 8], 53 | [11, 14], [12, 10], [12, 13], [12, 15], [13, 12], [13, 14], 54 | [14, 11], [14, 13], [14, 16], [15, 12], [15, 18], [16, 14], 55 | [16, 19], [17, 18], [18, 15], [18, 17], [18, 21], [19, 16], 56 | [19, 20], [19, 22], [20, 19], [21, 18], [21, 23], [22, 19], 57 | [22, 25], [23, 21], [23, 24], [24, 23], [24, 25], [25, 22], 58 | [25, 24], [25, 26], [26, 25]] 59 | self.basis = ['id', 'rz', 'sx', 'x', 'cx', 'reset'] 60 | 61 | def time_single_gate_compile(self): 62 | circ = qiskit.compiler.transpile(self.single_gate_circuit, 63 | coupling_map=self.coupling_map, 64 | basis_gates=self.basis, 65 | seed_transpiler=20220125) 66 | qiskit.compiler.assemble(circ) 67 | 68 | def time_cx_compile(self): 69 | circ = qiskit.compiler.transpile(self.cx_circuit, 70 | coupling_map=self.coupling_map, 71 | basis_gates=self.basis, 72 | seed_transpiler=20220125) 73 | qiskit.compiler.assemble(circ) 74 | 75 | def time_compile_from_large_qasm(self): 76 | circ = qiskit.compiler.transpile(self.large_qasm, 77 | coupling_map=self.coupling_map, 78 | basis_gates=self.basis, 79 | seed_transpiler=20220125) 80 | qiskit.compiler.assemble(circ) 81 | -------------------------------------------------------------------------------- /test/benchmarks/scheduling_passes.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # This code is part of Qiskit. 4 | # 5 | # (C) Copyright IBM 2021. 6 | # 7 | # This code is licensed under the Apache License, Version 2.0. You may 8 | # obtain a copy of this license in the LICENSE.txt file in the root directory 9 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 10 | # 11 | # Any modifications or derivative works of this code must retain this 12 | # copyright notice, and modified files need to carry a notice indicating 13 | # that they have been altered from the originals. 14 | 15 | # pylint: disable=invalid-name,missing-docstring 16 | # pylint: disable=attribute-defined-outside-init 17 | 18 | from qiskit import transpile 19 | from qiskit.circuit.library.standard_gates import XGate 20 | from qiskit.transpiler import CouplingMap 21 | from qiskit.transpiler import InstructionDurations 22 | from qiskit.transpiler.passes import ( 23 | TimeUnitConversion, 24 | ASAPSchedule, 25 | ALAPSchedule, 26 | DynamicalDecoupling, 27 | ) 28 | from qiskit.converters import circuit_to_dag 29 | 30 | from .utils import random_circuit 31 | 32 | 33 | class SchedulingPassBenchmarks: 34 | 35 | params = ([5, 10, 20], 36 | [500, 1000]) 37 | param_names = ['n_qubits', 'depth'] 38 | timeout = 300 39 | 40 | def setup(self, n_qubits, depth): 41 | seed = 42 42 | self.circuit = random_circuit(n_qubits, depth, measure=True, 43 | conditional=True, reset=True, seed=seed, 44 | max_operands=2) 45 | self.basis_gates = ['rz', 'sx', 'x', 'cx', 'id', 'reset'] 46 | self.cmap = [[0, 1], [1, 0], [1, 2], [1, 6], [2, 1], [2, 3], [3, 2], 47 | [3, 4], [3, 8], [4, 3], [5, 6], [5, 10], [6, 1], [6, 5], 48 | [6, 7], [7, 6], [7, 8], [7, 12], [8, 3], [8, 7], [8, 9], 49 | [9, 8], [9, 14], [10, 5], [10, 11], [11, 10], [11, 12], 50 | [11, 16], [12, 7], [12, 11], [12, 13], [13, 12], [13, 14], 51 | [13, 18], [14, 9], [14, 13], [15, 16], [16, 11], [16, 15], 52 | [16, 17], [17, 16], [17, 18], [18, 13], [18, 17], 53 | [18, 19], [19, 18]] 54 | self.coupling_map = CouplingMap(self.cmap) 55 | self.transpiled_circuit = transpile(self.circuit, 56 | basis_gates=self.basis_gates, 57 | coupling_map=self.coupling_map, 58 | optimization_level=1) 59 | self.dag = circuit_to_dag(self.transpiled_circuit) 60 | self.durations = InstructionDurations([ 61 | ("rz", None, 0), 62 | ("id", None, 160), 63 | ("sx", None, 160), 64 | ("x", None, 160), 65 | ("cx", None, 800), 66 | ("measure", None, 3200), 67 | ("reset", None, 3600), 68 | ], dt=1e-9) 69 | self.timed_dag = TimeUnitConversion(self.durations).run(self.dag) 70 | _pass = ALAPSchedule(self.durations) 71 | _pass.property_set['time_unit'] = "dt" 72 | self.scheduled_dag = _pass.run(self.timed_dag) 73 | 74 | def time_time_unit_conversion_pass(self, _, __): 75 | TimeUnitConversion(self.durations).run(self.dag) 76 | 77 | def time_alap_schedule_pass(self, _, __): 78 | _pass = ALAPSchedule(self.durations) 79 | _pass.property_set['time_unit'] = "dt" 80 | _pass.run(self.timed_dag) 81 | 82 | def time_asap_schedule_pass(self, _, __): 83 | _pass = ASAPSchedule(self.durations) 84 | _pass.property_set['time_unit'] = "dt" 85 | _pass.run(self.timed_dag) 86 | 87 | def time_dynamical_decoupling_pass(self, _, __): 88 | DynamicalDecoupling( 89 | self.durations, 90 | dd_sequence=[XGate(), XGate()] 91 | ).run(self.scheduled_dag) 92 | -------------------------------------------------------------------------------- /test/benchmarks/randomized_benchmarking.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # This code is part of Qiskit. 4 | # 5 | # (C) Copyright IBM 2019. 6 | # 7 | # This code is licensed under the Apache License, Version 2.0. You may 8 | # obtain a copy of this license in the LICENSE.txt file in the root directory 9 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 10 | # 11 | # Any modifications or derivative works of this code must retain this 12 | # copyright notice, and modified files need to carry a notice indicating 13 | # that they have been altered from the originals. 14 | 15 | # pylint: disable=no-member,invalid-name,missing-docstring,no-name-in-module 16 | # pylint: disable=attribute-defined-outside-init,unsubscriptable-object 17 | # pylint: disable=import-error 18 | 19 | import os 20 | import numpy as np 21 | from qiskit_experiments.library import StandardRB 22 | 23 | try: 24 | from qiskit.compiler import transpile 25 | TRANSPILER_SEED_KEYWORD = 'seed_transpiler' 26 | except ImportError: 27 | from qiskit.transpiler import transpile 28 | TRANSPILER_SEED_KEYWORD = 'seed_mapper' 29 | 30 | 31 | def build_rb_circuit(qubits, length_vector, num_samples=1, seed=None): 32 | """ 33 | Randomized Benchmarking sequences. 34 | """ 35 | if not seed: 36 | np.random.seed(10) 37 | else: 38 | np.random.seed(seed) 39 | 40 | # Generate the sequences 41 | try: 42 | rb_exp = StandardRB( 43 | qubits, 44 | lengths=length_vector, 45 | num_samples=num_samples, 46 | seed=seed, 47 | ) 48 | except OSError: 49 | skip_msg = ('Skipping tests because ' 50 | 'tables are missing') 51 | raise NotImplementedError( # pylint: disable=raise-missing-from 52 | skip_msg 53 | ) 54 | return rb_exp.circuits() 55 | 56 | 57 | class RandomizedBenchmarkingBenchmark: 58 | # parameters for RB (1&2 qubits): 59 | params = ([ 60 | [0], # Single qubit RB 61 | [0, 1], # Two qubit RB 62 | ],) 63 | param_names = ['qubits'] 64 | version = '0.3.0' 65 | timeout = 600 66 | 67 | def setup(self, qubits): 68 | length_vector = np.arange(1, 200, 4) 69 | num_samples = 1 70 | self.seed = 10 71 | self.circuits = build_rb_circuit(qubits=qubits, 72 | length_vector=length_vector, 73 | num_samples=num_samples, 74 | seed=self.seed) 75 | 76 | def teardown(self, _): 77 | os.environ['QISKIT_IN_PARALLEL'] = 'FALSE' 78 | 79 | def time_ibmq_backend_transpile(self, __): 80 | # Run with ibmq_16_melbourne configuration 81 | coupling_map = [[1, 0], [1, 2], [2, 3], [4, 3], [4, 10], [5, 4], 82 | [5, 6], [5, 9], [6, 8], [7, 8], [9, 8], [9, 10], 83 | [11, 3], [11, 10], [11, 12], [12, 2], [13, 1], 84 | [13, 12]] 85 | 86 | transpile(self.circuits, 87 | basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], 88 | coupling_map=coupling_map, optimization_level=0, 89 | **{TRANSPILER_SEED_KEYWORD: self.seed}) 90 | 91 | def time_ibmq_backend_transpile_single_thread(self, __): 92 | os.environ['QISKIT_IN_PARALLEL'] = 'TRUE' 93 | 94 | # Run with ibmq_16_melbourne configuration 95 | coupling_map = [[1, 0], [1, 2], [2, 3], [4, 3], [4, 10], [5, 4], 96 | [5, 6], [5, 9], [6, 8], [7, 8], [9, 8], [9, 10], 97 | [11, 3], [11, 10], [11, 12], [12, 2], [13, 1], 98 | [13, 12]] 99 | 100 | transpile(self.circuits, 101 | basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], 102 | coupling_map=coupling_map, optimization_level=0, 103 | **{TRANSPILER_SEED_KEYWORD: self.seed}) 104 | -------------------------------------------------------------------------------- /test/benchmarks/random_circuit_hex.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # This code is part of Qiskit. 4 | # 5 | # (C) Copyright IBM 2018, 2019. 6 | # 7 | # This code is licensed under the Apache License, Version 2.0. You may 8 | # obtain a copy of this license in the LICENSE.txt file in the root directory 9 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 10 | # 11 | # Any modifications or derivative works of this code must retain this 12 | # copyright notice, and modified files need to carry a notice indicating 13 | # that they have been altered from the originals. 14 | 15 | # pylint: disable=missing-docstring,invalid-name,no-member 16 | # pylint: disable=attribute-defined-outside-init 17 | 18 | import copy 19 | 20 | from qiskit.quantum_info.synthesis import OneQubitEulerDecomposer 21 | from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister 22 | 23 | try: 24 | from qiskit.compiler import transpile 25 | TRANSPILER_SEED_KEYWORD = 'seed_transpiler' 26 | except ImportError: 27 | from qiskit.transpiler import transpile 28 | TRANSPILER_SEED_KEYWORD = 'seed_mapper' 29 | try: 30 | from qiskit.quantum_info.random import random_unitary 31 | HAS_RANDOM_UNITARY = True 32 | except ImportError: 33 | from qiskit.tools.qi.qi import random_unitary_matrix 34 | HAS_RANDOM_UNITARY = False 35 | 36 | 37 | # Make a random circuit on a ring 38 | def make_circuit_ring(nq, depth, seed): 39 | assert int(nq / 2) == nq / 2 # for now size of ring must be even 40 | # Create a Quantum Register 41 | q = QuantumRegister(nq) 42 | # Create a Classical Register 43 | c = ClassicalRegister(nq) 44 | # Create a Quantum Circuit 45 | qc = QuantumCircuit(q, c) 46 | offset = 1 47 | decomposer = OneQubitEulerDecomposer() 48 | # initial round of random single-qubit unitaries 49 | for i in range(nq): 50 | qc.h(q[i]) 51 | for j in range(depth): 52 | for i in range(int(nq / 2)): # round of CNOTS 53 | k = i * 2 + offset + j % 2 # j%2 makes alternating rounds overlap 54 | qc.cx(q[k % nq], q[(k + 1) % nq]) 55 | for i in range(nq): # round of single-qubit unitaries 56 | if HAS_RANDOM_UNITARY: 57 | u = random_unitary(2, seed).data 58 | else: 59 | u = random_unitary_matrix(2) # pylint: disable=used-before-assignment # noqa 60 | 61 | angles = decomposer.angles(u) 62 | qc.u3(angles[0], angles[1], angles[2], q[i]) 63 | 64 | # insert the final measurements 65 | qcm = copy.deepcopy(qc) 66 | for i in range(nq): 67 | qcm.measure(q[i], c[i]) 68 | return [qc, qcm, nq] 69 | 70 | 71 | class BenchRandomCircuitHex: 72 | params = [2 * i for i in range(2, 8)] 73 | param_names = ['n_qubits'] 74 | version = 3 75 | 76 | def setup(self, n): 77 | depth = 2 * n 78 | self.seed = 0 79 | self.circuit = make_circuit_ring(n, depth, self.seed)[0] 80 | 81 | def time_ibmq_backend_transpile(self, _): 82 | # Run with ibmq_16_melbourne configuration 83 | coupling_map = [[1, 0], [1, 2], [2, 3], [4, 3], [4, 10], [5, 4], 84 | [5, 6], [5, 9], [6, 8], [7, 8], [9, 8], [9, 10], 85 | [11, 3], [11, 10], [11, 12], [12, 2], [13, 1], 86 | [13, 12]] 87 | transpile(self.circuit, 88 | basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], 89 | coupling_map=coupling_map, 90 | **{TRANSPILER_SEED_KEYWORD: self.seed}) 91 | 92 | def track_depth_ibmq_backend_transpile(self, _): 93 | # Run with ibmq_16_melbourne configuration 94 | coupling_map = [[1, 0], [1, 2], [2, 3], [4, 3], [4, 10], [5, 4], 95 | [5, 6], [5, 9], [6, 8], [7, 8], [9, 8], [9, 10], 96 | [11, 3], [11, 10], [11, 12], [12, 2], [13, 1], 97 | [13, 12]] 98 | return transpile(self.circuit, 99 | basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], 100 | coupling_map=coupling_map, 101 | **{TRANSPILER_SEED_KEYWORD: self.seed}).depth() 102 | -------------------------------------------------------------------------------- /docs/custom_extensions.py: -------------------------------------------------------------------------------- 1 | # This code is part of Qiskit. 2 | # 3 | # (C) Copyright IBM 2023. 4 | # 5 | # This code is licensed under the Apache License, Version 2.0. You may 6 | # obtain a copy of this license in the LICENSE.txt file in the root directory 7 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # Any modifications or derivative works of this code must retain this 10 | # copyright notice, and modified files need to carry a notice indicating 11 | # that they have been altered from the originals. 12 | 13 | import re 14 | import shutil 15 | import subprocess 16 | import tempfile 17 | import warnings 18 | from pathlib import Path 19 | 20 | from sphinx.util import logging 21 | 22 | logger = logging.getLogger(__name__) 23 | 24 | TERRA_FILES = [] 25 | TERRA_DIRS = [ 26 | "apidoc", 27 | "migration_guides", 28 | "_templates", 29 | "source_images", 30 | ] 31 | 32 | 33 | def _get_current_terra_version(app): 34 | setup_py = Path(app.srcdir, "../", "setup.py").read_text() 35 | version_regex = re.compile("qiskit-terra" + '[=|>]=(.*)"') 36 | match = version_regex.search(setup_py) 37 | return match[1] 38 | 39 | 40 | def load_terra_docs(app): 41 | """Git clones Qiskit Terra docs.""" 42 | if all(Path(app.srcdir, fp).exists() for fp in [*TERRA_DIRS, *TERRA_FILES]): 43 | warnings.warn( 44 | "Terra docs already exist. Skipping Git clone. These docs may be out of date! " 45 | "Run `tox -e docs-clean` to remove these docs." 46 | ) 47 | return 48 | 49 | version = _get_current_terra_version(app) 50 | with tempfile.TemporaryDirectory() as temp_dir: 51 | subprocess.run( 52 | ["git", "clone", "https://github.com/Qiskit/qiskit-terra", temp_dir], 53 | capture_output=True, 54 | ) 55 | subprocess.run(["git", "checkout", version], cwd=temp_dir, capture_output=True) 56 | for d in TERRA_DIRS: 57 | src = Path(temp_dir, "docs", "apidocs" if d == "apidoc" else d) 58 | shutil.copytree(src, Path(app.srcdir, d)) 59 | for f in TERRA_FILES: 60 | src = Path(temp_dir, "docs", f) 61 | shutil.copy(src, Path(app.srcdir, f)) 62 | 63 | 64 | def load_tutorials(app): 65 | """Git clones the tutorials repo so that we can generate their docs.""" 66 | if Path(app.srcdir, "tutorials").exists(): 67 | warnings.warn( 68 | "Tutorials already exist. Skipping Git clone. These docs may be out of date! " 69 | "Run `tox -e docs-clean` to remove these docs." 70 | ) 71 | return 72 | with tempfile.TemporaryDirectory() as temp_dir: 73 | subprocess.run( 74 | ["git", "clone", "https://github.com/Qiskit/qiskit-tutorials", temp_dir], 75 | capture_output=True, 76 | ) 77 | for d in ["algorithms", "circuits", "circuits_advanced", "operators"]: 78 | shutil.copytree(Path(temp_dir, "tutorials", d), Path(app.srcdir, "tutorials", d)) 79 | 80 | 81 | def add_versions_to_config(_app, config): 82 | """Add a list of old documentation versions that should have links generated to them into the 83 | context, so the theme can use them to generate a sidebar.""" 84 | # First 0.x version where Qiskit/Terra and the metapackage aligned on number. 85 | first_unified_zero_minor = 45 86 | 87 | # Start with the hardcoded versions of the documentation that were managed while the metapackage 88 | # still existed, so are based on tags that don't exist in the Qiskit package repo. 89 | versions = ["0.19"] + [f"0.{x}" for x in range(24, first_unified_zero_minor)] 90 | 91 | proc = subprocess.run(["git", "describe", "--abbrev=0"], capture_output=True, check=True) 92 | current_version = proc.stdout.decode("utf8") 93 | current_version_info = current_version.split(".") 94 | if current_version_info[0] != "0": 95 | raise Exception("TODO: handle major versions") 96 | versions.extend( 97 | f"0.{x}" % x for x in range(first_unified_zero_minor, int(current_version_info[1]) + 1) 98 | ) 99 | config.html_context["version_list"] = versions 100 | 101 | 102 | def clean_docs(app, exc): 103 | """Deletes the Git cloned docs.""" 104 | for d in [*TERRA_DIRS, "tutorials"]: 105 | shutil.rmtree(Path(app.srcdir, d)) 106 | for f in TERRA_FILES: 107 | Path(app.srcdir, f).unlink() 108 | -------------------------------------------------------------------------------- /test/benchmarks/qft.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -* 2 | 3 | # This code is part of Qiskit. 4 | # 5 | # (C) Copyright IBM 2018, 2019. 6 | # 7 | # This code is licensed under the Apache License, Version 2.0. You may 8 | # obtain a copy of this license in the LICENSE.txt file in the root directory 9 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 10 | # 11 | # Any modifications or derivative works of this code must retain this 12 | # copyright notice, and modified files need to carry a notice indicating 13 | # that they have been altered from the originals. 14 | 15 | # pylint: disable=missing-docstring,invalid-name,no-member 16 | # pylint: disable=attribute-defined-outside-init 17 | 18 | import itertools 19 | import math 20 | 21 | from qiskit import QuantumRegister, QuantumCircuit 22 | from qiskit.converters import circuit_to_dag 23 | from qiskit.transpiler import CouplingMap 24 | from qiskit.transpiler.passes import SabreSwap 25 | try: 26 | from qiskit.compiler import transpile 27 | except ImportError: 28 | from qiskit.transpiler import transpile 29 | 30 | 31 | def build_model_circuit(qreg, circuit=None): 32 | """Create quantum fourier transform circuit on quantum register qreg.""" 33 | if circuit is None: 34 | circuit = QuantumCircuit(qreg, name="qft") 35 | 36 | n = len(qreg) 37 | 38 | for i in range(n): 39 | for j in range(i): 40 | # Using negative exponents so we safely underflow to 0 rather than 41 | # raise `OverflowError`. 42 | circuit.cp(math.pi * (2.0 ** (j-i)), qreg[i], qreg[j]) 43 | circuit.h(qreg[i]) 44 | 45 | return circuit 46 | 47 | 48 | class QftTranspileBench: 49 | params = [1, 2, 3, 5, 8, 13, 14] 50 | 51 | def setup(self, n): 52 | qr = QuantumRegister(n) 53 | self.circuit = build_model_circuit(qr) 54 | 55 | def time_ibmq_backend_transpile(self, _): 56 | # Run with ibmq_16_melbourne configuration 57 | coupling_map = [[1, 0], [1, 2], [2, 3], [4, 3], [4, 10], [5, 4], 58 | [5, 6], [5, 9], [6, 8], [7, 8], [9, 8], [9, 10], 59 | [11, 3], [11, 10], [11, 12], [12, 2], [13, 1], 60 | [13, 12]] 61 | transpile(self.circuit, 62 | basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], 63 | coupling_map=coupling_map, 64 | seed_transpiler=20220125) 65 | 66 | 67 | class LargeQFTMappingTimeBench: 68 | timeout = 600.0 # seconds 69 | 70 | heavy_hex_size = {115: 7, 409: 13, 1081: 21} 71 | params = ([115, 409, 1081], ["lookahead", "decay"]) 72 | param_names = ["n_qubits", "heuristic"] 73 | 74 | def setup(self, n_qubits, _heuristic): 75 | qr = QuantumRegister(n_qubits, name="q") 76 | self.dag = circuit_to_dag(build_model_circuit(qr)) 77 | self.coupling = CouplingMap.from_heavy_hex( 78 | self.heavy_hex_size[n_qubits] 79 | ) 80 | 81 | def time_sabre_swap(self, _n_qubits, heuristic): 82 | pass_ = SabreSwap(self.coupling, heuristic, seed=2022_10_27, trials=1) 83 | pass_.run(self.dag) 84 | 85 | 86 | class LargeQFTMappingTrackBench: 87 | timeout = 600.0 # seconds, needs to account for the _entire_ setup. 88 | 89 | heavy_hex_size = {115: 7, 409: 13, 1081: 21} 90 | params = ([115, 409, 1081], ["lookahead", "decay"]) 91 | param_names = ["n_qubits", "heuristic"] 92 | 93 | # The benchmarks take a significant amount of time to run, and we don't 94 | # want to unnecessarily run things twice to get the two pieces of tracking 95 | # information we're interested in. We cheat by using the setup cache to do 96 | # all the calculation work only once, and then each tracker just quickly 97 | # pulls the result from the cache to return, saving the duplication. 98 | 99 | def setup_cache(self): 100 | def setup(n_qubits, heuristic): 101 | qr = QuantumRegister(n_qubits, name="q") 102 | dag = circuit_to_dag(build_model_circuit(qr)) 103 | coupling = CouplingMap.from_heavy_hex( 104 | self.heavy_hex_size[n_qubits] 105 | ) 106 | pass_ = SabreSwap(coupling, heuristic, seed=2022_10_27, trials=1) 107 | return pass_.run(dag) 108 | 109 | state = {} 110 | for params in itertools.product(*self.params): 111 | dag = setup(*params) 112 | state[params] = {"depth": dag.depth(), "size": dag.size()} 113 | return state 114 | 115 | def track_depth_sabre_swap(self, state, *params): 116 | return state[params]["depth"] 117 | 118 | def track_size_sabre_swap(self, state, *params): 119 | return state[params]["size"] 120 | -------------------------------------------------------------------------------- /test/benchmarks/transpiler_qualitative.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # This code is part of Qiskit. 4 | # 5 | # (C) Copyright IBM 2020. 6 | # 7 | # This code is licensed under the Apache License, Version 2.0. You may 8 | # obtain a copy of this license in the LICENSE.txt file in the root directory 9 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 10 | # 11 | # Any modifications or derivative works of this code must retain this 12 | # copyright notice, and modified files need to carry a notice indicating 13 | # that they have been altered from the originals. 14 | 15 | # pylint: disable=no-member,invalid-name,missing-docstring,no-name-in-module 16 | # pylint: disable=attribute-defined-outside-init,unsubscriptable-object 17 | 18 | import os 19 | 20 | from qiskit import QuantumCircuit 21 | from qiskit.compiler import transpile 22 | from qiskit.test.mock import FakeToronto 23 | 24 | 25 | class TranspilerQualitativeBench: 26 | params = ([0, 1, 2, 3], 27 | ["stochastic", "sabre"], 28 | ["dense", "noise_adaptive", "sabre"]) 29 | param_names = ["optimization level", "routing method", "layout method"] 30 | timeout = 600 31 | 32 | # pylint: disable=unused-argument 33 | def setup(self, optimization_level, routing_method, layout_method): 34 | self.backend = FakeToronto() 35 | self.qasm_path = os.path.abspath( 36 | os.path.join(os.path.dirname(__file__), "qasm")) 37 | 38 | self.depth_4gt10_v1_81 = QuantumCircuit.from_qasm_file( 39 | os.path.join(self.qasm_path, "depth_4gt10-v1_81.qasm")) 40 | self.depth_4mod5_v0_19 = QuantumCircuit.from_qasm_file( 41 | os.path.join(self.qasm_path, "depth_4mod5-v0_19.qasm")) 42 | self.depth_mod8_10_178 = QuantumCircuit.from_qasm_file( 43 | os.path.join(self.qasm_path, "depth_mod8-10_178.qasm")) 44 | 45 | self.time_cnt3_5_179 = QuantumCircuit.from_qasm_file( 46 | os.path.join(self.qasm_path, "time_cnt3-5_179.qasm")) 47 | self.time_cnt3_5_180 = QuantumCircuit.from_qasm_file( 48 | os.path.join(self.qasm_path, "time_cnt3-5_180.qasm")) 49 | self.time_qft_16 = QuantumCircuit.from_qasm_file( 50 | os.path.join(self.qasm_path, "time_qft_16.qasm")) 51 | 52 | def track_depth_transpile_4gt10_v1_81(self, optimization_level, 53 | routing_method, layout_method): 54 | return transpile(self.depth_4gt10_v1_81, self.backend, 55 | routing_method=routing_method, 56 | layout_method=layout_method, 57 | optimization_level=optimization_level, 58 | seed_transpiler=0).depth() 59 | 60 | def track_depth_transpile_4mod5_v0_19(self, optimization_level, 61 | routing_method, layout_method): 62 | return transpile(self.depth_4mod5_v0_19, self.backend, 63 | routing_method=routing_method, 64 | layout_method=layout_method, 65 | optimization_level=optimization_level, 66 | seed_transpiler=0).depth() 67 | 68 | def track_depth_transpile_mod8_10_178(self, optimization_level, 69 | routing_method, layout_method): 70 | return transpile(self.depth_mod8_10_178, self.backend, 71 | routing_method=routing_method, 72 | layout_method=layout_method, 73 | optimization_level=optimization_level, 74 | seed_transpiler=0).depth() 75 | 76 | def time_transpile_time_cnt3_5_179(self, optimization_level, 77 | routing_method, layout_method): 78 | transpile(self.time_cnt3_5_179, self.backend, 79 | routing_method=routing_method, 80 | layout_method=layout_method, 81 | optimization_level=optimization_level, 82 | seed_transpiler=0) 83 | 84 | def time_transpile_time_cnt3_5_180(self, optimization_level, 85 | routing_method, layout_method): 86 | transpile(self.time_cnt3_5_180, self.backend, 87 | routing_method=routing_method, 88 | layout_method=layout_method, 89 | optimization_level=optimization_level, 90 | seed_transpiler=0) 91 | 92 | def time_transpile_time_qft_16(self, optimization_level, 93 | routing_method, layout_method): 94 | transpile(self.time_qft_16, self.backend, 95 | routing_method=routing_method, 96 | layout_method=layout_method, 97 | optimization_level=optimization_level, 98 | seed_transpiler=0) 99 | -------------------------------------------------------------------------------- /docs/configuration.rst: -------------------------------------------------------------------------------- 1 | Local Configuration 2 | =================== 3 | 4 | Once you have Qiskit installed and running there are some optional configuration 5 | steps you can take to change the default behavior of Qiskit for your specific 6 | use case. 7 | 8 | User Config File 9 | ---------------- 10 | 11 | The main location for local configuration of Qiskit is the user config file. 12 | This is an `ini `__ format file that 13 | can be used to change defaults in Qiskit. 14 | 15 | For example: 16 | 17 | .. code-block:: ini 18 | 19 | [default] 20 | circuit_drawer = mpl 21 | circuit_mpl_style = default 22 | circuit_mpl_style_path = ~:~/.qiskit 23 | state_drawer = hinton 24 | transpile_optimization_level = 3 25 | parallel = False 26 | num_processes = 15 27 | 28 | By default this file lives in ``~/.qiskit/settings.conf`` but the path used 29 | can be overriden with the ``QISKIT_SETTINGS`` environment variable. If 30 | ``QISKIT_SETTINGS`` is set its value will used as the path to the user config 31 | file. 32 | 33 | Available options: 34 | 35 | * ``circuit_drawer``: This is used to change the default backend for 36 | the circuit drawer :meth:`qiskit.circuit.QuantumCircuit.draw` and 37 | :func:`qiskit.visualization.circuit_drawer`. It can be set to ``latex``, 38 | ``mpl``, ``text``, or ``latex_source`` and when the ``ouptut`` kwarg is 39 | not explicitly set that drawer backend will be used. 40 | * ``circuit_mpl_style``: This is the default style sheet used for the 41 | ``mpl`` output backend for the circuit drawer 42 | :meth:`qiskit.circuit.QuantumCircuit.draw` and 43 | :func:`qiskit.visualization.circuit_drawer`. It can be set to ``default`` 44 | or ``bw``. 45 | * ``circuit_mpl_style_path``: This can be used to set the path(s) to have the 46 | circuit drawer, :meth:`qiskit.circuit.QuantumCircuit.draw` or 47 | :func:`qiskit.visualization.circuit_drawer`, use to look for json style 48 | sheets when using the ``mpl`` output mode. 49 | * ``state_drawer``: This is used to change the default backend for the 50 | state visualization draw methods :meth:`qiskit.quantum_info.Statevector.draw` 51 | and :meth:`qiskit.quantum_info.DensityMatrix.draw`. It can be set to 52 | ``repr``, ``text``', ``latex``, ``latex_source``, ``qsphere``, ``hinton``, 53 | or bloch ``bloch`` and when the ``output`` kwarg is not explicitly set on 54 | the :meth:`~qiskit.quantum_info.DensityMatrix.draw` method that output 55 | method will be used. 56 | * ``transpile_optimization_level``: This takes an integer between 0-3 and is 57 | used to change the default optimization level for 58 | :func:`~qiskit.compiler.transpile` and :func:`~qiskit.execute.execute`. 59 | * ``parallel``: This option takes a boolean value (either ``True`` or 60 | ``False``) and is used to configure whether 61 | `Python multiprocessing `__ 62 | is enabled for operations that support running in parallel (for example 63 | transpilation of multiple :class:`~qiskit.circuit.QuantumCircuit` objects). 64 | The default setting in the user config file can be overriden by 65 | the ``QISKIT_PARALLEL`` environment variable. 66 | * ``num_processes``: This option takes an integer value (> 0) that is used 67 | to specify the maximum number of parallel processes to launch for parallel 68 | operations if parallel execution is enabled. The default setting in the 69 | user config file can be overriden by the ``QISKIT_NUM_PROCS`` environment 70 | variable. 71 | 72 | Environment Variables 73 | --------------------- 74 | 75 | There are also a few environment variables that can be set to alter the default 76 | behavior of Qiskit. 77 | 78 | * ``QISKIT_PARALLEL``: if this variable is set to ``TRUE`` it will enable 79 | the use of 80 | `Python multiprocessing `__ 81 | to parallelize certain operations (for example transpilation over multiple 82 | circuits) in Qiskit. 83 | * ``QISKIT_NUM_PROCS``: Specifies the maximum number of parallel processes to 84 | launch for parallel operations if parallel execution is enabled. It takes an 85 | integer > 0 as the expected value. 86 | * ``RAYON_NUM_THREADS``: Specifies the number of threads to run multithreaded 87 | operations in Qiskit. By default this multithreaded code will launch 88 | a thread for each logical CPU, if you'd like to adjust the number of threads 89 | Qiskit will use you can set this to an integer value. For example, setting 90 | ``RAYON_NUM_THREADS=4`` will only launch 4 threads for multithreaded 91 | functions. 92 | * ``QISKIT_FORCE_THREADS``: Specify that multithreaded code should always 93 | execute in multiple threads. By default if you're running multithreaded code 94 | in a section of Qiskit that is already running in parallel processes Qiskit 95 | will not launch multiple threads and instead execute that function serially. 96 | This is done to avoid potentially overloading limited CPU resources. However, 97 | if you would like to force the use of multiple threads even when in a 98 | multiprocess context you can set ``QISKIT_FORCE_THREADS=TRUE`` to do this. 99 | -------------------------------------------------------------------------------- /test/base.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # This code is part of Qiskit. 4 | # 5 | # (C) Copyright IBM 2018. 6 | # 7 | # This code is licensed under the Apache License, Version 2.0. You may 8 | # obtain a copy of this license in the LICENSE.txt file in the root directory 9 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 10 | # 11 | # Any modifications or derivative works of this code must retain this 12 | # copyright notice, and modified files need to carry a notice indicating 13 | # that they have been altered from the originals. 14 | 15 | # pylint: disable=missing-raises-doc 16 | 17 | """Base functionality for Qiskit tests.""" 18 | 19 | from unittest import TestCase 20 | from unittest.util import safe_repr 21 | 22 | 23 | class QiskitTestCase(TestCase): 24 | """TestCase subclass with a custom assertion.""" 25 | 26 | def assertDictAlmostEqual( 27 | self, dict1, dict2, delta=None, msg=None, places=None, default_value=0 28 | ): 29 | """Assert two dictionaries with numeric values are almost equal 30 | 31 | Fail if the two dictionaries are unequal as determined by 32 | comparing that the difference between values with the same key are 33 | not greater than delta (default 1e-8), or that difference rounded 34 | to the given number of decimal places is not zero. If a key in one 35 | dictionary is not in the other the default_value keyword argument 36 | will be used for the missing value (default 0). If the two objects 37 | compare equal then they will automatically compare almost equal. 38 | 39 | Args: 40 | dict1 (dict): a dictionary. 41 | dict2 (dict): a dictionary. 42 | delta (number): threshold for comparison (defaults to 1e-8). 43 | msg (str): return a custom message on failure. 44 | places (int): number of decimal places for comparison. 45 | default_value (number): default value for missing keys. 46 | 47 | Raises: 48 | TypeError: raises TestCase failureException if the test fails. 49 | """ 50 | if dict1 == dict2: 51 | # Shortcut 52 | return 53 | if delta is not None and places is not None: 54 | raise TypeError("specify delta or places not both") 55 | 56 | if places is not None: 57 | success = True 58 | standard_msg = "" 59 | # check value for keys in target 60 | keys1 = set(dict1.keys()) 61 | for key in keys1: 62 | val1 = dict1.get(key, default_value) 63 | val2 = dict2.get(key, default_value) 64 | if round(abs(val1 - val2), places) != 0: 65 | success = False 66 | standard_msg += "(%s: %s != %s), " % ( 67 | safe_repr(key), 68 | safe_repr(val1), 69 | safe_repr(val2), 70 | ) 71 | # check values for keys in counts, not in target 72 | keys2 = set(dict2.keys()) - keys1 73 | for key in keys2: 74 | val1 = dict1.get(key, default_value) 75 | val2 = dict2.get(key, default_value) 76 | if round(abs(val1 - val2), places) != 0: 77 | success = False 78 | standard_msg += "(%s: %s != %s), " % ( 79 | safe_repr(key), 80 | safe_repr(val1), 81 | safe_repr(val2), 82 | ) 83 | if success is True: 84 | return 85 | standard_msg = standard_msg[:-2] + " within %s places" % places 86 | 87 | else: 88 | if delta is None: 89 | delta = 1e-8 # default delta value 90 | success = True 91 | standard_msg = "" 92 | # check value for keys in target 93 | keys1 = set(dict1.keys()) 94 | for key in keys1: 95 | val1 = dict1.get(key, default_value) 96 | val2 = dict2.get(key, default_value) 97 | if abs(val1 - val2) > delta: 98 | success = False 99 | standard_msg += "(%s: %s != %s), " % ( 100 | safe_repr(key), 101 | safe_repr(val1), 102 | safe_repr(val2), 103 | ) 104 | # check values for keys in counts, not in target 105 | keys2 = set(dict2.keys()) - keys1 106 | for key in keys2: 107 | val1 = dict1.get(key, default_value) 108 | val2 = dict2.get(key, default_value) 109 | if abs(val1 - val2) > delta: 110 | success = False 111 | standard_msg += "(%s: %s != %s), " % ( 112 | safe_repr(key), 113 | safe_repr(val1), 114 | safe_repr(val2), 115 | ) 116 | if success is True: 117 | return 118 | standard_msg = standard_msg[:-2] + " within %s delta" % delta 119 | 120 | msg = self._formatMessage(msg, standard_msg) 121 | raise self.failureException(msg) 122 | -------------------------------------------------------------------------------- /test/benchmarks/qasm/depth_mod8-10_178.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 2.0; 2 | include "qelib1.inc"; 3 | qreg q[16]; 4 | creg c[16]; 5 | h q[2]; 6 | t q[4]; 7 | t q[3]; 8 | t q[2]; 9 | cx q[3],q[4]; 10 | cx q[2],q[3]; 11 | cx q[4],q[2]; 12 | tdg q[3]; 13 | cx q[4],q[3]; 14 | tdg q[4]; 15 | tdg q[3]; 16 | t q[2]; 17 | cx q[2],q[3]; 18 | cx q[4],q[2]; 19 | cx q[3],q[4]; 20 | h q[2]; 21 | cx q[4],q[2]; 22 | cx q[1],q[3]; 23 | h q[5]; 24 | t q[4]; 25 | t q[3]; 26 | t q[5]; 27 | cx q[3],q[4]; 28 | cx q[5],q[3]; 29 | cx q[4],q[5]; 30 | tdg q[3]; 31 | cx q[4],q[3]; 32 | tdg q[4]; 33 | tdg q[3]; 34 | t q[5]; 35 | cx q[5],q[3]; 36 | cx q[4],q[5]; 37 | cx q[3],q[4]; 38 | h q[5]; 39 | h q[1]; 40 | t q[5]; 41 | t q[4]; 42 | t q[1]; 43 | cx q[4],q[5]; 44 | cx q[1],q[4]; 45 | cx q[5],q[1]; 46 | tdg q[4]; 47 | cx q[5],q[4]; 48 | tdg q[5]; 49 | tdg q[4]; 50 | t q[1]; 51 | cx q[1],q[4]; 52 | cx q[5],q[1]; 53 | cx q[4],q[5]; 54 | h q[1]; 55 | h q[4]; 56 | t q[2]; 57 | t q[0]; 58 | t q[4]; 59 | cx q[0],q[2]; 60 | cx q[4],q[0]; 61 | cx q[2],q[4]; 62 | tdg q[0]; 63 | cx q[2],q[0]; 64 | tdg q[2]; 65 | tdg q[0]; 66 | t q[4]; 67 | cx q[4],q[0]; 68 | cx q[2],q[4]; 69 | cx q[0],q[2]; 70 | h q[4]; 71 | h q[1]; 72 | t q[5]; 73 | t q[4]; 74 | t q[1]; 75 | cx q[4],q[5]; 76 | cx q[1],q[4]; 77 | cx q[5],q[1]; 78 | tdg q[4]; 79 | cx q[5],q[4]; 80 | tdg q[5]; 81 | tdg q[4]; 82 | t q[1]; 83 | cx q[1],q[4]; 84 | cx q[5],q[1]; 85 | cx q[4],q[5]; 86 | h q[1]; 87 | h q[4]; 88 | t q[2]; 89 | t q[0]; 90 | t q[4]; 91 | cx q[0],q[2]; 92 | cx q[4],q[0]; 93 | cx q[2],q[4]; 94 | tdg q[0]; 95 | cx q[2],q[0]; 96 | tdg q[2]; 97 | tdg q[0]; 98 | t q[4]; 99 | cx q[4],q[0]; 100 | cx q[2],q[4]; 101 | cx q[0],q[2]; 102 | h q[4]; 103 | h q[5]; 104 | t q[4]; 105 | t q[3]; 106 | t q[5]; 107 | cx q[3],q[4]; 108 | cx q[5],q[3]; 109 | cx q[4],q[5]; 110 | tdg q[3]; 111 | cx q[4],q[3]; 112 | tdg q[4]; 113 | tdg q[3]; 114 | t q[5]; 115 | cx q[5],q[3]; 116 | cx q[4],q[5]; 117 | cx q[3],q[4]; 118 | h q[5]; 119 | h q[1]; 120 | t q[5]; 121 | t q[4]; 122 | t q[1]; 123 | cx q[4],q[5]; 124 | cx q[1],q[4]; 125 | cx q[5],q[1]; 126 | tdg q[4]; 127 | cx q[5],q[4]; 128 | tdg q[5]; 129 | tdg q[4]; 130 | t q[1]; 131 | cx q[1],q[4]; 132 | cx q[5],q[1]; 133 | cx q[4],q[5]; 134 | h q[1]; 135 | h q[4]; 136 | t q[2]; 137 | t q[0]; 138 | t q[4]; 139 | cx q[0],q[2]; 140 | cx q[4],q[0]; 141 | cx q[2],q[4]; 142 | tdg q[0]; 143 | cx q[2],q[0]; 144 | tdg q[2]; 145 | tdg q[0]; 146 | t q[4]; 147 | cx q[4],q[0]; 148 | cx q[2],q[4]; 149 | cx q[0],q[2]; 150 | h q[4]; 151 | h q[1]; 152 | t q[5]; 153 | t q[4]; 154 | t q[1]; 155 | cx q[4],q[5]; 156 | cx q[1],q[4]; 157 | cx q[5],q[1]; 158 | tdg q[4]; 159 | cx q[5],q[4]; 160 | tdg q[5]; 161 | tdg q[4]; 162 | t q[1]; 163 | cx q[1],q[4]; 164 | cx q[5],q[1]; 165 | cx q[4],q[5]; 166 | h q[1]; 167 | h q[4]; 168 | t q[2]; 169 | t q[0]; 170 | t q[4]; 171 | cx q[0],q[2]; 172 | cx q[4],q[0]; 173 | cx q[2],q[4]; 174 | tdg q[0]; 175 | cx q[2],q[0]; 176 | tdg q[2]; 177 | tdg q[0]; 178 | t q[4]; 179 | cx q[4],q[0]; 180 | cx q[2],q[4]; 181 | cx q[0],q[2]; 182 | h q[4]; 183 | cx q[1],q[3]; 184 | h q[5]; 185 | t q[4]; 186 | t q[2]; 187 | t q[5]; 188 | cx q[2],q[4]; 189 | cx q[5],q[2]; 190 | cx q[4],q[5]; 191 | tdg q[2]; 192 | cx q[4],q[2]; 193 | tdg q[4]; 194 | tdg q[2]; 195 | t q[5]; 196 | cx q[5],q[2]; 197 | cx q[4],q[5]; 198 | cx q[2],q[4]; 199 | h q[5]; 200 | h q[3]; 201 | t q[5]; 202 | t q[4]; 203 | t q[3]; 204 | cx q[4],q[5]; 205 | cx q[3],q[4]; 206 | cx q[5],q[3]; 207 | tdg q[4]; 208 | cx q[5],q[4]; 209 | tdg q[5]; 210 | tdg q[4]; 211 | t q[3]; 212 | cx q[3],q[4]; 213 | cx q[5],q[3]; 214 | cx q[4],q[5]; 215 | h q[3]; 216 | h q[4]; 217 | t q[1]; 218 | t q[0]; 219 | t q[4]; 220 | cx q[0],q[1]; 221 | cx q[4],q[0]; 222 | cx q[1],q[4]; 223 | tdg q[0]; 224 | cx q[1],q[0]; 225 | tdg q[1]; 226 | tdg q[0]; 227 | t q[4]; 228 | cx q[4],q[0]; 229 | cx q[1],q[4]; 230 | cx q[0],q[1]; 231 | h q[4]; 232 | h q[3]; 233 | t q[5]; 234 | t q[4]; 235 | t q[3]; 236 | cx q[4],q[5]; 237 | cx q[3],q[4]; 238 | cx q[5],q[3]; 239 | tdg q[4]; 240 | cx q[5],q[4]; 241 | tdg q[5]; 242 | tdg q[4]; 243 | t q[3]; 244 | cx q[3],q[4]; 245 | cx q[5],q[3]; 246 | cx q[4],q[5]; 247 | h q[3]; 248 | h q[4]; 249 | t q[1]; 250 | t q[0]; 251 | t q[4]; 252 | cx q[0],q[1]; 253 | cx q[4],q[0]; 254 | cx q[1],q[4]; 255 | tdg q[0]; 256 | cx q[1],q[0]; 257 | tdg q[1]; 258 | tdg q[0]; 259 | t q[4]; 260 | cx q[4],q[0]; 261 | cx q[1],q[4]; 262 | cx q[0],q[1]; 263 | h q[4]; 264 | h q[5]; 265 | t q[4]; 266 | t q[2]; 267 | t q[5]; 268 | cx q[2],q[4]; 269 | cx q[5],q[2]; 270 | cx q[4],q[5]; 271 | tdg q[2]; 272 | cx q[4],q[2]; 273 | tdg q[4]; 274 | tdg q[2]; 275 | t q[5]; 276 | cx q[5],q[2]; 277 | cx q[4],q[5]; 278 | cx q[2],q[4]; 279 | h q[5]; 280 | h q[3]; 281 | t q[5]; 282 | t q[4]; 283 | t q[3]; 284 | cx q[4],q[5]; 285 | cx q[3],q[4]; 286 | cx q[5],q[3]; 287 | tdg q[4]; 288 | cx q[5],q[4]; 289 | tdg q[5]; 290 | tdg q[4]; 291 | t q[3]; 292 | cx q[3],q[4]; 293 | cx q[5],q[3]; 294 | cx q[4],q[5]; 295 | h q[3]; 296 | h q[4]; 297 | t q[1]; 298 | t q[0]; 299 | t q[4]; 300 | cx q[0],q[1]; 301 | cx q[4],q[0]; 302 | cx q[1],q[4]; 303 | tdg q[0]; 304 | cx q[1],q[0]; 305 | tdg q[1]; 306 | tdg q[0]; 307 | t q[4]; 308 | cx q[4],q[0]; 309 | cx q[1],q[4]; 310 | cx q[0],q[1]; 311 | h q[4]; 312 | h q[3]; 313 | t q[5]; 314 | t q[4]; 315 | t q[3]; 316 | cx q[4],q[5]; 317 | cx q[3],q[4]; 318 | cx q[5],q[3]; 319 | tdg q[4]; 320 | cx q[5],q[4]; 321 | tdg q[5]; 322 | tdg q[4]; 323 | t q[3]; 324 | cx q[3],q[4]; 325 | cx q[5],q[3]; 326 | cx q[4],q[5]; 327 | h q[3]; 328 | h q[4]; 329 | t q[1]; 330 | t q[0]; 331 | t q[4]; 332 | cx q[0],q[1]; 333 | cx q[4],q[0]; 334 | cx q[1],q[4]; 335 | tdg q[0]; 336 | cx q[1],q[0]; 337 | tdg q[1]; 338 | tdg q[0]; 339 | t q[4]; 340 | cx q[4],q[0]; 341 | cx q[1],q[4]; 342 | cx q[0],q[1]; 343 | h q[4]; 344 | cx q[4],q[3]; 345 | cx q[4],q[2]; 346 | x q[4]; 347 | -------------------------------------------------------------------------------- /test/benchmarks/quantum_volume.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Copyright 2018 IBM RESEARCH. All Rights Reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # ============================================================================= 17 | 18 | # pylint: disable=missing-class-docstring,missing-function-docstring 19 | # pylint: disable=attribute-defined-outside-init 20 | 21 | """Module for estimating quantum volume. 22 | See arXiv:1811.12926 [quant-ph]""" 23 | 24 | import itertools 25 | 26 | import numpy as np 27 | 28 | from qiskit.compiler import transpile 29 | from qiskit.converters import circuit_to_dag 30 | from qiskit.transpiler import CouplingMap 31 | from qiskit.transpiler.passes import SabreSwap 32 | 33 | from .utils import build_qv_model_circuit 34 | 35 | 36 | class QuantumVolumeBenchmark: 37 | params = ([1, 2, 3, 5, 8, 14, 20, 27], ['translator', 'synthesis']) 38 | param_names = ['Number of Qubits', 'Basis Translation Method'] 39 | version = 3 40 | 41 | def setup(self, width, _): 42 | random_seed = np.random.seed(10) 43 | self.circuit = build_qv_model_circuit(width, width, random_seed) 44 | self.coupling_map = [ 45 | [0, 1], [1, 0], [1, 2], [1, 4], [2, 1], [2, 3], [3, 2], [3, 5], 46 | [4, 1], [4, 7], [5, 3], [5, 8], [6, 7], [7, 4], [7, 6], [7, 10], 47 | [8, 5], [8, 9], [8, 11], [9, 8], [10, 7], [10, 12], [11, 8], 48 | [11, 14], [12, 10], [12, 13], [12, 15], [13, 12], [13, 14], 49 | [14, 11], [14, 13], [14, 16], [15, 12], [15, 18], [16, 14], 50 | [16, 19], [17, 18], [18, 15], [18, 17], [18, 21], [19, 16], 51 | [19, 20], [19, 22], [20, 19], [21, 18], [21, 23], [22, 19], 52 | [22, 25], [23, 21], [23, 24], [24, 23], [24, 25], [25, 22], 53 | [25, 24], [25, 26], [26, 25]] 54 | self.basis = ['id', 'rz', 'sx', 'x', 'cx', 'reset'] 55 | 56 | def time_ibmq_backend_transpile(self, _, translation): 57 | transpile(self.circuit, 58 | basis_gates=self.basis, 59 | coupling_map=self.coupling_map, 60 | translation_method=translation, 61 | seed_transpiler=20220125) 62 | 63 | 64 | class LargeQuantumVolumeMappingTimeBench: 65 | timeout = 600.0 # seconds 66 | heavy_hex_distance = {115: 7, 409: 13, 1081: 21} 67 | allowed_sizes = {(115, 100), (115, 10), (409, 10), (1081, 10)} 68 | n_qubits = sorted({n_qubits for n_qubits, _ in allowed_sizes}) 69 | depths = sorted({depth for _, depth in allowed_sizes}) 70 | 71 | params = (n_qubits, depths, ["lookahead", "decay"]) 72 | param_names = ["n_qubits", "depth", "heuristic"] 73 | 74 | def setup(self, n_qubits, depth, _): 75 | if (n_qubits, depth) not in self.allowed_sizes: 76 | raise NotImplementedError 77 | seed = 2022_10_27 78 | self.dag = circuit_to_dag( 79 | build_qv_model_circuit(n_qubits, depth, seed) 80 | ) 81 | self.coupling = CouplingMap.from_heavy_hex( 82 | self.heavy_hex_distance[n_qubits] 83 | ) 84 | 85 | def time_sabre_swap(self, _n_qubits, _depth, heuristic): 86 | pass_ = SabreSwap(self.coupling, heuristic, seed=2022_10_27, trials=1) 87 | pass_.run(self.dag) 88 | 89 | 90 | class LargeQuantumVolumeMappingTrackBench: 91 | timeout = 600.0 # seconds 92 | 93 | allowed_sizes = {(115, 100), (115, 10), (409, 10), (1081, 10)} 94 | heuristics = ["lookahead", "decay"] 95 | n_qubits = sorted({n_qubits for n_qubits, _ in allowed_sizes}) 96 | depths = sorted({depth for _, depth in allowed_sizes}) 97 | 98 | params = (n_qubits, depths, heuristics) 99 | param_names = ["n_qubits", "depth", "heuristic"] 100 | 101 | # The benchmarks take a significant amount of time to run, and we don't 102 | # want to unnecessarily run things twice to get the two pieces of tracking 103 | # information we're interested in. We cheat by using the setup cache to do 104 | # all the calculation work only once, and then each tracker just quickly 105 | # pulls the result from the cache to return, saving the duplication. 106 | 107 | def setup_cache(self): 108 | heavy_hex_distance = {115: 7, 409: 13, 1081: 21} 109 | seed = 2022_10_27 110 | 111 | def setup(n_qubits, depth, heuristic): 112 | dag = circuit_to_dag( 113 | build_qv_model_circuit(n_qubits, depth, seed) 114 | ) 115 | coupling = CouplingMap.from_heavy_hex(heavy_hex_distance[n_qubits]) 116 | return SabreSwap(coupling, heuristic, seed=seed, trials=1).run(dag) 117 | 118 | state = {} 119 | for params in itertools.product(*self.params): 120 | n_qubits, depth, _ = params 121 | if (n_qubits, depth) not in self.allowed_sizes: 122 | continue 123 | dag = setup(*params) 124 | state[params] = {"depth": dag.depth(), "size": dag.size()} 125 | return state 126 | 127 | def setup(self, _state, n_qubits, depth, _heuristic): 128 | if (n_qubits, depth) not in self.allowed_sizes: 129 | raise NotImplementedError 130 | 131 | def track_depth_sabre_swap(self, state, *params): 132 | return state[params]["depth"] 133 | 134 | def track_size_sabre_swap(self, state, *params): 135 | return state[params]["size"] 136 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | The Qiskit Community is dedicated to our values of treating every individual 6 | with respect and dignity. In the interest of fostering an open and welcoming 7 | environment, all participants, including attendees, speakers, sponsors, 8 | volunteers, online contributors, and IBM employees are expected to show 9 | courtesy for each other and our community by creating a harassment-free 10 | experience for everyone, regardless of age, personal appearance, disability, 11 | ethnicity, gender identity and expression, body size, level of experience, 12 | nationality, race, religion, caste, or sexual identity and orientation. 13 | Expected behavior applies to both online and offline engagement within the 14 | Qiskit Community. 15 | 16 | ## Scope 17 | 18 | The purpose of this Code of Conduct is to define and enforce the values and 19 | conduct of contributors and participants in the Qiskit open source community. 20 | The Code of Conduct applies both within project spaces and in public spaces 21 | when an individual is engaging with the Qiskit open source community. Examples 22 | include attending a Qiskit event, contributing to online projects, commentary 23 | on Slack, or representing a project or community, including using an official 24 | project e-mail address, posting via an official social media account, or 25 | acting as an appointed representative at an online or offline event. 26 | Representation of a project may be further defined and clarified by project 27 | maintainers. 28 | 29 | ## Our Standards 30 | 31 | Examples of behavior that contributes to creating a positive environment 32 | include: 33 | 34 | - Using welcoming and inclusive language 35 | - Being respectful of differing viewpoints, experiences, and cultures 36 | - Gracefully accepting constructive criticism 37 | - Focusing on what is best for the community 38 | - Showing empathy towards other community members 39 | - Being mindful of your surroundings and your fellow participants and listening 40 | to others 41 | - Valuing the contributions of all participants 42 | - Engaging in collaboration before conflict 43 | - Pointing out unintentionally racist, sexist, casteist, or biased comments and 44 | jokes made by community members when they happen 45 | 46 | Examples of unacceptable behavior by participants, even when presented as 47 | "ironic" or "joking," include: 48 | 49 | - The use of sexualized language or imagery and unwelcome physical contact, 50 | sexual attention, or advances 51 | - Trolling, insulting/derogatory comments, and personal or political attacks 52 | - Public or private harassment, including offensive or degrading language 53 | - Publishing others' private information, such as a physical or electronic 54 | address, without explicit permission. This includes any sort of "outing" of 55 | any aspect of someone's identity without their consent. 56 | - "Doxxing," Publishing screenshots or quotes, especially from identity slack 57 | channels, private chat, or public events, without all quoted users' explicit 58 | consent. 59 | - Engaging in spamming activities, such as repeatedly sending unsolicited messages, LLMs (Large Language Models) output, advertisements, or promotional content to community members without previous IBM authorization. 60 | - Other conduct which could reasonably be considered inappropriate in a 61 | professional setting 62 | 63 | ## Responsibilities & Enforcement 64 | 65 | The entire Qiskit community is responsible for upholding the terms of the Code 66 | of Conduct in Qiskit Community events and spaces and reporting violations if 67 | they see them. The internal Qiskit team at IBM is ultimately responsible for 68 | clarifying the standards of acceptable behavior and enforcement, and is expected 69 | to take appropriate and fair corrective action in response to any instances of 70 | unacceptable behavior. 71 | 72 | If a participant or contributor engages in negative or harmful behavior, IBM 73 | will take any action they deem appropriate, including but not limited to 74 | issuing warnings, expulsion from an event with no refund, deleting comments, 75 | permanent banning from future events or online community, or calling local law 76 | enforcement. IBM has the right and responsibility to remove, edit, or reject 77 | comments, commits, code, wiki edits, issues, and other contributions that are 78 | not aligned to this Code of Conduct, or to temporarily or permanently ban any 79 | contributor or participant for other behaviors that they deem inappropriate, 80 | threatening, offensive, or harmful. 81 | 82 | If you see a Code of Conduct violation: 83 | 84 | 1. If you feel comfortable, let the person know that what they did is not 85 | appropriate and ask them to stop and/or edit or delete their message(s) or 86 | comment(s). 87 | 2. If the person does not immediately stop the behavior or correct the issue, 88 | or if you're uncomfortable speaking up, flag a moderator and, if appropriate, 89 | fill out the anonymous 90 | [Code of Conduct violation form](https://airtable.com/shrl5mEF4Eun1aIDm). 91 | 3. The Qiskit Community will open an investigation upon receiving your form 92 | entry. When reporting, please include any relevant details, links, 93 | screenshots, context, or other information that may be used to better 94 | understand and resolve the situation. 95 | 4. If the code of conduct violation occurs at an event and requires immediate 96 | response or contains a concern about an individual attending an upcoming 97 | event, contact the event's on-call Code of Conduct point of contact listed 98 | in the event specific code of conduct document. If you don't feel comfortable 99 | speaking to the point of contact in person, fill out a Code of Conduct 100 | violation form entry and include the details of the event so that the Code of 101 | Conduct enforcement board can contact the event's on-call Code of Conduct 102 | point of contact. 103 | 5. If an IBM employee witnesses a Code of Conduct violation at any time, such as 104 | at events, in a Slack channel, or open source forums, it is their 105 | responsibility to file a Code of Conduct violation report. 106 | 107 | This Code of Conduct does not supersede existing IBM corporate policies, such as 108 | the IBM Business Conduct Guidelines and IBM Business Partner Code of Conduct. 109 | IBM employees must follow IBM's Business Conduct Guidelines. IBM's business 110 | partners must follow the IBM Business Partner Code of Conduct. IBM employees 111 | concerned with a fellow IBMer's behavior should follow IBM's own internal HR 112 | reporting protocols, which include engaging the offending IBMer's manager and 113 | involving IBM Concerns and Appeals. IBM employees concerned with an IBM 114 | business partner's behavior should notify tellibm@us.ibm.com. 115 | -------------------------------------------------------------------------------- /test/benchmarks/pulse/schedule_construction.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -* 2 | 3 | # This code is part of Qiskit. 4 | # 5 | # (C) Copyright IBM 2020. 6 | # 7 | # This code is licensed under the Apache License, Version 2.0. You may 8 | # obtain a copy of this license in the LICENSE.txt file in the root directory 9 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 10 | # 11 | # Any modifications or derivative works of this code must retain this 12 | # copyright notice, and modified files need to carry a notice indicating 13 | # that they have been altered from the originals. 14 | 15 | # pylint: disable=missing-docstring,invalid-name,no-member 16 | # pylint: disable=attribute-defined-outside-init 17 | 18 | import numpy as np 19 | 20 | from qiskit.circuit import Parameter, QuantumCircuit, Gate 21 | from qiskit.pulse import builder, library, channels 22 | 23 | 24 | class EchoedCrossResonanceConstructionBench: 25 | 26 | def setup(self): 27 | 28 | with builder.build() as x_ctrl: 29 | builder.play( 30 | library.Drag(160, 0.2, 40, 1.5), 31 | channels.DriveChannel(0), 32 | ) 33 | self.x_ctrl = x_ctrl 34 | 35 | with builder.build() as cr45p: 36 | builder.play( 37 | library.GaussianSquare(800, 0.4, 64, 544), 38 | channels.ControlChannel(0), 39 | ) 40 | builder.play( 41 | library.GaussianSquare(800, 0.1, 64, 544), 42 | channels.DriveChannel(1), 43 | ) 44 | self.cr45p = cr45p 45 | 46 | def time_full_scratch(self): 47 | # Full scratch in a single builder context 48 | with builder.build(): 49 | with builder.align_sequential(): 50 | with builder.align_left(): 51 | builder.play( 52 | library.GaussianSquare(800, 0.4, 64, 544), 53 | channels.ControlChannel(0), 54 | ) 55 | builder.play( 56 | library.GaussianSquare(800, 0.1, 64, 544), 57 | channels.DriveChannel(1), 58 | ) 59 | builder.play( 60 | library.Drag(160, 0.2, 40, 1.5), 61 | channels.DriveChannel(0), 62 | ) 63 | with builder.phase_offset( 64 | np.pi, 65 | channels.ControlChannel(0), 66 | channels.DriveChannel(1), 67 | ): 68 | with builder.align_left(): 69 | builder.play( 70 | library.GaussianSquare(800, 0.4, 64, 544), 71 | channels.ControlChannel(0), 72 | ) 73 | builder.play( 74 | library.GaussianSquare(800, 0.1, 64, 544), 75 | channels.DriveChannel(1), 76 | ) 77 | builder.play( 78 | library.Drag(160, 0.2, 40, 1.5), 79 | channels.DriveChannel(0), 80 | ) 81 | 82 | def time_with_call(self): 83 | # Call subroutine, internally creates reference and assign immediately 84 | with builder.build(): 85 | with builder.align_sequential(): 86 | builder.call(self.cr45p) 87 | builder.call(self.x_ctrl) 88 | with builder.phase_offset( 89 | np.pi, 90 | channels.ControlChannel(0), 91 | channels.DriveChannel(1), 92 | ): 93 | builder.call(self.cr45p) 94 | builder.call(self.x_ctrl) 95 | 96 | def time_assign_later(self): 97 | # Create placeholder and assign subroutine at a later time 98 | with builder.build() as temp_sched: 99 | with builder.align_sequential(): 100 | builder.reference("cr45p", "q0", "q1") 101 | builder.reference("x", "q0") 102 | with builder.phase_offset( 103 | np.pi, 104 | channels.ControlChannel(0), 105 | channels.DriveChannel(1), 106 | ): 107 | builder.reference("cr45p", "q0", "q1") 108 | builder.reference("x", "q0") 109 | 110 | temp_sched.assign_references( 111 | { 112 | ("cr45p", "q0", "q1"): self.cr45p, 113 | ("x", "q0"): self.x_ctrl, 114 | }, 115 | inplace=True, 116 | ) 117 | 118 | 119 | class ParameterizedScheduleBench: 120 | 121 | params = [3, 11, 31, 51] 122 | 123 | def setup(self, nscan): 124 | self.p0 = Parameter("P0") 125 | self.p1 = Parameter("P1") 126 | self.p2 = Parameter("P2") 127 | 128 | with builder.build() as schedule: 129 | builder.play( 130 | library.Constant(self.p0, self.p1), 131 | channels.DriveChannel(self.p2), 132 | ) 133 | self.schedule = schedule 134 | 135 | with builder.build() as outer_schedule: 136 | builder.reference("subroutine") 137 | outer_schedule.assign_references( 138 | {("subroutine", ): schedule}, inplace=True 139 | ) 140 | self.outer_schedule = outer_schedule 141 | 142 | gate = Gate("my_gate", 1, [self.p0, self.p1, self.p2]) 143 | qc = QuantumCircuit(1) 144 | qc.append(gate, [0]) 145 | qc.add_calibration(gate, (0,), schedule) 146 | self.qc = qc 147 | 148 | # list of parameters 149 | self.amps = np.linspace(-1, 1, nscan) 150 | 151 | def time_assign_single_schedule(self, _): 152 | 153 | out = [] 154 | for amp in self.amps: 155 | assigned = self.schedule.assign_parameters( 156 | {self.p0: 100, self.p1: amp, self.p2: 0}, 157 | inplace=False, 158 | ) 159 | out.append(assigned) 160 | 161 | def time_assign_parameterized_subroutine(self, _): 162 | 163 | out = [] 164 | for amp in self.amps: 165 | assigned = self.outer_schedule.assign_parameters( 166 | {self.p0: 100, self.p1: amp, self.p2: 0}, 167 | inplace=False, 168 | ) 169 | out.append(assigned) 170 | 171 | def time_assign_through_pulse_gate(self, _): 172 | 173 | out = [] 174 | for amp in self.amps: 175 | assigned = self.qc.assign_parameters( 176 | {self.p0: 100, self.p1: amp, self.p2: 0}, 177 | inplace=False, 178 | ) 179 | out.append(assigned) 180 | -------------------------------------------------------------------------------- /test/benchmarks/utils.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # This code is part of Qiskit. 4 | # 5 | # (C) Copyright IBM 2019. 6 | # 7 | # This code is licensed under the Apache License, Version 2.0. You may 8 | # obtain a copy of this license in the LICENSE.txt file in the root directory 9 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 10 | # 11 | # Any modifications or derivative works of this code must retain this 12 | # copyright notice, and modified files need to carry a notice indicating 13 | # that they have been altered from the originals. 14 | 15 | # pylint: disable=invalid-name,no-member 16 | 17 | """Benchmark utility functions.""" 18 | 19 | import numpy as np 20 | 21 | from qiskit.quantum_info.random import random_unitary 22 | from qiskit.circuit import QuantumRegister, ClassicalRegister, QuantumCircuit 23 | from qiskit.circuit import Reset 24 | from qiskit.circuit.library import (IGate, U1Gate, U2Gate, U3Gate, XGate, 25 | YGate, ZGate, HGate, SGate, SdgGate, TGate, 26 | TdgGate, RXGate, RYGate, RZGate, CXGate, 27 | CYGate, CZGate, CHGate, CRZGate, CU1Gate, 28 | CU3Gate, SwapGate, RZZGate, 29 | CCXGate, CSwapGate) 30 | 31 | 32 | def random_circuit(n_qubits, depth, max_operands=3, measure=False, 33 | conditional=False, reset=False, seed=None): 34 | """Generate random circuit of arbitrary size and form. 35 | 36 | Args: 37 | n_qubits (int): number of quantum wires 38 | depth (int): layers of operations (i.e. critical path length) 39 | max_operands (int): maximum operands of each gate (between 1 and 3) 40 | measure (bool): if True, measure all qubits at the end 41 | conditional (bool): if True, insert middle measurements and 42 | conditionals 43 | reset (bool): if True, insert middle resets 44 | seed (int): sets random seed (optional) 45 | 46 | Returns: 47 | QuantumCircuit: constructed circuit 48 | 49 | Raises: 50 | Exception: when invalid options given 51 | """ 52 | if max_operands < 1 or max_operands > 3: 53 | raise Exception("max_operands must be between 1 and 3") 54 | 55 | one_q_ops = [IGate, U1Gate, U2Gate, U3Gate, XGate, YGate, ZGate, 56 | HGate, SGate, SdgGate, TGate, TdgGate, RXGate, RYGate, RZGate] 57 | one_param = [U1Gate, RXGate, RYGate, RZGate, RZZGate, CU1Gate, CRZGate] 58 | two_param = [U2Gate] 59 | three_param = [U3Gate, CU3Gate] 60 | two_q_ops = [CXGate, CYGate, CZGate, CHGate, CRZGate, 61 | CYGate, CU3Gate, SwapGate, RZZGate] 62 | three_q_ops = [CCXGate, CSwapGate] 63 | 64 | qr = QuantumRegister(n_qubits, 'q') 65 | qc = QuantumCircuit(n_qubits) 66 | 67 | if measure or conditional: 68 | cr = ClassicalRegister(n_qubits, 'c') 69 | qc.add_register(cr) 70 | 71 | if reset: 72 | one_q_ops += [Reset] 73 | 74 | if seed is None: 75 | seed = np.random.randint(0, np.iinfo(np.int32).max) 76 | rng = np.random.RandomState(seed) 77 | 78 | # apply arbitrary random operations at every depth 79 | for _ in range(depth): 80 | # choose either 1, 2, or 3 qubits for the operation 81 | remaining_qubits = list(range(n_qubits)) 82 | while remaining_qubits: 83 | max_possible_operands = min(len(remaining_qubits), max_operands) 84 | num_operands = rng.choice(range(max_possible_operands)) + 1 85 | rng.shuffle(remaining_qubits) 86 | operands = remaining_qubits[:num_operands] 87 | remaining_qubits = [ 88 | q for q in remaining_qubits if q not in operands] 89 | if num_operands == 1: 90 | operation = rng.choice(one_q_ops) 91 | elif num_operands == 2: 92 | operation = rng.choice(two_q_ops) 93 | elif num_operands == 3: 94 | operation = rng.choice(three_q_ops) 95 | if operation in one_param: 96 | num_angles = 1 97 | elif operation in two_param: 98 | num_angles = 2 99 | elif operation in three_param: 100 | num_angles = 3 101 | else: 102 | num_angles = 0 103 | angles = [rng.uniform(0, 2*np.pi) for x in range(num_angles)] 104 | register_operands = [qr[i] for i in operands] 105 | op = operation(*angles) 106 | 107 | # with some low probability, condition on classical bit values 108 | if conditional and rng.choice(range(10)) == 0: 109 | value = rng.randint(0, np.power(2, n_qubits)) 110 | op.condition = (cr, value) 111 | 112 | qc.append(op, register_operands) 113 | 114 | if measure: 115 | qc.measure(qr, cr) 116 | 117 | return qc 118 | 119 | 120 | def build_qv_model_circuit(width, depth, seed=None): 121 | """ 122 | The model circuits consist of layers of Haar random 123 | elements of SU(4) applied between corresponding pairs 124 | of qubits in a random bipartition. 125 | """ 126 | np.random.seed(seed) 127 | circuit = QuantumCircuit(width) 128 | # For each layer 129 | for _ in range(depth): 130 | # Generate uniformly random permutation Pj of [0...n-1] 131 | perm = np.random.permutation(width) 132 | # For each pair p in Pj, generate Haar random SU(4) 133 | for k in range(int(np.floor(width/2))): 134 | U = random_unitary(4) 135 | pair = int(perm[2*k]), int(perm[2*k+1]) 136 | circuit.append(U, [pair[0], pair[1]]) 137 | return circuit 138 | 139 | 140 | def build_ripple_adder_circuit(size): 141 | """ 142 | Builds a ripple adder of a given size. 143 | """ 144 | n = size 145 | a = QuantumRegister(n, "a") 146 | b = QuantumRegister(n, "b") 147 | cin = QuantumRegister(1, "cin") 148 | cout = QuantumRegister(1, "cout") 149 | ans = ClassicalRegister(n+1, "ans") 150 | qc = QuantumCircuit(a, b, cin, cout, ans, name="rippleadd") 151 | 152 | def majority(p, a, b, c): 153 | """Majority gate.""" 154 | p.cx(c, b) 155 | p.cx(c, a) 156 | p.ccx(a, b, c) 157 | 158 | def unmajority(p, a, b, c): 159 | """Unmajoritygate.""" 160 | p.ccx(a, b, c) 161 | p.cx(c, a) 162 | p.cx(a, b) 163 | 164 | # Build a temporary subcircuitthat adds a to b, 165 | # storing the result in b 166 | adder_subcircuit = QuantumCircuit(cin, a, b, cout) 167 | majority(adder_subcircuit, cin[0], b[0], a[0]) 168 | for j in range(n - 1): 169 | majority(adder_subcircuit, a[j], b[j + 1], a[j + 1]) 170 | 171 | adder_subcircuit.cx(a[n - 1], cout[0]) 172 | 173 | for j in reversed(range(n - 1)): 174 | unmajority(adder_subcircuit, a[j], b[j + 1], a[j + 1]) 175 | unmajority(adder_subcircuit, cin[0], b[0], a[0]) 176 | 177 | # Set the inputs to the adder 178 | qc.x(a[0]) # Set input a = 0...0001 179 | qc.x(b) # Set input b = 1...1111 180 | # Apply the adder 181 | qc += adder_subcircuit 182 | 183 | # Measure the output register in the computational basis 184 | for j in range(n): 185 | qc.measure(b[j], ans[j]) 186 | qc.measure(cout[0], ans[n]) 187 | 188 | return qc 189 | -------------------------------------------------------------------------------- /test/benchmarks/quantum_info.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -* 2 | 3 | # This code is part of Qiskit. 4 | # 5 | # (C) Copyright IBM 2021. 6 | # 7 | # This code is licensed under the Apache License, Version 2.0. You may 8 | # obtain a copy of this license in the LICENSE.txt file in the root directory 9 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 10 | # 11 | # Any modifications or derivative works of this code must retain this 12 | # copyright notice, and modified files need to carry a notice indicating 13 | # that they have been altered from the originals. 14 | 15 | # pylint: disable=missing-docstring,invalid-name,no-member 16 | # pylint: disable=attribute-defined-outside-init 17 | 18 | import random 19 | 20 | import numpy as np 21 | 22 | from qiskit.quantum_info import random_clifford, Clifford, \ 23 | decompose_clifford, random_pauli, SparsePauliOp 24 | from qiskit.quantum_info.operators.symplectic.random import random_pauli_list 25 | from qiskit.quantum_info import random_cnotdihedral, CNOTDihedral 26 | 27 | 28 | class RandomCliffordBench: 29 | params = ['1,3000', '2,2500', '3,2000', '4,1500', '5,1000', '6,700'] 30 | param_names = ['nqubits,length'] 31 | 32 | def time_random_clifford(self, nqubits_length): 33 | (nqubits, length) = map(int, nqubits_length.split(',')) 34 | for _ in range(length): 35 | random_clifford(nqubits) 36 | 37 | 38 | class CliffordComposeBench: 39 | params = ['1,7000', '2,5000', '3,5000', '4,2500', '5,2000'] 40 | param_names = ['nqubits,length'] 41 | 42 | def setup(self, nqubits_length): 43 | (nqubits, length) = map(int, nqubits_length.split(',')) 44 | self.random_clifford = \ 45 | [random_clifford(nqubits) for _ in range(length)] 46 | 47 | def time_compose(self, nqubits_length): 48 | (nqubits, length) = map(int, nqubits_length.split(',')) 49 | clifford = Clifford(np.eye(2 * nqubits)) 50 | for i in range(length): 51 | clifford.compose(self.random_clifford[i]) 52 | 53 | 54 | class CliffordDecomposeBench: 55 | params = ['1,1000', '2,500', '3,100', '4,50', '5,10'] 56 | param_names = ['nqubits,length'] 57 | 58 | def setup(self, nqubits_length): 59 | (nqubits, length) = map(int, nqubits_length.split(',')) 60 | self.random_clifford = \ 61 | [random_clifford(nqubits) for _ in range(length)] 62 | 63 | def time_decompose(self, nqubits_length): 64 | length = int(nqubits_length.split(',')[1]) 65 | for i in range(length): 66 | decompose_clifford(self.random_clifford[i]) 67 | 68 | 69 | class RandomCnotDihedralBench: 70 | params = ['1,2000', '2,1500', '3,1200', '4,1000', '5,800', '6,700'] 71 | param_names = ['nqubits,length'] 72 | 73 | def time_random_cnotdihedral(self, nqubits_length): 74 | (nqubits, length) = map(int, nqubits_length.split(',')) 75 | for _ in range(length): 76 | random_cnotdihedral(nqubits) 77 | 78 | 79 | class CnotDihedralComposeBench: 80 | params = ['1,1500', '2,400', '3,100', '4,40', '5,10'] 81 | param_names = ['nqubits,length'] 82 | 83 | def setup(self, nqubits_length): 84 | (nqubits, length) = map(int, nqubits_length.split(',')) 85 | self.random_cnotdihedral = \ 86 | [random_cnotdihedral(nqubits) for _ in range(length)] 87 | 88 | def time_compose(self, nqubits_length): 89 | (nqubits, length) = map(int, nqubits_length.split(',')) 90 | cxdihedral = CNOTDihedral(num_qubits=nqubits) 91 | for i in range(length): 92 | cxdihedral.compose(self.random_cnotdihedral[i]) 93 | 94 | 95 | class PauliBench: 96 | params = [100, 200, 300, 400, 500] 97 | param_names = ["num_qubits"] 98 | 99 | def setup(self, num_qubits): 100 | self.p1 = random_pauli(num_qubits, True) 101 | self.p2 = random_pauli(num_qubits, True) 102 | 103 | def time_compose(self, _): 104 | self.p1.compose(self.p2) 105 | 106 | def time_evolve(self, _): 107 | self.p1.evolve(self.p2) # by another Pauli, so by composition 108 | 109 | def time_commutes(self, _): 110 | self.p1.commutes(self.p2) 111 | 112 | def time_to_instruction(self, _): 113 | self.p1.to_instruction() 114 | 115 | def time_to_label(self, _): 116 | self.p1.to_label() 117 | 118 | def time_evolve_by_clifford(self, num_qubits): 119 | c1 = random_clifford(num_qubits) 120 | 121 | self.p1.evolve(c1) 122 | time_evolve_by_clifford.params = [10] 123 | 124 | 125 | class PauliListBench: 126 | params = [[100, 200, 300, 400, 500], [500]] 127 | param_names = ["num_qubits", "length"] 128 | 129 | def setup(self, num_qubits, length): 130 | self.pl1 = random_pauli_list(num_qubits=num_qubits, size=length, 131 | phase=True) 132 | self.pl2 = random_pauli_list(num_qubits=num_qubits, size=length, 133 | phase=True) 134 | 135 | def time_commutes(self, _, __): 136 | self.pl1.commutes(self.pl2) 137 | 138 | def time_commutes_with_all(self, _, __): 139 | self.pl1.commutes_with_all(self.pl2) 140 | 141 | def time_argsort(self, _, __): 142 | self.pl1.argsort() 143 | 144 | def time_compose(self, _, __): 145 | self.pl1.compose(self.pl2) 146 | 147 | def time_group_qubit_wise_commuting(self, _, __): 148 | self.pl1.group_qubit_wise_commuting() # exercise retworkx-based code 149 | 150 | def time_evolve_by_clifford(self, num_qubits, __): 151 | c1 = random_clifford(num_qubits) 152 | self.pl1.evolve(c1) 153 | time_evolve_by_clifford.params = [[20], [100]] 154 | 155 | 156 | class PauliListQargsBench: 157 | params = [[100, 200, 300, 400, 500], [500]] 158 | param_names = ["num_qubits", "length"] 159 | 160 | def setup(self, num_qubits, length): 161 | half_qubits = int(num_qubits/2) 162 | 163 | self.pl1 = random_pauli_list(num_qubits=num_qubits, size=length, 164 | phase=True) 165 | self.pl2 = random_pauli_list(num_qubits=half_qubits, size=length, 166 | phase=True) 167 | self.qargs = [random.randint(0, num_qubits - 1) 168 | for _ in range(half_qubits)] 169 | 170 | def time_commutes_with_qargs(self, _, __): 171 | self.pl1.commutes(self.pl2, self.qargs) 172 | 173 | def time_compose_with_qargs(self, _, __): 174 | self.pl1.compose(self.pl2, self.qargs) 175 | 176 | 177 | class SparsePauliOpBench: 178 | params = [[50, 100, 150, 200], [100]] 179 | param_names = ["num_qubits", "length"] 180 | 181 | def setup(self, num_qubits, length): 182 | self.p1 = SparsePauliOp( 183 | random_pauli_list(num_qubits=num_qubits, size=length, phase=True)) 184 | self.p2 = SparsePauliOp( 185 | random_pauli_list(num_qubits=num_qubits, size=length, phase=True)) 186 | 187 | def time_compose(self, _, __): 188 | self.p1.compose(self.p2) 189 | 190 | def time_simplify(self, _, __): 191 | self.p1.simplify() 192 | 193 | def time_tensor(self, _, __): 194 | self.p1.tensor(self.p2) 195 | 196 | def time_add(self, _, __): 197 | _ = self.p1 + self.p2 198 | time_add.params = [[50, 100, 150, 200], [10000]] 199 | 200 | def time_to_list(self, _, __): 201 | self.p1.to_list() 202 | time_to_list.params = [[2, 4, 6, 8, 10], [50]] 203 | 204 | def time_to_operator(self, _, __): 205 | self.p1.to_operator() 206 | time_to_operator.params = [[2, 4, 6, 8, 10], [50]] 207 | 208 | def time_to_matrix(self, _, __): 209 | self.p1.to_matrix() 210 | time_to_matrix.params = [[2, 4, 6, 8, 10], [50]] 211 | -------------------------------------------------------------------------------- /test/benchmarks/transpiler_levels.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # This code is part of Qiskit. 4 | # 5 | # (C) Copyright IBM 2019. 6 | # 7 | # This code is licensed under the Apache License, Version 2.0. You may 8 | # obtain a copy of this license in the LICENSE.txt file in the root directory 9 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 10 | # 11 | # Any modifications or derivative works of this code must retain this 12 | # copyright notice, and modified files need to carry a notice indicating 13 | # that they have been altered from the originals. 14 | 15 | # pylint: disable=no-member,invalid-name,missing-docstring,no-name-in-module 16 | # pylint: disable=attribute-defined-outside-init,unsubscriptable-object 17 | 18 | import os 19 | 20 | from qiskit.compiler import transpile 21 | from qiskit import QuantumCircuit 22 | from qiskit.transpiler import InstructionDurations 23 | from qiskit.providers.fake_provider import FakeMelbourne 24 | 25 | from .utils import build_qv_model_circuit 26 | 27 | 28 | class TranspilerLevelBenchmarks: 29 | params = [0, 1, 2, 3] 30 | param_names = ['transpiler optimization level'] 31 | timeout = 600 32 | 33 | def setup(self, _): 34 | self.rochester_coupling_map = [ 35 | [0, 5], 36 | [0, 1], 37 | [1, 2], 38 | [1, 0], 39 | [2, 3], 40 | [2, 1], 41 | [3, 4], 42 | [3, 2], 43 | [4, 6], 44 | [4, 3], 45 | [5, 9], 46 | [5, 0], 47 | [6, 13], 48 | [6, 4], 49 | [7, 16], 50 | [7, 8], 51 | [8, 9], 52 | [8, 7], 53 | [9, 10], 54 | [9, 8], 55 | [9, 5], 56 | [10, 11], 57 | [10, 9], 58 | [11, 17], 59 | [11, 12], 60 | [11, 10], 61 | [12, 13], 62 | [12, 11], 63 | [13, 14], 64 | [13, 12], 65 | [13, 6], 66 | [14, 15], 67 | [14, 13], 68 | [15, 18], 69 | [15, 14], 70 | [16, 19], 71 | [16, 7], 72 | [17, 23], 73 | [17, 11], 74 | [18, 27], 75 | [18, 15], 76 | [19, 20], 77 | [19, 16], 78 | [20, 21], 79 | [20, 19], 80 | [21, 28], 81 | [21, 22], 82 | [21, 20], 83 | [22, 23], 84 | [22, 21], 85 | [23, 24], 86 | [23, 22], 87 | [23, 17], 88 | [24, 25], 89 | [24, 23], 90 | [25, 29], 91 | [25, 26], 92 | [25, 24], 93 | [26, 27], 94 | [26, 25], 95 | [27, 26], 96 | [27, 18], 97 | [28, 32], 98 | [28, 21], 99 | [29, 36], 100 | [29, 25], 101 | [30, 39], 102 | [30, 31], 103 | [31, 32], 104 | [31, 30], 105 | [32, 33], 106 | [32, 31], 107 | [32, 28], 108 | [33, 34], 109 | [33, 32], 110 | [34, 40], 111 | [34, 35], 112 | [34, 33], 113 | [35, 36], 114 | [35, 34], 115 | [36, 37], 116 | [36, 35], 117 | [36, 29], 118 | [37, 38], 119 | [37, 36], 120 | [38, 41], 121 | [38, 37], 122 | [39, 42], 123 | [39, 30], 124 | [40, 46], 125 | [40, 34], 126 | [41, 50], 127 | [41, 38], 128 | [42, 43], 129 | [42, 39], 130 | [43, 44], 131 | [43, 42], 132 | [44, 51], 133 | [44, 45], 134 | [44, 43], 135 | [45, 46], 136 | [45, 44], 137 | [46, 47], 138 | [46, 45], 139 | [46, 40], 140 | [47, 48], 141 | [47, 46], 142 | [48, 52], 143 | [48, 49], 144 | [48, 47], 145 | [49, 50], 146 | [49, 48], 147 | [50, 49], 148 | [50, 41], 149 | [51, 44], 150 | [52, 48]] 151 | self.basis_gates = ['u1', 'u2', 'u3', 'cx', 'id'] 152 | self.qv_50_x_20 = build_qv_model_circuit(50, 20, 0) 153 | self.qv_14_x_14 = build_qv_model_circuit(14, 14, 0) 154 | self.qasm_path = os.path.abspath( 155 | os.path.join(os.path.dirname(__file__), 'qasm')) 156 | large_qasm_path = os.path.join(self.qasm_path, 'test_eoh_qasm.qasm') 157 | self.large_qasm = QuantumCircuit.from_qasm_file(large_qasm_path) 158 | self.melbourne = FakeMelbourne() 159 | self.durations = InstructionDurations([ 160 | ("u1", None, 0), 161 | ("id", None, 160), 162 | ("u2", None, 160), 163 | ("u3", None, 320), 164 | ("cx", None, 800), 165 | ("measure", None, 3200), 166 | ], dt=1e-9) 167 | 168 | def time_quantum_volume_transpile_50_x_20(self, transpiler_level): 169 | transpile(self.qv_50_x_20, basis_gates=self.basis_gates, 170 | coupling_map=self.rochester_coupling_map, 171 | seed_transpiler=0, 172 | optimization_level=transpiler_level) 173 | 174 | def track_depth_quantum_volume_transpile_50_x_20(self, transpiler_level): 175 | return transpile(self.qv_50_x_20, basis_gates=self.basis_gates, 176 | coupling_map=self.rochester_coupling_map, 177 | seed_transpiler=0, 178 | optimization_level=transpiler_level).depth() 179 | 180 | def time_transpile_from_large_qasm(self, transpiler_level): 181 | transpile(self.large_qasm, basis_gates=self.basis_gates, 182 | coupling_map=self.rochester_coupling_map, 183 | seed_transpiler=0, 184 | optimization_level=transpiler_level) 185 | 186 | def track_depth_transpile_from_large_qasm(self, transpiler_level): 187 | return transpile(self.large_qasm, basis_gates=self.basis_gates, 188 | coupling_map=self.rochester_coupling_map, 189 | seed_transpiler=0, 190 | optimization_level=transpiler_level).depth() 191 | 192 | def time_transpile_from_large_qasm_backend_with_prop(self, 193 | transpiler_level): 194 | transpile(self.large_qasm, self.melbourne, seed_transpiler=0, 195 | optimization_level=transpiler_level) 196 | 197 | def track_depth_transpile_from_large_qasm_backend_with_prop( 198 | self, transpiler_level): 199 | return transpile(self.large_qasm, self.melbourne, seed_transpiler=0, 200 | optimization_level=transpiler_level).depth() 201 | 202 | def time_transpile_qv_14_x_14(self, transpiler_level): 203 | transpile(self.qv_14_x_14, self.melbourne, seed_transpiler=0, 204 | optimization_level=transpiler_level) 205 | 206 | def track_depth_transpile_qv_14_x_14(self, transpiler_level): 207 | return transpile(self.qv_14_x_14, self.melbourne, seed_transpiler=0, 208 | optimization_level=transpiler_level).depth() 209 | 210 | def time_schedule_qv_14_x_14(self, transpiler_level): 211 | transpile(self.qv_14_x_14, self.melbourne, seed_transpiler=0, 212 | optimization_level=transpiler_level, 213 | scheduling_method="alap", 214 | instruction_durations=self.durations) 215 | 216 | # limit optimization levels to reduce time 217 | time_schedule_qv_14_x_14.params = [0, 1] 218 | -------------------------------------------------------------------------------- /test/benchmarks/passes.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # This code is part of Qiskit. 4 | # 5 | # (C) Copyright IBM 2019. 6 | # 7 | # This code is licensed under the Apache License, Version 2.0. You may 8 | # obtain a copy of this license in the LICENSE.txt file in the root directory 9 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 10 | # 11 | # Any modifications or derivative works of this code must retain this 12 | # copyright notice, and modified files need to carry a notice indicating 13 | # that they have been altered from the originals. 14 | 15 | # pylint: disable=no-member,invalid-name,missing-docstring,no-name-in-module 16 | # pylint: disable=attribute-defined-outside-init,unsubscriptable-object 17 | # pylint: disable=unused-wildcard-import,wildcard-import,undefined-variable 18 | 19 | 20 | from qiskit.circuit.equivalence_library import SessionEquivalenceLibrary as SEL 21 | from qiskit.transpiler.passes import * 22 | from qiskit.converters import circuit_to_dag 23 | 24 | from .utils import random_circuit 25 | 26 | 27 | class Collect2QPassBenchmarks: 28 | params = ([5, 14, 20], 29 | [1024]) 30 | 31 | param_names = ['n_qubits', 'depth'] 32 | timeout = 300 33 | 34 | def setup(self, n_qubits, depth): 35 | seed = 42 36 | self.circuit = random_circuit(n_qubits, depth, measure=True, 37 | conditional=True, reset=True, seed=seed) 38 | self.dag = circuit_to_dag(self.circuit) 39 | collect_blocks = Collect2qBlocks() 40 | collect_blocks.run(self.dag) 41 | self.block_list = collect_blocks.property_set['block_list'] 42 | 43 | def time_consolidate_blocks(self, _, __): 44 | _pass = ConsolidateBlocks() 45 | _pass.property_set['block_list'] = self.block_list 46 | _pass.run(self.dag) 47 | 48 | 49 | class CommutativeAnalysisPassBenchmarks: 50 | params = ([5, 14, 20], 51 | [1024]) 52 | 53 | param_names = ['n_qubits', 'depth'] 54 | timeout = 300 55 | 56 | def setup(self, n_qubits, depth): 57 | seed = 42 58 | self.circuit = random_circuit(n_qubits, depth, measure=True, 59 | conditional=True, reset=True, seed=seed) 60 | self.dag = circuit_to_dag(self.circuit) 61 | commutative_analysis = CommutationAnalysis() 62 | commutative_analysis.run( 63 | self.dag) 64 | self.commutation_set = commutative_analysis.property_set[ 65 | 'commutation_set'] 66 | 67 | def time_commutative_cancellation(self, _, __): 68 | _pass = CommutativeCancellation() 69 | _pass.property_set['commutation_set'] = self.commutation_set 70 | _pass.run(self.dag) 71 | 72 | 73 | class UnrolledPassBenchmarks: 74 | params = ([5, 14, 20], 75 | [1024]) 76 | 77 | param_names = ['n_qubits', 'depth'] 78 | timeout = 300 79 | 80 | def setup(self, n_qubits, depth): 81 | seed = 42 82 | self.circuit = random_circuit(n_qubits, depth, measure=True, 83 | conditional=True, reset=True, seed=seed) 84 | self.dag = circuit_to_dag(self.circuit) 85 | self.basis_gates = ['u1', 'u2', 'u3', 'cx', 'id'] 86 | self.unrolled_dag = Unroller(self.basis_gates).run(self.dag) 87 | 88 | def time_optimize_1q(self, _, __): 89 | Optimize1qGates().run(self.unrolled_dag) 90 | 91 | 92 | class MultipleBasisPassBenchmarks: 93 | params = ([5, 14, 20], 94 | [1024], 95 | [['u', 'cx', 'id'], ['rx', 'ry', 'rz', 'r', 'rxx', 'id'], 96 | ['rz', 'x', 'sx', 'cx', 'id']]) 97 | 98 | param_names = ['n_qubits', 'depth', 'basis_gates'] 99 | timeout = 300 100 | 101 | def setup(self, n_qubits, depth, basis_gates): 102 | seed = 42 103 | self.circuit = random_circuit(n_qubits, depth, measure=True, seed=seed) 104 | self.dag = circuit_to_dag(self.circuit) 105 | self.basis_gates = basis_gates 106 | 107 | def time_optimize_1q_decompose(self, _, __, ___): 108 | Optimize1qGatesDecomposition(self.basis_gates).run(self.dag) 109 | 110 | def time_optimize_1q_commutation(self, _, __, ___): 111 | Optimize1qGatesSimpleCommutation(self.basis_gates).run(self.dag) 112 | 113 | def time_basis_translator(self, _, __, ___): 114 | BasisTranslator(SEL, self.basis_gates).run(self.dag) 115 | 116 | 117 | class PassBenchmarks: 118 | params = ([5, 14, 20], 119 | [1024]) 120 | 121 | param_names = ['n_qubits', 'depth'] 122 | timeout = 300 123 | 124 | def setup(self, n_qubits, depth): 125 | seed = 42 126 | self.circuit = random_circuit(n_qubits, depth, measure=True, 127 | conditional=True, reset=True, seed=seed) 128 | self.dag = circuit_to_dag(self.circuit) 129 | self.basis_gates = ['u1', 'u2', 'u3', 'cx', 'id'] 130 | 131 | def time_unroller(self, _, __): 132 | Unroller(self.basis_gates).run(self.dag) 133 | 134 | def time_depth_pass(self, _, __): 135 | Depth().run(self.dag) 136 | 137 | def time_size_pass(self, _, __): 138 | Size().run(self.dag) 139 | 140 | def time_width_pass(self, _, __): 141 | Width().run(self.dag) 142 | 143 | def time_count_ops_pass(self, _, __): 144 | CountOps().run(self.dag) 145 | 146 | def time_count_ops_longest_path(self, _, __): 147 | CountOpsLongestPath().run(self.dag) 148 | 149 | def time_num_tensor_factors(self, _, __): 150 | NumTensorFactors().run(self.dag) 151 | 152 | def time_resource_optimization(self, _, __): 153 | ResourceEstimation().run(self.dag) 154 | 155 | def time_cx_cancellation(self, _, __): 156 | CXCancellation().run(self.dag) 157 | 158 | def time_dag_longest_path(self, _, __): 159 | DAGLongestPath().run(self.dag) 160 | 161 | def time_merge_adjacent_barriers(self, _, __): 162 | MergeAdjacentBarriers().run(self.dag) 163 | 164 | def time_decompose_pass(self, _, __): 165 | Decompose().run(self.dag) 166 | 167 | def time_unroll_3q_or_more(self, _, __): 168 | Unroll3qOrMore().run(self.dag) 169 | 170 | def time_commutation_analysis(self, _, __): 171 | CommutationAnalysis().run(self.dag) 172 | 173 | def time_remove_reset_in_zero_state(self, _, __): 174 | RemoveResetInZeroState().run(self.dag) 175 | 176 | def time_collect_2q_blocks(self, _, __): 177 | Collect2qBlocks().run(self.dag) 178 | 179 | def time_optimize_swap_before_measure(self, _, __): 180 | OptimizeSwapBeforeMeasure().run(self.dag) 181 | 182 | def time_barrier_before_final_measurements(self, _, __): 183 | BarrierBeforeFinalMeasurements().run(self.dag) 184 | 185 | def time_remove_diagonal_gates_before_measurement(self, _, __): 186 | RemoveDiagonalGatesBeforeMeasure().run(self.dag) 187 | 188 | def time_remove_final_measurements(self, _, __): 189 | RemoveFinalMeasurements().run(self.dag) 190 | 191 | def time_contains_instruction(self, _, __): 192 | ContainsInstruction('cx').run(self.dag) 193 | 194 | def time_gates_in_basis(self, _, __): 195 | GatesInBasis(self.basis_gates).run(self.dag) 196 | 197 | def time_remove_barriers(self, _, __): 198 | RemoveBarriers().run(self.dag) 199 | 200 | 201 | class MultiQBlockPassBenchmarks: 202 | params = ([5, 14, 20], 203 | [1024], [1, 2, 3, 4, 5]) 204 | 205 | param_names = ['n_qubits', 'depth', 'max_block_size'] 206 | timeout = 300 207 | 208 | def setup(self, n_qubits, depth, _): 209 | seed = 42 210 | self.circuit = random_circuit(n_qubits, depth, measure=True, 211 | conditional=True, reset=True, seed=seed) 212 | self.dag = circuit_to_dag(self.circuit) 213 | 214 | def time_collect_multiq_block(self, _, __, max_block_size): 215 | CollectMultiQBlocks(max_block_size).run(self.dag) 216 | -------------------------------------------------------------------------------- /test/benchmarks/mapping_passes.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # This code is part of Qiskit. 4 | # 5 | # (C) Copyright IBM 2019. 6 | # 7 | # This code is licensed under the Apache License, Version 2.0. You may 8 | # obtain a copy of this license in the LICENSE.txt file in the root directory 9 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 10 | # 11 | # Any modifications or derivative works of this code must retain this 12 | # copyright notice, and modified files need to carry a notice indicating 13 | # that they have been altered from the originals. 14 | 15 | # pylint: disable=no-member,invalid-name,missing-docstring,no-name-in-module 16 | # pylint: disable=attribute-defined-outside-init,unsubscriptable-object 17 | # pylint: disable=unused-wildcard-import,wildcard-import,undefined-variable 18 | 19 | from qiskit.transpiler import CouplingMap 20 | from qiskit.transpiler.passes import * 21 | from qiskit.converters import circuit_to_dag 22 | from qiskit.providers.fake_provider import FakeSingapore 23 | 24 | from .utils import random_circuit 25 | 26 | 27 | class PassBenchmarks: 28 | 29 | params = ([5, 14, 20], 30 | [1024]) 31 | 32 | param_names = ['n_qubits', 'depth'] 33 | timeout = 300 34 | 35 | def setup(self, n_qubits, depth): 36 | seed = 42 37 | self.circuit = random_circuit(n_qubits, depth, measure=True, 38 | conditional=True, reset=True, seed=seed, 39 | max_operands=2) 40 | self.fresh_dag = circuit_to_dag(self.circuit) 41 | self.basis_gates = ['u1', 'u2', 'u3', 'cx', 'iid'] 42 | self.cmap = [[0, 1], [1, 0], [1, 2], [1, 6], [2, 1], [2, 3], [3, 2], 43 | [3, 4], [3, 8], [4, 3], [5, 6], [5, 10], [6, 1], [6, 5], 44 | [6, 7], [7, 6], [7, 8], [7, 12], [8, 3], [8, 7], [8, 9], 45 | [9, 8], [9, 14], [10, 5], [10, 11], [11, 10], [11, 12], 46 | [11, 16], [12, 7], [12, 11], [12, 13], [13, 12], [13, 14], 47 | [13, 18], [14, 9], [14, 13], [15, 16], [16, 11], [16, 15], 48 | [16, 17], [17, 16], [17, 18], [18, 13], [18, 17], 49 | [18, 19], [19, 18]] 50 | self.coupling_map = CouplingMap(self.cmap) 51 | 52 | layout_pass = DenseLayout(self.coupling_map) 53 | layout_pass.run(self.fresh_dag) 54 | self.layout = layout_pass.property_set['layout'] 55 | full_ancilla_pass = FullAncillaAllocation(self.coupling_map) 56 | full_ancilla_pass.property_set['layout'] = self.layout 57 | self.full_ancilla_dag = full_ancilla_pass.run(self.fresh_dag) 58 | enlarge_pass = EnlargeWithAncilla() 59 | enlarge_pass.property_set['layout'] = self.layout 60 | self.enlarge_dag = enlarge_pass.run(self.full_ancilla_dag) 61 | apply_pass = ApplyLayout() 62 | apply_pass.property_set['layout'] = self.layout 63 | self.dag = apply_pass.run(self.enlarge_dag) 64 | self.backend_props = FakeSingapore().properties() 65 | 66 | def time_stochastic_swap(self, _, __): 67 | swap = StochasticSwap(self.coupling_map, seed=42) 68 | swap.property_set['layout'] = self.layout 69 | swap.run(self.dag) 70 | 71 | def time_sabre_swap(self, _, __): 72 | swap = SabreSwap(self.coupling_map, seed=42) 73 | swap.property_set['layout'] = self.layout 74 | swap.run(self.dag) 75 | 76 | def time_basic_swap(self, _, __): 77 | swap = BasicSwap(self.coupling_map) 78 | swap.property_set['layout'] = self.layout 79 | swap.run(self.dag) 80 | 81 | def time_csp_layout(self, _, __): 82 | CSPLayout(self.coupling_map, seed=42).run(self.fresh_dag) 83 | 84 | def time_dense_layout(self, _, __): 85 | DenseLayout(self.coupling_map).run(self.fresh_dag) 86 | 87 | def time_layout_2q_distance(self, _, __): 88 | layout = Layout2qDistance(self.coupling_map) 89 | layout.property_set['layout'] = self.layout 90 | layout.run(self.dag) 91 | 92 | def time_apply_layout(self, _, __): 93 | layout = ApplyLayout() 94 | layout.property_set['layout'] = self.layout 95 | layout.run(self.dag) 96 | 97 | def time_full_ancilla_allocation(self, _, __): 98 | ancilla = FullAncillaAllocation(self.coupling_map) 99 | ancilla.property_set['layout'] = self.layout 100 | ancilla.run(self.fresh_dag) 101 | 102 | def time_enlarge_with_ancilla(self, _, __): 103 | ancilla = EnlargeWithAncilla() 104 | ancilla.property_set['layout'] = self.layout 105 | ancilla.run(self.full_ancilla_dag) 106 | 107 | def time_check_map(self, _, __): 108 | CheckMap(self.coupling_map).run(self.dag) 109 | 110 | def time_trivial_layout(self, _, __): 111 | TrivialLayout(self.coupling_map).run(self.fresh_dag) 112 | 113 | def time_set_layout(self, _, __): 114 | SetLayout(self.layout).run(self.fresh_dag) 115 | 116 | def time_noise_adaptive_layout(self, _, __): 117 | NoiseAdaptiveLayout(self.backend_props).run(self.fresh_dag) 118 | 119 | def time_sabre_layout(self, _, __): 120 | SabreLayout(self.coupling_map, seed=42).run(self.fresh_dag) 121 | 122 | 123 | class RoutedPassBenchmarks: 124 | params = ([5, 14, 20], 125 | [1024]) 126 | 127 | param_names = ['n_qubits', 'depth'] 128 | timeout = 300 129 | 130 | def setup(self, n_qubits, depth): 131 | seed = 42 132 | self.circuit = random_circuit(n_qubits, depth, measure=True, 133 | conditional=True, reset=True, seed=seed, 134 | max_operands=2) 135 | self.fresh_dag = circuit_to_dag(self.circuit) 136 | self.basis_gates = ['u1', 'u2', 'u3', 'cx', 'iid'] 137 | self.cmap = [[0, 1], [1, 0], [1, 2], [1, 6], [2, 1], [2, 3], [3, 2], 138 | [3, 4], [3, 8], [4, 3], [5, 6], [5, 10], [6, 1], [6, 5], 139 | [6, 7], [7, 6], [7, 8], [7, 12], [8, 3], [8, 7], [8, 9], 140 | [9, 8], [9, 14], [10, 5], [10, 11], [11, 10], [11, 12], 141 | [11, 16], [12, 7], [12, 11], [12, 13], [13, 12], [13, 14], 142 | [13, 18], [14, 9], [14, 13], [15, 16], [16, 11], [16, 15], 143 | [16, 17], [17, 16], [17, 18], [18, 13], [18, 17], 144 | [18, 19], [19, 18]] 145 | self.coupling_map = CouplingMap(self.cmap) 146 | 147 | layout_pass = DenseLayout(self.coupling_map) 148 | layout_pass.run(self.fresh_dag) 149 | self.layout = layout_pass.property_set['layout'] 150 | full_ancilla_pass = FullAncillaAllocation(self.coupling_map) 151 | full_ancilla_pass.property_set['layout'] = self.layout 152 | self.full_ancilla_dag = full_ancilla_pass.run(self.fresh_dag) 153 | enlarge_pass = EnlargeWithAncilla() 154 | enlarge_pass.property_set['layout'] = self.layout 155 | self.enlarge_dag = enlarge_pass.run(self.full_ancilla_dag) 156 | apply_pass = ApplyLayout() 157 | apply_pass.property_set['layout'] = self.layout 158 | self.dag = apply_pass.run(self.enlarge_dag) 159 | self.backend_props = FakeSingapore().properties() 160 | self.routed_dag = StochasticSwap(self.coupling_map, 161 | seed=42).run(self.dag) 162 | 163 | def time_cxdirection(self, _, __): 164 | CXDirection(self.coupling_map).run(self.routed_dag) 165 | 166 | def time_check_cx_direction(self, _, __): 167 | CheckCXDirection(self.coupling_map).run(self.routed_dag) 168 | 169 | def time_gate_direction(self, _, __): 170 | GateDirection(self.coupling_map).run(self.routed_dag) 171 | 172 | def time_check_gate_direction(self, _, __): 173 | CheckGateDirection(self.coupling_map).run(self.routed_dag) 174 | 175 | def time_check_map(self, _, __): 176 | CheckMap(self.coupling_map).run(self.routed_dag) 177 | -------------------------------------------------------------------------------- /asv.conf.json: -------------------------------------------------------------------------------- 1 | { 2 | // The version of the config file format. Do not change, unless 3 | // you know what you are doing. 4 | "version": 1, 5 | 6 | // The name of the project being benchmarked 7 | "project": "qiskit-terra", 8 | 9 | // The project's homepage 10 | "project_url": "https://qiskit.org", 11 | 12 | // The URL or local path of the source code repository for the 13 | // project being benchmarked 14 | "repo": "https://github.com/Qiskit/qiskit-terra.git", 15 | 16 | // The Python project's subdirectory in your repo. If missing or 17 | // the empty string, the project is assumed to be located at the root 18 | // of the repository. 19 | // "repo_subdir": "", 20 | 21 | // Customizable commands for building, installing, and 22 | // uninstalling the project. See asv.conf.json documentation. 23 | // 24 | "install_command": [ 25 | "return-code=any python -c \"import shutil; shutil.rmtree('{build_dir}/build')\"", 26 | "return-code=any python -c \"import shutil; shutil.rmtree('{build_dir}/qiskit_terra.egg-info')\"", 27 | "python -mpip install seaborn", 28 | "python -mpip install pygments", 29 | "python -mpip install {wheel_file}", 30 | "python -mpip install -U qiskit-experiments==0.3.0", 31 | "python -mpip install -U python-constraint" 32 | ], 33 | "uninstall_command": [ 34 | "return-code=any python -mpip uninstall -y {project}", 35 | "return-code=any python -mpip uninstall -y qiskit-experiments" 36 | ], 37 | "build_command": [ 38 | "pip install -U Cython setuptools-rust", 39 | "python setup.py build_rust --release", 40 | "PIP_NO_BUILD_ISOLATION=false python -mpip wheel --no-deps --no-index -w {build_cache_dir} {build_dir}" 41 | ], 42 | 43 | // List of branches to benchmark. If not provided, defaults to "master" 44 | // (for git) or "default" (for mercurial). 45 | "branches": ["main"], // for git 46 | // "branches": ["default"], // for mercurial 47 | 48 | // The DVCS being used. If not set, it will be automatically 49 | // determined from "repo" by looking at the protocol in the URL 50 | // (if remote), or by looking for special directories, such as 51 | // ".git" (if local). 52 | "dvcs": "git", 53 | 54 | // The tool to use to create environments. May be "conda", 55 | // "virtualenv" or other value depending on the plugins in use. 56 | // If missing or the empty string, the tool will be automatically 57 | // determined by looking for tools on the PATH environment 58 | // variable. 59 | "environment_type": "virtualenv", 60 | 61 | // timeout in seconds for installing any dependencies in environment 62 | // defaults to 10 min 63 | //"install_timeout": 600, 64 | 65 | // the base URL to show a commit for the project. 66 | "show_commit_url": "http://github.com/Qiskit/qiskit-terra/commit/", 67 | 68 | // The Pythons you'd like to test against. If not provided, defaults 69 | // to the current version of Python used to run `asv`. 70 | "pythons": ["3.7", "3.8", "3.9", "3.10"], 71 | 72 | // The list of conda channel names to be searched for benchmark 73 | // dependency packages in the specified order 74 | // "conda_channels": ["conda-forge", "defaults"] 75 | 76 | // The matrix of dependencies to test. Each key is the name of a 77 | // package (in PyPI) and the values are version numbers. An empty 78 | // list or empty string indicates to just test against the default 79 | // (latest) version. null indicates that the package is to not be 80 | // installed. If the package to be tested is only available from 81 | // PyPi, and the 'environment_type' is conda, then you can preface 82 | // the package name by 'pip+', and the package will be installed via 83 | // pip (with all the conda available packages installed first, 84 | // followed by the pip installed packages). 85 | // 86 | // "matrix": { 87 | // "numpy": ["1.6", "1.7"], 88 | // "six": ["", null], // test with and without six installed 89 | // "pip+emcee": [""], // emcee is only available for install with pip. 90 | // }, 91 | 92 | // Combinations of libraries/python versions can be excluded/included 93 | // from the set to test. Each entry is a dictionary containing additional 94 | // key-value pairs to include/exclude. 95 | // 96 | // An exclude entry excludes entries where all values match. The 97 | // values are regexps that should match the whole string. 98 | // 99 | // An include entry adds an environment. Only the packages listed 100 | // are installed. The 'python' key is required. The exclude rules 101 | // do not apply to includes. 102 | // 103 | // In addition to package names, the following keys are available: 104 | // 105 | // - python 106 | // Python version, as in the *pythons* variable above. 107 | // - environment_type 108 | // Environment type, as above. 109 | // - sys_platform 110 | // Platform, as in sys.platform. Possible values for the common 111 | // cases: 'linux2', 'win32', 'cygwin', 'darwin'. 112 | // 113 | // "exclude": [ 114 | // {"python": "3.2", "sys_platform": "win32"}, // skip py3.2 on windows 115 | // {"environment_type": "conda", "six": null}, // don't run without six on conda 116 | // ], 117 | // 118 | // "include": [ 119 | // // additional env for python2.7 120 | // {"python": "2.7", "numpy": "1.8"}, 121 | // // additional env if run on windows+conda 122 | // {"platform": "win32", "environment_type": "conda", "python": "2.7", "libpython": ""}, 123 | // ], 124 | 125 | // The directory (relative to the current directory) that benchmarks are 126 | // stored in. If not provided, defaults to "benchmarks" 127 | "benchmark_dir": "test/benchmarks", 128 | 129 | // The directory (relative to the current directory) to cache the Python 130 | // environments in. If not provided, defaults to "env" 131 | "env_dir": ".asv/env", 132 | 133 | // The directory (relative to the current directory) that raw benchmark 134 | // results are stored in. If not provided, defaults to "results". 135 | "results_dir": ".asv/results", 136 | 137 | // The directory (relative to the current directory) that the html tree 138 | // should be written to. If not provided, defaults to "html". 139 | // "html_dir": "html", 140 | 141 | // The number of characters to retain in the commit hashes. 142 | // "hash_length": 8, 143 | 144 | // `asv` will cache results of the recent builds in each 145 | // environment, making them faster to install next time. This is 146 | // the number of builds to keep, per environment. 147 | // "build_cache_size": 2, 148 | 149 | // The commits after which the regression search in `asv publish` 150 | // should start looking for regressions. Dictionary whose keys are 151 | // regexps matching to benchmark names, and values corresponding to 152 | // the commit (exclusive) after which to start looking for 153 | // regressions. The default is to start from the first commit 154 | // with results. If the commit is `null`, regression detection is 155 | // skipped for the matching benchmark. 156 | // 157 | // "regressions_first_commits": { 158 | // "some_benchmark": "352cdf", // Consider regressions only after this commit 159 | // "another_benchmark": null, // Skip regression detection altogether 160 | // }, 161 | 162 | // The thresholds for relative change in results, after which `asv 163 | // publish` starts reporting regressions. Dictionary of the same 164 | // form as in ``regressions_first_commits``, with values 165 | // indicating the thresholds. If multiple entries match, the 166 | // maximum is taken. If no entry matches, the default is 5%. 167 | // 168 | // "regressions_thresholds": { 169 | // "some_benchmark": 0.01, // Threshold of 1% 170 | // "another_benchmark": 0.5, // Threshold of 50% 171 | // }, 172 | } 173 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # This code is part of Qiskit. 2 | # 3 | # (C) Copyright IBM 2018. 4 | # 5 | # This code is licensed under the Apache License, Version 2.0. You may 6 | # obtain a copy of this license in the LICENSE.txt file in the root directory 7 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # Any modifications or derivative works of this code must retain this 10 | # copyright notice, and modified files need to carry a notice indicating 11 | # that they have been altered from the originals. 12 | 13 | # Configuration file for the Sphinx documentation builder. 14 | # 15 | # This file does only contain a selection of the most common options. For a 16 | # full list see the documentation: 17 | # http://www.sphinx-doc.org/en/master/config 18 | 19 | import datetime 20 | import os 21 | import sys 22 | 23 | import sphinx.ext.doctest 24 | 25 | sys.path.insert(0, os.path.abspath(".")) 26 | 27 | import custom_extensions 28 | 29 | # -- General configuration --------------------------------------------------- 30 | 31 | project = "Qiskit" 32 | copyright = f"2017-{datetime.date.today().year}, Qiskit Development Team" 33 | author = "Qiskit Development Team" 34 | 35 | # The short X.Y version 36 | version = "" 37 | # The full version, including alpha/beta/rc tags 38 | release = "0.44.0" 39 | 40 | docs_url_prefix = "documentation" # i.e., www.qiskit.org/documentation/ 41 | 42 | rst_prolog = """ 43 | .. |version| replace:: {0} 44 | """.format( 45 | release 46 | ) 47 | 48 | extensions = [ 49 | "sphinx.ext.napoleon", 50 | "sphinx.ext.autodoc", 51 | "sphinx.ext.autosummary", 52 | "sphinx.ext.mathjax", 53 | "sphinx.ext.viewcode", 54 | "sphinx.ext.extlinks", 55 | "nbsphinx", 56 | "sphinx_design", 57 | "matplotlib.sphinxext.plot_directive", 58 | "qiskit_sphinx_theme", 59 | "sphinx.ext.doctest", 60 | "sphinx.ext.intersphinx", 61 | ] 62 | 63 | nbsphinx_timeout = 300 64 | nbsphinx_execute = os.getenv("QISKIT_DOCS_BUILD_TUTORIALS", "never") 65 | nbsphinx_widgets_path = "" 66 | html_sourcelink_suffix = "" 67 | exclude_patterns = ["_build", "**.ipynb_checkpoints"] 68 | 69 | nbsphinx_thumbnails = {"**": "_static/images/logo.png"} 70 | 71 | nbsphinx_prolog = """ 72 | {% set docname = env.doc2path(env.docname, base=None) %} 73 | 74 | .. only:: html 75 | 76 | .. role:: raw-html(raw) 77 | :format: html 78 | 79 | .. note:: 80 | This page was generated from `{{ docname }}`__. 81 | 82 | __ https://github.com/Qiskit/qiskit-tutorials/blob/master/{{ docname }} 83 | 84 | """ 85 | 86 | panels_css_variables = { 87 | "tabs-color-label-active": "rgb(138, 63, 252)", 88 | "tabs-color-label-inactive": "rgb(221, 225, 230)", 89 | } 90 | 91 | html_static_path = ["_static"] 92 | templates_path = ["_templates"] 93 | 94 | source_suffix = ".rst" 95 | master_doc = "index" 96 | 97 | # Number figures, tables and code-blocks if they have a caption. 98 | numfig = True 99 | # Available keys are 'figure', 'table', 'code-block' and 'section'. '%s' is the number. 100 | numfig_format = {"table": "Table %s"} 101 | 102 | language = "en" 103 | translations_list = [ 104 | ("en", "English"), 105 | ("bn_BN", "Bengali"), 106 | ("fr_FR", "French"), 107 | ("de_DE", "German"), 108 | ("ja_JP", "Japanese"), 109 | ("ko_KR", "Korean"), 110 | ("pt_UN", "Portuguese"), 111 | ("es_UN", "Spanish"), 112 | ("ta_IN", "Tamil"), 113 | ] 114 | # For Adding Locale 115 | locale_dirs = ["locale/"] # path is example but recommended. 116 | gettext_compact = False # optional. 117 | 118 | pygments_style = "colorful" 119 | 120 | # Whether module names are included in crossrefs of functions, classes, etc. 121 | add_module_names = True 122 | 123 | # A list of prefixes that are ignored for sorting the Python module index 124 | # (e.g., if this is set to ['foo.'], then foo.bar is shown under B, not F). 125 | # This can be handy if you document a project that consists of a single 126 | # package. Works only for the HTML builder currently. 127 | modindex_common_prefix = ["qiskit."] 128 | 129 | 130 | # -- Configuration for extlinks extension ------------------------------------ 131 | # Refer to https://www.sphinx-doc.org/en/master/usage/extensions/extlinks.html 132 | extlinks = { 133 | "pull_terra": ("https://github.com/Qiskit/qiskit-terra/pull/%s", "qiskit-terra #%s"), 134 | "pull_aer": ("https://github.com/Qiskit/qiskit-aer/pull/%s", "qiskit-aer #%s"), 135 | "pull_ibmq-provider": ( 136 | "https://github.com/Qiskit/qiskit-ibmq-provider/pull/%s", 137 | "qiskit-ibmq-provider #%s", 138 | ), 139 | } 140 | 141 | intersphinx_mapping = { 142 | "rustworkx": ("https://qiskit.org/ecosystem/rustworkx/", None), 143 | "qiskit-ibm-runtime": ("https://qiskit.org/ecosystem/ibm-runtime/", None), 144 | "qiskit-aer": ("https://qiskit.org/ecosystem/aer/", None), 145 | "numpy": ("https://numpy.org/doc/stable/", None), 146 | "matplotlib": ("https://matplotlib.org/stable/", None), 147 | } 148 | 149 | # -- Options for HTML output ------------------------------------------------- 150 | 151 | html_theme = "qiskit" 152 | html_favicon = "images/favicon.ico" 153 | html_last_updated_fmt = "%Y/%m/%d" 154 | html_context = { 155 | "analytics_enabled": os.getenv("QISKIT_ENABLE_ANALYTICS", False) 156 | } # enable segment analytics for qiskit.org/documentation 157 | 158 | # -- Options for Autosummary and Autodoc ------------------------------------ 159 | # Note that setting autodoc defaults here may not have as much of an effect as you may expect; any 160 | # documentation created by autosummary uses a template file (in autosummary in the templates path), 161 | # which likely overrides the autodoc defaults. 162 | autosummary_generate = True 163 | autosummary_generate_overwrite = False 164 | autoclass_content = "both" 165 | 166 | # The pulse library contains some names that differ only in capitalisation, during the changeover 167 | # surrounding SymbolPulse. Since these resolve to autosummary filenames that also differ only in 168 | # capitalisation, this causes problems when the documentation is built on an OS/filesystem that is 169 | # enforcing case-insensitive semantics. This setting defines some custom names to prevent the clash 170 | # from happening. 171 | autosummary_filename_map = { 172 | "qiskit.pulse.library.Constant": "qiskit.pulse.library.Constant_class.rst", 173 | "qiskit.pulse.library.Sawtooth": "qiskit.pulse.library.Sawtooth_class.rst", 174 | "qiskit.pulse.library.Triangle": "qiskit.pulse.library.Triangle_class.rst", 175 | "qiskit.pulse.library.Cos": "qiskit.pulse.library.Cos_class.rst", 176 | "qiskit.pulse.library.Sin": "qiskit.pulse.library.Sin_class.rst", 177 | "qiskit.pulse.library.Gaussian": "qiskit.pulse.library.Gaussian_class.rst", 178 | "qiskit.pulse.library.Drag": "qiskit.pulse.library.Drag_class.rst", 179 | } 180 | 181 | # Move type hints from signatures to the parameter descriptions (except in overload cases, where 182 | # that's not possible). 183 | autodoc_typehints = "description" 184 | # Only add type hints from signature to description body if the parameter has documentation. The 185 | # return type is always added to the description (if in the signature). 186 | autodoc_typehints_description_target = "documented_params" 187 | 188 | # Plot directive configuration 189 | # ---------------------------- 190 | 191 | plot_html_show_formats = False 192 | 193 | # --------------------------------------------------------------------------- 194 | # Doctest 195 | # --------------------------------------------------------------------------- 196 | 197 | # This option will make doctest ignore whitespace when testing code. 198 | # It's specially important for circuit representation as it gives an 199 | # error otherwise 200 | doctest_default_flags = sphinx.ext.doctest.doctest.NORMALIZE_WHITESPACE 201 | 202 | # Leaving this string empty disables testing of doctest blocks from docstrings. 203 | # Doctest blocks are structures like this one: 204 | # >> code 205 | # output 206 | doctest_test_doctest_blocks = "" 207 | 208 | 209 | # -- Extension configuration ------------------------------------------------- 210 | 211 | 212 | def setup(app): 213 | custom_extensions.load_terra_docs(app) 214 | custom_extensions.load_tutorials(app) 215 | app.connect("config-inited", custom_extensions.add_versions_to_config) 216 | app.connect("build-finished", custom_extensions.clean_docs) 217 | -------------------------------------------------------------------------------- /test/benchmarks/qasm/time_cnt3-5_180.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 2.0; 2 | include "qelib1.inc"; 3 | qreg q[16]; 4 | creg c[16]; 5 | h q[15]; 6 | t q[13]; 7 | t q[14]; 8 | t q[15]; 9 | cx q[14],q[13]; 10 | cx q[15],q[14]; 11 | cx q[13],q[15]; 12 | tdg q[14]; 13 | cx q[13],q[14]; 14 | tdg q[13]; 15 | tdg q[14]; 16 | t q[15]; 17 | cx q[15],q[14]; 18 | cx q[13],q[15]; 19 | cx q[14],q[13]; 20 | h q[15]; 21 | h q[12]; 22 | t q[13]; 23 | t q[11]; 24 | t q[12]; 25 | cx q[11],q[13]; 26 | cx q[12],q[11]; 27 | cx q[13],q[12]; 28 | tdg q[11]; 29 | cx q[13],q[11]; 30 | tdg q[13]; 31 | tdg q[11]; 32 | t q[12]; 33 | cx q[12],q[11]; 34 | cx q[13],q[12]; 35 | cx q[11],q[13]; 36 | h q[12]; 37 | h q[11]; 38 | t q[15]; 39 | t q[14]; 40 | t q[11]; 41 | cx q[14],q[15]; 42 | cx q[11],q[14]; 43 | cx q[15],q[11]; 44 | tdg q[14]; 45 | cx q[15],q[14]; 46 | tdg q[15]; 47 | tdg q[14]; 48 | t q[11]; 49 | cx q[11],q[14]; 50 | cx q[15],q[11]; 51 | cx q[14],q[15]; 52 | h q[11]; 53 | h q[12]; 54 | t q[13]; 55 | t q[11]; 56 | t q[12]; 57 | cx q[11],q[13]; 58 | cx q[12],q[11]; 59 | cx q[13],q[12]; 60 | tdg q[11]; 61 | cx q[13],q[11]; 62 | tdg q[13]; 63 | tdg q[11]; 64 | t q[12]; 65 | cx q[12],q[11]; 66 | cx q[13],q[12]; 67 | cx q[11],q[13]; 68 | h q[12]; 69 | h q[11]; 70 | t q[15]; 71 | t q[14]; 72 | t q[11]; 73 | cx q[14],q[15]; 74 | cx q[11],q[14]; 75 | cx q[15],q[11]; 76 | tdg q[14]; 77 | cx q[15],q[14]; 78 | tdg q[15]; 79 | tdg q[14]; 80 | t q[11]; 81 | cx q[11],q[14]; 82 | cx q[15],q[11]; 83 | cx q[14],q[15]; 84 | h q[11]; 85 | h q[14]; 86 | t q[15]; 87 | t q[13]; 88 | t q[14]; 89 | cx q[13],q[15]; 90 | cx q[14],q[13]; 91 | cx q[15],q[14]; 92 | tdg q[13]; 93 | cx q[15],q[13]; 94 | tdg q[15]; 95 | tdg q[13]; 96 | t q[14]; 97 | cx q[14],q[13]; 98 | cx q[15],q[14]; 99 | cx q[13],q[15]; 100 | h q[14]; 101 | cx q[13],q[15]; 102 | h q[11]; 103 | t q[12]; 104 | t q[10]; 105 | t q[11]; 106 | cx q[10],q[12]; 107 | cx q[11],q[10]; 108 | cx q[12],q[11]; 109 | tdg q[10]; 110 | cx q[12],q[10]; 111 | tdg q[12]; 112 | tdg q[10]; 113 | t q[11]; 114 | cx q[11],q[10]; 115 | cx q[12],q[11]; 116 | cx q[10],q[12]; 117 | h q[11]; 118 | h q[9]; 119 | t q[12]; 120 | t q[15]; 121 | t q[9]; 122 | cx q[15],q[12]; 123 | cx q[9],q[15]; 124 | cx q[12],q[9]; 125 | tdg q[15]; 126 | cx q[12],q[15]; 127 | tdg q[12]; 128 | tdg q[15]; 129 | t q[9]; 130 | cx q[9],q[15]; 131 | cx q[12],q[9]; 132 | cx q[15],q[12]; 133 | h q[9]; 134 | h q[15]; 135 | t q[11]; 136 | t q[10]; 137 | t q[15]; 138 | cx q[10],q[11]; 139 | cx q[15],q[10]; 140 | cx q[11],q[15]; 141 | tdg q[10]; 142 | cx q[11],q[10]; 143 | tdg q[11]; 144 | tdg q[10]; 145 | t q[15]; 146 | cx q[15],q[10]; 147 | cx q[11],q[15]; 148 | cx q[10],q[11]; 149 | h q[15]; 150 | h q[9]; 151 | t q[12]; 152 | t q[15]; 153 | t q[9]; 154 | cx q[15],q[12]; 155 | cx q[9],q[15]; 156 | cx q[12],q[9]; 157 | tdg q[15]; 158 | cx q[12],q[15]; 159 | tdg q[12]; 160 | tdg q[15]; 161 | t q[9]; 162 | cx q[9],q[15]; 163 | cx q[12],q[9]; 164 | cx q[15],q[12]; 165 | h q[9]; 166 | h q[15]; 167 | t q[11]; 168 | t q[10]; 169 | t q[15]; 170 | cx q[10],q[11]; 171 | cx q[15],q[10]; 172 | cx q[11],q[15]; 173 | tdg q[10]; 174 | cx q[11],q[10]; 175 | tdg q[11]; 176 | tdg q[10]; 177 | t q[15]; 178 | cx q[15],q[10]; 179 | cx q[11],q[15]; 180 | cx q[10],q[11]; 181 | h q[15]; 182 | h q[10]; 183 | t q[11]; 184 | t q[12]; 185 | t q[10]; 186 | cx q[12],q[11]; 187 | cx q[10],q[12]; 188 | cx q[11],q[10]; 189 | tdg q[12]; 190 | cx q[11],q[12]; 191 | tdg q[11]; 192 | tdg q[12]; 193 | t q[10]; 194 | cx q[10],q[12]; 195 | cx q[11],q[10]; 196 | cx q[12],q[11]; 197 | h q[10]; 198 | cx q[12],q[11]; 199 | h q[8]; 200 | t q[9]; 201 | t q[7]; 202 | t q[8]; 203 | cx q[7],q[9]; 204 | cx q[8],q[7]; 205 | cx q[9],q[8]; 206 | tdg q[7]; 207 | cx q[9],q[7]; 208 | tdg q[9]; 209 | tdg q[7]; 210 | t q[8]; 211 | cx q[8],q[7]; 212 | cx q[9],q[8]; 213 | cx q[7],q[9]; 214 | h q[8]; 215 | h q[6]; 216 | t q[9]; 217 | t q[15]; 218 | t q[6]; 219 | cx q[15],q[9]; 220 | cx q[6],q[15]; 221 | cx q[9],q[6]; 222 | tdg q[15]; 223 | cx q[9],q[15]; 224 | tdg q[9]; 225 | tdg q[15]; 226 | t q[6]; 227 | cx q[6],q[15]; 228 | cx q[9],q[6]; 229 | cx q[15],q[9]; 230 | h q[6]; 231 | h q[15]; 232 | t q[8]; 233 | t q[7]; 234 | t q[15]; 235 | cx q[7],q[8]; 236 | cx q[15],q[7]; 237 | cx q[8],q[15]; 238 | tdg q[7]; 239 | cx q[8],q[7]; 240 | tdg q[8]; 241 | tdg q[7]; 242 | t q[15]; 243 | cx q[15],q[7]; 244 | cx q[8],q[15]; 245 | cx q[7],q[8]; 246 | h q[15]; 247 | h q[6]; 248 | t q[9]; 249 | t q[15]; 250 | t q[6]; 251 | cx q[15],q[9]; 252 | cx q[6],q[15]; 253 | cx q[9],q[6]; 254 | tdg q[15]; 255 | cx q[9],q[15]; 256 | tdg q[9]; 257 | tdg q[15]; 258 | t q[6]; 259 | cx q[6],q[15]; 260 | cx q[9],q[6]; 261 | cx q[15],q[9]; 262 | h q[6]; 263 | h q[15]; 264 | t q[8]; 265 | t q[7]; 266 | t q[15]; 267 | cx q[7],q[8]; 268 | cx q[15],q[7]; 269 | cx q[8],q[15]; 270 | tdg q[7]; 271 | cx q[8],q[7]; 272 | tdg q[8]; 273 | tdg q[7]; 274 | t q[15]; 275 | cx q[15],q[7]; 276 | cx q[8],q[15]; 277 | cx q[7],q[8]; 278 | h q[15]; 279 | h q[7]; 280 | t q[8]; 281 | t q[9]; 282 | t q[7]; 283 | cx q[9],q[8]; 284 | cx q[7],q[9]; 285 | cx q[8],q[7]; 286 | tdg q[9]; 287 | cx q[8],q[9]; 288 | tdg q[8]; 289 | tdg q[9]; 290 | t q[7]; 291 | cx q[7],q[9]; 292 | cx q[8],q[7]; 293 | cx q[9],q[8]; 294 | h q[7]; 295 | cx q[9],q[8]; 296 | h q[5]; 297 | t q[6]; 298 | t q[4]; 299 | t q[5]; 300 | cx q[4],q[6]; 301 | cx q[5],q[4]; 302 | cx q[6],q[5]; 303 | tdg q[4]; 304 | cx q[6],q[4]; 305 | tdg q[6]; 306 | tdg q[4]; 307 | t q[5]; 308 | cx q[5],q[4]; 309 | cx q[6],q[5]; 310 | cx q[4],q[6]; 311 | h q[5]; 312 | h q[3]; 313 | t q[6]; 314 | t q[15]; 315 | t q[3]; 316 | cx q[15],q[6]; 317 | cx q[3],q[15]; 318 | cx q[6],q[3]; 319 | tdg q[15]; 320 | cx q[6],q[15]; 321 | tdg q[6]; 322 | tdg q[15]; 323 | t q[3]; 324 | cx q[3],q[15]; 325 | cx q[6],q[3]; 326 | cx q[15],q[6]; 327 | h q[3]; 328 | h q[15]; 329 | t q[5]; 330 | t q[4]; 331 | t q[15]; 332 | cx q[4],q[5]; 333 | cx q[15],q[4]; 334 | cx q[5],q[15]; 335 | tdg q[4]; 336 | cx q[5],q[4]; 337 | tdg q[5]; 338 | tdg q[4]; 339 | t q[15]; 340 | cx q[15],q[4]; 341 | cx q[5],q[15]; 342 | cx q[4],q[5]; 343 | h q[15]; 344 | h q[3]; 345 | t q[6]; 346 | t q[15]; 347 | t q[3]; 348 | cx q[15],q[6]; 349 | cx q[3],q[15]; 350 | cx q[6],q[3]; 351 | tdg q[15]; 352 | cx q[6],q[15]; 353 | tdg q[6]; 354 | tdg q[15]; 355 | t q[3]; 356 | cx q[3],q[15]; 357 | cx q[6],q[3]; 358 | cx q[15],q[6]; 359 | h q[3]; 360 | h q[15]; 361 | t q[5]; 362 | t q[4]; 363 | t q[15]; 364 | cx q[4],q[5]; 365 | cx q[15],q[4]; 366 | cx q[5],q[15]; 367 | tdg q[4]; 368 | cx q[5],q[4]; 369 | tdg q[5]; 370 | tdg q[4]; 371 | t q[15]; 372 | cx q[15],q[4]; 373 | cx q[5],q[15]; 374 | cx q[4],q[5]; 375 | h q[15]; 376 | h q[4]; 377 | t q[5]; 378 | t q[6]; 379 | t q[4]; 380 | cx q[6],q[5]; 381 | cx q[4],q[6]; 382 | cx q[5],q[4]; 383 | tdg q[6]; 384 | cx q[5],q[6]; 385 | tdg q[5]; 386 | tdg q[6]; 387 | t q[4]; 388 | cx q[4],q[6]; 389 | cx q[5],q[4]; 390 | cx q[6],q[5]; 391 | h q[4]; 392 | cx q[6],q[5]; 393 | h q[2]; 394 | t q[3]; 395 | t q[1]; 396 | t q[2]; 397 | cx q[1],q[3]; 398 | cx q[2],q[1]; 399 | cx q[3],q[2]; 400 | tdg q[1]; 401 | cx q[3],q[1]; 402 | tdg q[3]; 403 | tdg q[1]; 404 | t q[2]; 405 | cx q[2],q[1]; 406 | cx q[3],q[2]; 407 | cx q[1],q[3]; 408 | h q[2]; 409 | h q[0]; 410 | t q[3]; 411 | t q[15]; 412 | t q[0]; 413 | cx q[15],q[3]; 414 | cx q[0],q[15]; 415 | cx q[3],q[0]; 416 | tdg q[15]; 417 | cx q[3],q[15]; 418 | tdg q[3]; 419 | tdg q[15]; 420 | t q[0]; 421 | cx q[0],q[15]; 422 | cx q[3],q[0]; 423 | cx q[15],q[3]; 424 | h q[0]; 425 | h q[15]; 426 | t q[2]; 427 | t q[1]; 428 | t q[15]; 429 | cx q[1],q[2]; 430 | cx q[15],q[1]; 431 | cx q[2],q[15]; 432 | tdg q[1]; 433 | cx q[2],q[1]; 434 | tdg q[2]; 435 | tdg q[1]; 436 | t q[15]; 437 | cx q[15],q[1]; 438 | cx q[2],q[15]; 439 | cx q[1],q[2]; 440 | h q[15]; 441 | h q[0]; 442 | t q[3]; 443 | t q[15]; 444 | t q[0]; 445 | cx q[15],q[3]; 446 | cx q[0],q[15]; 447 | cx q[3],q[0]; 448 | tdg q[15]; 449 | cx q[3],q[15]; 450 | tdg q[3]; 451 | tdg q[15]; 452 | t q[0]; 453 | cx q[0],q[15]; 454 | cx q[3],q[0]; 455 | cx q[15],q[3]; 456 | h q[0]; 457 | h q[15]; 458 | t q[2]; 459 | t q[1]; 460 | t q[15]; 461 | cx q[1],q[2]; 462 | cx q[15],q[1]; 463 | cx q[2],q[15]; 464 | tdg q[1]; 465 | cx q[2],q[1]; 466 | tdg q[2]; 467 | tdg q[1]; 468 | t q[15]; 469 | cx q[15],q[1]; 470 | cx q[2],q[15]; 471 | cx q[1],q[2]; 472 | h q[15]; 473 | h q[1]; 474 | t q[2]; 475 | t q[3]; 476 | t q[1]; 477 | cx q[3],q[2]; 478 | cx q[1],q[3]; 479 | cx q[2],q[1]; 480 | tdg q[3]; 481 | cx q[2],q[3]; 482 | tdg q[2]; 483 | tdg q[3]; 484 | t q[1]; 485 | cx q[1],q[3]; 486 | cx q[2],q[1]; 487 | cx q[3],q[2]; 488 | h q[1]; 489 | cx q[3],q[2]; 490 | -------------------------------------------------------------------------------- /docs/intro_tutorial1.rst: -------------------------------------------------------------------------------- 1 | ====================== 2 | Introduction to Qiskit 3 | ====================== 4 | 5 | When using Qiskit a user workflow nominally consists of 6 | following four high-level steps: 7 | 8 | - **Build**: Design a quantum circuit(s) that represents the problem you are 9 | considering. 10 | - **Compile**: Compile circuits for a specific quantum service, e.g. a quantum 11 | system or classical simulator. 12 | - **Run**: Run the compiled circuits on the specified quantum service(s). These 13 | services can be cloud-based or local. 14 | - **Analyze**: Compute summary statistics and visualize the results of the 15 | experiments. 16 | 17 | Here is an example of the entire workflow, with each step explained in detail in 18 | subsequent sections: 19 | 20 | .. plot:: 21 | :include-source: 22 | :context: 23 | 24 | from qiskit import QuantumCircuit, transpile 25 | from qiskit_aer import AerSimulator 26 | from qiskit.visualization import plot_histogram 27 | 28 | # Use Aer's AerSimulator 29 | simulator = AerSimulator() 30 | 31 | # Create a Quantum Circuit acting on the q register 32 | circuit = QuantumCircuit(2, 2) 33 | 34 | # Add a H gate on qubit 0 35 | circuit.h(0) 36 | 37 | # Add a CX (CNOT) gate on control qubit 0 and target qubit 1 38 | circuit.cx(0, 1) 39 | 40 | # Map the quantum measurement to the classical bits 41 | circuit.measure([0, 1], [0, 1]) 42 | 43 | # Compile the circuit for the support instruction set (basis_gates) 44 | # and topology (coupling_map) of the backend 45 | compiled_circuit = transpile(circuit, simulator) 46 | 47 | # Execute the circuit on the aer simulator 48 | job = simulator.run(compiled_circuit, shots=1000) 49 | 50 | # Grab results from the job 51 | result = job.result() 52 | 53 | # Returns counts 54 | counts = result.get_counts(compiled_circuit) 55 | print("\nTotal count for 00 and 11 are:", counts) 56 | 57 | # Draw the circuit 58 | circuit.draw("mpl") 59 | 60 | .. plot:: 61 | :include-source: 62 | :context: close-figs 63 | 64 | # Plot a histogram 65 | plot_histogram(counts) 66 | 67 | 68 | 69 | ----------------------- 70 | Workflow Step--by--Step 71 | ----------------------- 72 | 73 | The program above can be broken down into six steps: 74 | 75 | 1. Import packages 76 | 2. Initialize variables 77 | 3. Add gates 78 | 4. Visualize the circuit 79 | 5. Simulate the experiment 80 | 6. Visualize the results 81 | 82 | 83 | ~~~~~~~~~~~~~~~~~~~~~~~~ 84 | Step 1 : Import Packages 85 | ~~~~~~~~~~~~~~~~~~~~~~~~ 86 | 87 | The basic elements needed for your program are imported as follows: 88 | 89 | .. code-block:: python 90 | 91 | from qiskit import QuantumCircuit 92 | from qiskit_aer import AerSimulator 93 | from qiskit.visualization import plot_histogram 94 | 95 | In more detail, the imports are 96 | 97 | - ``QuantumCircuit``: can be thought as the instructions of the quantum system. 98 | It holds all your quantum operations. 99 | - ``AerSimulator``: is the Aer high performance circuit simulator. 100 | - ``plot_histogram``: creates histograms. 101 | 102 | 103 | 104 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 105 | Step 2 : Initialize Variables 106 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 107 | 108 | Consider the next line of code 109 | 110 | .. code-block:: python 111 | 112 | circuit = QuantumCircuit(2, 2) 113 | 114 | Here, you are initializing with 2 qubits in the zero state; with 2 115 | classical bits set to zero; and ``circuit`` is the quantum circuit. 116 | 117 | Syntax: 118 | 119 | - ``QuantumCircuit(int, int)`` 120 | 121 | 122 | 123 | ~~~~~~~~~~~~~~~~~~ 124 | Step 3 : Add Gates 125 | ~~~~~~~~~~~~~~~~~~ 126 | 127 | You can add gates (operations) to manipulate the registers of your circuit. 128 | 129 | Consider the following three lines of code: 130 | 131 | .. code-block:: python 132 | 133 | circuit.h(0) 134 | circuit.cx(0, 1) 135 | circuit.measure([0, 1], [0, 1]) 136 | 137 | The gates are added to the circuit one-by-one to form the Bell state 138 | 139 | .. math:: \lvert\psi\rangle = \left(\lvert00\rangle+\lvert11\rangle\right)/\sqrt{2}. 140 | 141 | The code above applies the following gates: 142 | 143 | - ``QuantumCircuit.h(0)``: A Hadamard gate :math:`H` on qubit 0, 144 | which puts it into a **superposition state**. 145 | - ``QuantumCircuit.cx(0, 1)``: A controlled-Not operation 146 | (:math:`CNOT`) on control qubit 0 and target qubit 1, putting the qubits in 147 | an **entangled state**. 148 | - ``QuantumCircuit.measure([0,1], [0,1])``: if you pass 149 | the entire quantum and classical registers to ``measure``, the ith qubit’s 150 | measurement result will be stored in the ith classical bit. 151 | 152 | 153 | 154 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 155 | Step 4 : Visualize the Circuit 156 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 157 | 158 | You can use :meth:`qiskit.circuit.QuantumCircuit.draw` to view the circuit that you have designed 159 | in the various forms used in many textbooks and research articles. 160 | 161 | .. plot:: 162 | :include-source: 163 | :context: close-figs 164 | 165 | circuit.draw("mpl") 166 | 167 | In this circuit, the qubits are ordered with qubit zero at the top and 168 | qubit one at the bottom. The circuit is read left-to-right, meaning that gates 169 | which are applied earlier in the circuit show up farther to the left. 170 | 171 | The default backend for ``QuantumCircuit.draw()`` or ``qiskit.visualization.circuit_drawer()`` 172 | is the text backend. However, depending on your local environment you may want to change 173 | these defaults to something better suited for your use case. This is done with the user 174 | config file. By default the user config file should be located in 175 | ``~/.qiskit/settings.conf`` and is a ``.ini`` file. 176 | 177 | For example, a ``settings.conf`` file for setting a Matplotlib drawer is: 178 | 179 | .. code-block:: text 180 | 181 | [default] 182 | circuit_drawer = mpl 183 | 184 | You can use any of the valid circuit drawer backends as the value for this config, this includes 185 | text, mpl, latex, and latex_source. 186 | 187 | 188 | 189 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 190 | Step 5 : Simulate the Experiment 191 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 192 | 193 | `Qiskit Aer `_ is a high performance 194 | simulator framework for quantum circuits. It provides several backends to 195 | achieve different simulation goals. 196 | 197 | If you have issues installing Aer, you can alternatively use the Basic Aer 198 | provider by replacing `Aer` with `BasicAer`. Basic Aer is included in Qiskit. 199 | 200 | .. code-block:: python 201 | 202 | from qiskit import QuantumCircuit, transpile 203 | from qiskit.providers.basicaer import QasmSimulatorPy 204 | ... 205 | 206 | To simulate this circuit, you will use the ``AerSimulator``. Each run of this 207 | circuit will yield either the bit string 00 or 11. 208 | 209 | .. plot:: 210 | :include-source: 211 | :context: close-figs 212 | 213 | simulator = AerSimulator() 214 | compiled_circuit = transpile(circuit, simulator) 215 | job = simulator.run(compiled_circuit, shots=1000) 216 | result = job.result() 217 | counts = result.get_counts(circuit) 218 | print("\nTotal count for 00 and 11 are:",counts) 219 | 220 | As expected, the output bit string is 00 approximately 50 percent of the time. 221 | The number of times the circuit is run can be specified via the ``shots`` 222 | argument of the ``execute`` method. The number of shots of the simulation was 223 | set to be 1000 (the default is 1024). 224 | 225 | Once you have a ``result`` object, you can access the counts via the method 226 | ``get_counts(circuit)``. This gives you the aggregate outcomes of the 227 | experiment you ran. 228 | 229 | 230 | 231 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 232 | Step 6 : Visualize the Results 233 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 234 | 235 | Qiskit provides `many visualizations `__, 236 | 237 | including the function ``plot_histogram``, to view your results. 238 | 239 | .. plot:: 240 | :include-source: 241 | :context: close-figs 242 | 243 | plot_histogram(counts) 244 | 245 | The observed probabilities :math:`Pr(00)` and :math:`Pr(11)` are computed by 246 | taking the respective counts and dividing by the total number of shots. 247 | 248 | .. note:: 249 | 250 | Try changing the ``shots`` keyword in the ``run()`` method to see how 251 | the estimated probabilities change. 252 | 253 | 254 | ---------- 255 | Next Steps 256 | ---------- 257 | 258 | Now that you have learnt the basics, consider these learning resources: 259 | 260 | - :ref:`Qiskit tutorials ` 261 | - `Textbook: Learn Quantum Computing using Qiskit `_ 262 | - `Video series: Coding with Qiskit `_ 263 | -------------------------------------------------------------------------------- /test/benchmarks/queko.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # This code is part of Qiskit. 4 | # 5 | # (C) Copyright IBM 2021. 6 | # 7 | # This code is licensed under the Apache License, Version 2.0. You may 8 | # obtain a copy of this license in the LICENSE.txt file in the root directory 9 | # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. 10 | # 11 | # Any modifications or derivative works of this code must retain this 12 | # copyright notice, and modified files need to carry a notice indicating 13 | # that they have been altered from the originals. 14 | 15 | # pylint: disable=no-member,invalid-name,missing-docstring,no-name-in-module 16 | # pylint: disable=attribute-defined-outside-init,unsubscriptable-object 17 | 18 | import os 19 | 20 | from qiskit import QuantumCircuit 21 | from qiskit.compiler import transpile 22 | 23 | 24 | class QUEKOTranspilerBench: 25 | params = ([0, 1, 2, 3], 26 | [None, "sabre"]) 27 | param_names = ["optimization level", "routing/layout method"] 28 | timeout = 600 29 | 30 | # pylint: disable=unused-argument 31 | def setup(self, optimization_level, routing_method): 32 | self.rochester_coupling_map = [ 33 | [0, 5], 34 | [0, 1], 35 | [1, 2], 36 | [1, 0], 37 | [2, 3], 38 | [2, 1], 39 | [3, 4], 40 | [3, 2], 41 | [4, 6], 42 | [4, 3], 43 | [5, 9], 44 | [5, 0], 45 | [6, 13], 46 | [6, 4], 47 | [7, 16], 48 | [7, 8], 49 | [8, 9], 50 | [8, 7], 51 | [9, 10], 52 | [9, 8], 53 | [9, 5], 54 | [10, 11], 55 | [10, 9], 56 | [11, 17], 57 | [11, 12], 58 | [11, 10], 59 | [12, 13], 60 | [12, 11], 61 | [13, 14], 62 | [13, 12], 63 | [13, 6], 64 | [14, 15], 65 | [14, 13], 66 | [15, 18], 67 | [15, 14], 68 | [16, 19], 69 | [16, 7], 70 | [17, 23], 71 | [17, 11], 72 | [18, 27], 73 | [18, 15], 74 | [19, 20], 75 | [19, 16], 76 | [20, 21], 77 | [20, 19], 78 | [21, 28], 79 | [21, 22], 80 | [21, 20], 81 | [22, 23], 82 | [22, 21], 83 | [23, 24], 84 | [23, 22], 85 | [23, 17], 86 | [24, 25], 87 | [24, 23], 88 | [25, 29], 89 | [25, 26], 90 | [25, 24], 91 | [26, 27], 92 | [26, 25], 93 | [27, 26], 94 | [27, 18], 95 | [28, 32], 96 | [28, 21], 97 | [29, 36], 98 | [29, 25], 99 | [30, 39], 100 | [30, 31], 101 | [31, 32], 102 | [31, 30], 103 | [32, 33], 104 | [32, 31], 105 | [32, 28], 106 | [33, 34], 107 | [33, 32], 108 | [34, 40], 109 | [34, 35], 110 | [34, 33], 111 | [35, 36], 112 | [35, 34], 113 | [36, 37], 114 | [36, 35], 115 | [36, 29], 116 | [37, 38], 117 | [37, 36], 118 | [38, 41], 119 | [38, 37], 120 | [39, 42], 121 | [39, 30], 122 | [40, 46], 123 | [40, 34], 124 | [41, 50], 125 | [41, 38], 126 | [42, 43], 127 | [42, 39], 128 | [43, 44], 129 | [43, 42], 130 | [44, 51], 131 | [44, 45], 132 | [44, 43], 133 | [45, 46], 134 | [45, 44], 135 | [46, 47], 136 | [46, 45], 137 | [46, 40], 138 | [47, 48], 139 | [47, 46], 140 | [48, 52], 141 | [48, 49], 142 | [48, 47], 143 | [49, 50], 144 | [49, 48], 145 | [50, 49], 146 | [50, 41], 147 | [51, 44], 148 | [52, 48]] 149 | 150 | self.tokyo_coupling_map = [ 151 | [0, 1], [1, 2], [2, 3], [3, 4], 152 | [0, 5], [1, 6], [1, 7], [2, 6], [2, 7], [3, 8], [3, 9], [4, 8], 153 | [4, 9], [5, 6], [6, 7], [7, 8], [8, 9], [5, 10], [5, 11], [6, 10], 154 | [6, 11], [7, 12], [7, 13], [8, 12], [8, 13], [9, 14], [10, 11], 155 | [11, 12], [12, 13], [13, 14], [10, 15], [11, 16], [11, 17], 156 | [12, 16], [12, 17], [13, 18], [13, 19], [14, 18], [14, 19], 157 | [15, 16], [16, 17], [17, 18], [18, 19] 158 | ] 159 | self.sycamore_coupling_map = [ 160 | [0, 6], [1, 6], [1, 7], [2, 7], [2, 8], [3, 8], [3, 9], [4, 9], 161 | [4, 10], [5, 10], [5, 11], [6, 12], [6, 13], [7, 13], [7, 14], 162 | [8, 14], [8, 15], [9, 15], [9, 16], [10, 16], [10, 17], [11, 17], 163 | [12, 18], [13, 18], [13, 19], [14, 19], [14, 20], [15, 20], 164 | [15, 21], [16, 21], [16, 22], [17, 22], [17, 23], [18, 24], 165 | [18, 25], [19, 25], [19, 26], [20, 26], [20, 27], [21, 27], 166 | [21, 28], [22, 28], [22, 29], [23, 29], [24, 30], [25, 30], 167 | [25, 31], [26, 31], [26, 32], [27, 32], [27, 33], [28, 33], 168 | [28, 34], [29, 34], [29, 35], [30, 36], [30, 37], [31, 37], 169 | [31, 38], [32, 38], [32, 39], [33, 39], [33, 40], [34, 40], 170 | [34, 41], [35, 41], [36, 42], [37, 42], [37, 43], [38, 43], 171 | [38, 44], [39, 44], [39, 45], [40, 45], [40, 46], [41, 46], 172 | [41, 47], [42, 48], [42, 49], [43, 49], [43, 50], [44, 50], 173 | [44, 51], [45, 51], [45, 52], [46, 52], [46, 53], [47, 53] 174 | ] 175 | self.basis_gates = ["id", "rz", "sx", "x", "cx"] 176 | self.qasm_path = os.path.abspath( 177 | os.path.join(os.path.dirname(__file__), "qasm")) 178 | 179 | self.bigd = QuantumCircuit.from_qasm_file( 180 | os.path.join(self.qasm_path, "20QBT_45CYC_.0D1_.1D2_3.qasm")) 181 | self.bss = QuantumCircuit.from_qasm_file( 182 | os.path.join(self.qasm_path, "53QBT_100CYC_QSE_3.qasm")) 183 | self.bntf = QuantumCircuit.from_qasm_file( 184 | os.path.join(self.qasm_path, "54QBT_25CYC_QSE_3.qasm")) 185 | 186 | def track_depth_bntf_optimal_depth_25(self, optimization_level, 187 | routing_method): 188 | return transpile(self.bntf, coupling_map=self.sycamore_coupling_map, 189 | basis_gates=self.basis_gates, 190 | routing_method=routing_method, 191 | layout_method=routing_method, 192 | optimization_level=optimization_level, 193 | seed_transpiler=0).depth() 194 | 195 | def track_depth_bss_optimal_depth_100(self, optimization_level, 196 | routing_method): 197 | return transpile(self.bss, coupling_map=self.rochester_coupling_map, 198 | basis_gates=self.basis_gates, 199 | routing_method=routing_method, 200 | layout_method=routing_method, 201 | optimization_level=optimization_level, 202 | seed_transpiler=0).depth() 203 | 204 | def track_depth_bigd_optimal_depth_45(self, optimization_level, 205 | routing_method): 206 | return transpile(self.bigd, coupling_map=self.tokyo_coupling_map, 207 | basis_gates=self.basis_gates, 208 | routing_method=routing_method, 209 | layout_method=routing_method, 210 | optimization_level=optimization_level, 211 | seed_transpiler=0).depth() 212 | 213 | def time_transpile_bntf(self, optimization_level, routing_method): 214 | transpile(self.bntf, coupling_map=self.sycamore_coupling_map, 215 | basis_gates=self.basis_gates, 216 | routing_method=routing_method, 217 | layout_method=routing_method, 218 | optimization_level=optimization_level, 219 | seed_transpiler=0).depth() 220 | 221 | def time_transpile_bss(self, optimization_level, routing_method): 222 | transpile(self.bss, coupling_map=self.rochester_coupling_map, 223 | basis_gates=self.basis_gates, 224 | routing_method=routing_method, 225 | layout_method=routing_method, 226 | optimization_level=optimization_level, 227 | seed_transpiler=0).depth() 228 | 229 | def time_transpile_bigd(self, optimization_level, routing_method): 230 | transpile(self.bigd, coupling_map=self.tokyo_coupling_map, 231 | basis_gates=self.basis_gates, 232 | routing_method=routing_method, 233 | layout_method=routing_method, 234 | optimization_level=optimization_level, 235 | seed_transpiler=0).depth() 236 | --------------------------------------------------------------------------------