{ "info": { "author": "Gate42 Quantum Computing Lab", "author_email": "team@gate42.org", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Science/Research", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# Error Mitigation Implemented on Rigetti Forest™\n\nThe unwanted interaction of the quantum computer with the outside\nworld introduces noise into the computations which makes \nfault tolerant Quantum Computation outof reach of current technologies.\nIn this regard, to make use of NISQ devices one can consider techniques which\nalleviate the impacts of errors without additional resource\nrequirements. One of such mitigation techniques (for\nshort depth circuits) is the so called \u201dExtrapolation to\nthe zero noise limit\u201d or as we will refer to it Error Mitigation (EM)\nwhich has been successfully [implemented recently](https://www.nature.com/articles/s41586-019-1040-7).\nIt is assumed that the action of the noise is weak and it can be described by\nsome small parameter. The expectation value of any\nobservable depends on this parameter and can be expanded\nas series in it and the 0th order term will correspond\nto noise-free value. It\u2019s suggested to gain the \nexpectation values at different noise parameters and then apply\nRichardson\u2019s deferred approach to the limit to obtain an\napproximation to noise-free value. \n\nThis package provides easy to use interface for applying error correcting code with EM technique to any PyQuil program.\n\nEM in this package is implemented as described [here](https://arxiv.org/abs/1612.02058).\n\n## Installation\n\nEMPyQuil can be installed using pip, or directly from source.\n\nTo instead install EMPyQuil as a PyPI package, do the following:\n\n`pip install em_pyquil`\n\nIf you would prefer to install EMPyQuil directly from source, do the following:\n\n`pip install git+https://github.com/gate42qc/em-pyquil`\n\n\n## Usage\n\nThis package provides two functions: `apply_em` and `apply_noise` which can be used with PyQuil `QuantumComputer` objects.\nThese functions will override `run` methods of passed `QuantumComputer` objects making them return error mitigated results.\n\nSo if you have some piece of code and want to run the error mitigated version of it you only need to call `apply_em` on `QuantumComputer` \nobject you will use for running your program.\n\n```python\nfrom pyquil.api import get_qc\nfrom pyquil.quil import Program\nfrom pyquil.gates import X\nfrom em_pyquil import apply_em, apply_noise\n\nnoisy_qc = apply_noise(get_qc(\"3q-qvm\"))\nem_qc = apply_em(get_qc(\"3q-qvm\"))\n\np = Program(X(0))\n\nem_res = em_qc.run_and_measure(p, 1000) # results obtained running the program with noise and filtered with EM technique\n\nnoisy_res = noisy_qc.run_and_measure(p, 1000) # results obtained running the program with just noise model without filtering\n```\n\n## Examples\n\nThere are more examples in the [examples directory](examples).\n\n\n## Running your programs with EM technique applied\n\nIn our EM implementation we run the program \nmultiple times with noise models with \ndifferent values of the noise parameter \n(in current implementation noise parameter is the gate time).\nThen we will collect result bitstrings, get mean results for each qubit over trials,\nthen using Richardson\u2019s method we extrapolate results.\nThe extrapolated results are rounded to 0 or 1 and returned.\n\nSo after the following line:\n\n`em_qc = apply_em(get_qc(\"3q-qvm\"))`\n\nthe `em_qc` will work exactly like `QuantumComputer` instance would work \nexcept that it will run programs multiple times and will return extrapolated results.\nThis allows you to run you existing programs with EM \nwithout changing much of our existing code.\n\n:note\nDo not call `apply_noise` or `noisy_qc` on the same `QuantumComputer` object.\n\n\nYou can customise noise parameters used in EM by giving the base parameter and list of coefficients:\n\n```python\n# programs will run with gate times: 1*60e-9, 1.5*60e-9 and 2*60e-9\nem_qc = apply_em(get_qc(\"3q-qvm\"), base_gate_time=60e-9, noise_param_coefficients=[1, 1.5, 2])\n```\n\n## Comparing noisy and noise + EM results\n\nThere is another function: `apply_noise` in this package you could use to \nobtain `QuantumComputer` instance that uses similar noise \nmodel to `apply_em` so that you can compare results:\n\n```python\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport random\n\nfrom pyquil.api import get_qc\nfrom pyquil.quil import Program\nfrom pyquil.gates import RX, RZ, CZ\n\nfrom em_pyquil import apply_em, apply_noise\n\n\ndef get_dagger_of_native_gate(gate):\n if gate.name == \"RZ\":\n return RZ(-gate.params[0], gate.qubits[0])\n if gate.name == \"RX\":\n return RX(-gate.params[0], gate.qubits[0])\n if gate.name == \"CZ\":\n return CZ(*gate.qubits)\n\n raise ValueError(\"Unsupported gate: \" + str(gate))\n\n\ndef get_random_circuit(qubits, length, two_qubit_gate_portion=0.3):\n p = Program()\n\n for i in range(int(length / 2)):\n if (len(qubits) > 1) and (random.random() < two_qubit_gate_portion):\n random_gate = CZ(*(random.sample(qubits, 2)))\n else:\n theta = 2 * np.pi * random.random()\n qubit = random.choice(qubits)\n random_gate = random.choice([\n RZ(theta, qubit),\n RX(np.pi / 2, qubit),\n RX(- np.pi / 2, qubit)\n ])\n\n p.inst(random_gate)\n\n for gate in reversed(Program(p.out()).instructions):\n p.inst(get_dagger_of_native_gate(gate))\n\n return Program('PRAGMA PRESERVE_BLOCK') + p + Program('PRAGMA END_PRESERVE_BLOCK')\n\n\ndef run_with_qc(qc, lengths):\n data = []\n\n for i in lengths:\n fidelities = []\n for j in range(20):\n p = get_random_circuit(qc.qubits(), i)\n res = qc.run_and_measure(p, 10000)\n fidelity = 1 - np.mean(res[0] * res[1])\n fidelities.append(fidelity)\n mean_fidelity = np.mean(np.array(fidelities))\n data.append(mean_fidelity)\n\n return data\n\n\nnoisy_qc = apply_noise(get_qc(\"3q-qvm\"))\nem_qc = apply_em(get_qc(\"3q-qvm\"))\n\nlengths = np.arange(2, 100, 5)\n\nem_data = run_with_qc(em_qc, lengths)\nnoisy_data = run_with_qc(noisy_qc, lengths)\n\nplt.xlabel('Circuit depth')\nplt.ylabel('Fidelity')\nplt.plot(lengths, noisy_data, 'o-', label=\"Only Noise\")\nplt.plot(lengths, em_data, 'o-', label=\"Noise + EM\")\nplt.legend()\nplt.show()\n\n```\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/gate42qc/em-pyquil.git", "keywords": "quantum quil programming pyquil error mitigation", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "em-pyquil", "package_url": "https://pypi.org/project/em-pyquil/", "platform": "", "project_url": "https://pypi.org/project/em-pyquil/", "project_urls": { "Homepage": "https://github.com/gate42qc/em-pyquil.git" }, "release_url": "https://pypi.org/project/em-pyquil/1.0.2/", "requires_dist": [ "numpy", "pyquil (>=2.10.0)" ], "requires_python": ">=3.6", "summary": "A Python library implementing error mitigation on pyquil programs.", "version": "1.0.2" }, "last_serial": 5963183, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "b70d12a82972672a42528e543d8de0c9", "sha256": "fddad771485d8b3a8006f0636bfe700af56f78788a70c8617b239893f7f74ca2" }, "downloads": -1, "filename": "em_pyquil-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "b70d12a82972672a42528e543d8de0c9", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 3979, "upload_time": "2019-10-11T17:21:20", "url": "https://files.pythonhosted.org/packages/94/d2/d2317ef0875d08a552e79e293e87ea45711d17260e98e2eb3ea86133008b/em_pyquil-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5bdc6d6d7a11e50e09d7939c49780c9a", "sha256": "90ed111578b4813c6719402ad33750a2a065695ea87fe0822c46d852edb701ea" }, "downloads": -1, "filename": "em-pyquil-1.0.0.tar.gz", "has_sig": false, "md5_digest": "5bdc6d6d7a11e50e09d7939c49780c9a", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 4962, "upload_time": "2019-10-11T17:21:23", "url": "https://files.pythonhosted.org/packages/2d/0c/3e8e21dae4b6d1d306884267f0105278bbf60f2f4c8346224f8647fa4009/em-pyquil-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "f1b78cba2f5207dbc0a097942aeb198c", "sha256": "faf4bcc08139dd98becb85e5d8ac5a349ced6541b15257c118152b35159a0032" }, "downloads": -1, "filename": "em_pyquil-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "f1b78cba2f5207dbc0a097942aeb198c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 6320, "upload_time": "2019-10-11T17:37:35", "url": "https://files.pythonhosted.org/packages/4f/76/f9d57672078f1504573ee2262010e2c5fbb1beebbbdd495a24e6c928c0a4/em_pyquil-1.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "87e265dfa1662e48b3edbe8c4db044fc", "sha256": "db0e18c6861ab12d6e4f1a2567a1f32d0243c9c57fa2f51e289d07bf8e9bd3db" }, "downloads": -1, "filename": "em-pyquil-1.0.1.tar.gz", "has_sig": false, "md5_digest": "87e265dfa1662e48b3edbe8c4db044fc", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 5619, "upload_time": "2019-10-11T17:37:37", "url": "https://files.pythonhosted.org/packages/54/04/6c5ec94a566a81be62cf338730a604f3d6cb70f10f223e4d20f960b6d4df/em-pyquil-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "177bd8938e618eabd4c0f8b3fece0aa3", "sha256": "fbd43c7f0021795edfe49f64af986a6672ccb8d468a0a7a3e4e32a5d7de9651f" }, "downloads": -1, "filename": "em_pyquil-1.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "177bd8938e618eabd4c0f8b3fece0aa3", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 6334, "upload_time": "2019-10-12T06:01:23", "url": "https://files.pythonhosted.org/packages/f3/b3/af41968e768ae63736ce88010c760db023697c1cbcc2ee48ea0f99214ef9/em_pyquil-1.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b1a695f0249146d7ae25e4fb1a0d63e5", "sha256": "6b488c91adeb59967a872d2e473200ca85b9b09f7112ae1451374d58f63dd933" }, "downloads": -1, "filename": "em-pyquil-1.0.2.tar.gz", "has_sig": false, "md5_digest": "b1a695f0249146d7ae25e4fb1a0d63e5", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 5641, "upload_time": "2019-10-12T06:01:25", "url": "https://files.pythonhosted.org/packages/0b/24/820bad2ebd6f3ed3eb3836ba352595e117b32fc76cc613c203f7555e8a3e/em-pyquil-1.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "177bd8938e618eabd4c0f8b3fece0aa3", "sha256": "fbd43c7f0021795edfe49f64af986a6672ccb8d468a0a7a3e4e32a5d7de9651f" }, "downloads": -1, "filename": "em_pyquil-1.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "177bd8938e618eabd4c0f8b3fece0aa3", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 6334, "upload_time": "2019-10-12T06:01:23", "url": "https://files.pythonhosted.org/packages/f3/b3/af41968e768ae63736ce88010c760db023697c1cbcc2ee48ea0f99214ef9/em_pyquil-1.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b1a695f0249146d7ae25e4fb1a0d63e5", "sha256": "6b488c91adeb59967a872d2e473200ca85b9b09f7112ae1451374d58f63dd933" }, "downloads": -1, "filename": "em-pyquil-1.0.2.tar.gz", "has_sig": false, "md5_digest": "b1a695f0249146d7ae25e4fb1a0d63e5", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 5641, "upload_time": "2019-10-12T06:01:25", "url": "https://files.pythonhosted.org/packages/0b/24/820bad2ebd6f3ed3eb3836ba352595e117b32fc76cc613c203f7555e8a3e/em-pyquil-1.0.2.tar.gz" } ] }