{"id":22882600,"url":"https://github.com/cqcl/phayes","last_synced_at":"2025-03-31T16:38:28.214Z","repository":{"id":177282527,"uuid":"643888999","full_name":"CQCL/phayes","owner":"CQCL","description":"Easy and efficient Bayesian quantum phase estimation","archived":false,"fork":false,"pushed_at":"2023-07-11T13:28:35.000Z","size":1022,"stargazers_count":2,"open_issues_count":4,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-06T21:46:27.882Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CQCL.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-22T11:17:16.000Z","updated_at":"2024-01-20T12:28:01.000Z","dependencies_parsed_at":"2023-07-20T04:01:34.997Z","dependency_job_id":null,"html_url":"https://github.com/CQCL/phayes","commit_stats":null,"previous_names":["cqcl/phayes"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CQCL%2Fphayes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CQCL%2Fphayes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CQCL%2Fphayes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CQCL%2Fphayes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CQCL","download_url":"https://codeload.github.com/CQCL/phayes/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246499331,"owners_count":20787483,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-13T18:18:31.763Z","updated_at":"2025-03-31T16:38:28.208Z","avatar_url":"https://github.com/CQCL.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# phayes\n\n`phayes` is a python package for easy and efficient quantum phase estimation.\n\nExtensive details on Bayesian quantum phase estimation can be found in the accompanying paper, [Yamamoto et al, 2023](https://arxiv.org/abs/2306.16608).\n\n\n\u003cimg src=\"examples/hadamard_qpe_circuit.png\" width=\"500\"\u003e\n\nQuantum phase estimation\n[Wiebe et al, 2015](https://arxiv.org/abs/1508.00869),\n[O'Brien et al, 2018](https://iopscience.iop.org/article/10.1088/1367-2630/aafb8e/pdf),\n[van den Berg, 2021](https://quantum-journal.org/papers/q-2021-06-07-469/pdf/) (and \nquantum amplitude estimation [Suzuki et al, 2019](https://arxiv.org/abs/1904.10246)) can be implemented as an instance of Bayesian inference. Shots are generated from a quantum circuit with likelihood\n$$p(m \\mid \\phi, k, \\beta) = \\frac12\\left(1 + (1 - q)\\cos(k\\phi + \\beta - m \\pi)\\right),$$\nwhere $m \\in \\{0,1\\}$ is the binary _shot_ produced by the quantum device, $\\phi$ is the unknown underlying _phase_, $q$ is a noise parameter or error rate. $k$ and $\\beta$ are circuit parameters that are chosen by the user (or `phayes`).\n\nStarting with a uniform prior over $\\phi$, `phayes` uses Bayesian inference to hone in on the true value (with uncertainty quantification) through repeated measurements.\n\n\n## Install\n\n```\npip install phayes\n```\n\n## Bayesian updates\n\nThe core functions are `phayes.get_k_and_beta` and `phayes.update`, which determine the experiment parameters and then update the posterior distribution in light of a new measurement (or series of measurements)\n\n```python\nfrom jax import numpy as jnp\nimport phayes\n\nnum_shots = 100\n\nposterior_state = phayes.init()\nfor _ in range(num_shots):\n    k, beta = phayes.get_k_and_beta(posterior_state)\n    m = get_shot(k, beta)\n    posterior_state = phayes.update(posterior_state, m, k, beta)\n```\nHere the function `get_shot` executes the quantum circuit above and returns a binary shot (or multiple shots) according the likelihood $p(m\\mid \\phi, k, \\beta)$.\n\n\n\n## There's more\n\nThe probability density function can be visualised easily\n\n```python\nprior_state = phayes.init()\nm = jnp.array([0, 1, 1, 0, 0, 1])\nk = jnp.array([1, 4, 3, 8, 5, 10])\nbeta = jnp.array([1.4, 0.6, 1.2, 1.1, 1.9, 0.3])\n\nposterior_state = phayes.update(prior_state, m, k, beta)\n\nimport matplotlib.pyplot as plt\nlinsp = jnp.linspace(-jnp.pi, jnp.pi, 1000)\npdf = phayes.pdf(linsp, posterior_state)\nplt.plot(linsp, pdf)\n```\n\n\u003cimg src=\"examples/bpe_posterior.png\" width=\"500\"\u003e\n\n\n`phayes` also has a host of other useful functions\n\n```python\nposterior_mean = phayes.circular_mean(posterior_state)\nposterior_circular_variance = phayes.circular_variance(posterior_state)\nposterior_holevo_variance = phayes.holevo_variance(posterior_state)\n```\n\nExample notebooks can be found in the [examples](examples) folder.\n\n\n## Precision\n\nBy default [JAX uses 32-bit precision](https://jax.readthedocs.io/en/latest/notebooks/Common_Gotchas_in_JAX.html#double-64bit-precision), \nfor phase estimation experiments you may well want to enable 64-bit precision by \nadding the following to the top of your script\n```python\nfrom jax.config import config\nconfig.update(“jax_enable_x64”, True)\n```\n\n\n## Citation\n\n```\n@software{phayes,\nauthor={Duffield, Samuel},\ntitle={phayes: A python package for easy and efficient Bayesian quantum phase estimation},\nyear={2023},\nurl={https://github.com/CQCL/phayes}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcqcl%2Fphayes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcqcl%2Fphayes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcqcl%2Fphayes/lists"}