{"id":16345476,"url":"https://github.com/averyanalex/quantpiler","last_synced_at":"2025-03-16T15:30:53.336Z","repository":{"id":180785688,"uuid":"665622492","full_name":"averyanalex/quantpiler","owner":"averyanalex","description":"Сompiler of classical algorithms into oracles for quantum computing","archived":false,"fork":false,"pushed_at":"2024-06-25T18:37:14.000Z","size":471,"stargazers_count":10,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-12T00:31:58.292Z","etag":null,"topics":["quantum-computing"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/averyanalex.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}},"created_at":"2023-07-12T15:58:11.000Z","updated_at":"2024-09-23T11:23:27.000Z","dependencies_parsed_at":"2023-07-12T21:01:34.669Z","dependency_job_id":"d44f6018-d160-4d7a-a5ce-3a9a0b92517d","html_url":"https://github.com/averyanalex/quantpiler","commit_stats":{"total_commits":100,"total_committers":2,"mean_commits":50.0,"dds":0.12,"last_synced_commit":"5d82510ac01efdee8916b7349a3455131b689ebc"},"previous_names":["averyanalex/quantpiler"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/averyanalex%2Fquantpiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/averyanalex%2Fquantpiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/averyanalex%2Fquantpiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/averyanalex%2Fquantpiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/averyanalex","download_url":"https://codeload.github.com/averyanalex/quantpiler/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221665199,"owners_count":16860191,"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":["quantum-computing"],"created_at":"2024-10-11T00:31:57.205Z","updated_at":"2024-10-27T10:49:17.362Z","avatar_url":"https://github.com/averyanalex.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![CI](https://github.com/averyanalex/quantpiler/actions/workflows/ci.yml/badge.svg)](https://github.com/averyanalex/quantpiler/actions/workflows/ci.yml)\n[![License](https://img.shields.io/github/license/averyanalex/quantpiler.svg)](https://opensource.org/license/agpl-v3)\n[![Version](https://img.shields.io/pypi/v/quantpiler.svg)](https://pypi.org/project/quantpiler/)\n\n# Сompiler of classical algorithms into oracles for quantum computing\n\n## Achievements:\n\n- CRC32 hash function (4 byte input) - 116 qubits.\n\n## Architecture:\n\n1. Building expression.\n2. Optimizing expression.\n3. Constructing list of logical gates (logical expressions) for each bit of\n   optimized expression.\n4. Logical gates optimization (minimizing unique logic operations and qubit\n   allocations).\n5. Generation of a quantum circuit from a DAG of logical gates.\n\n## Authors:\n\n- Alexander Averyanov - author\n- Evgeny Kiktenko - mentor\n- Dmitry Ershov - helped with the optimizer design\n\n## Example:\n\n```python\nimport quantpiler\n\nx_len = 4\nx = quantpiler.argument(\"x\", x_len)\n\na = 6\n# N = 2**4\n\nprod = 1\nfor i in range(x_len):\n    prod = ((x \u003e\u003e i) \u0026 1).ternary(prod * a**(2**i), prod) \u0026 0b1111\n\ncirc = prod.compile()\nqc = quantpiler.circuit_to_qiskit(circ)\n\nqc.draw(\"mpl\")\n```\n\n![Resulting circuit](https://raw.githubusercontent.com/averyanalex/quantpiler/main/example.png)\n\n```python\n# returning ancillas and arguments to their original state\nrqc = quantpiler.circuit_to_qiskit(circ, rev=True)\n\nrqc.draw(\"mpl\")\n```\n\n![Resulting reversed circuit](https://raw.githubusercontent.com/averyanalex/quantpiler/main/example-rev.png)\n\n## User guide\n\n### Installation\n\n```shell\npip install quantpiler\n```\n\nBinary releases on PyPI only available for Windows (x86, x86_64) and\nGNU/Linux (x86_64).\n\nNow you can import library in Python:\n\n```python\nimport quantpiler\n```\n\n### Creating input variables\n\n```python\na = quantpiler.argument(\"a\", 2)\nb = quantpiler.argument(\"b\", 4)\n```\n\nThis will create argument \"a\" with length of 2 qubits and \"b\" with length of 4\nqubits. You can't use arguments with same name but with\ndifferent lengths.\n\n### Expressions\n\nAny argument variable, constant, or combination thereof is an expression.\nExpressions are actually lists of logic gates representing each bit. For\nexample, `a ^ b` is effectively `[[a[0] ^ b[0], [a[1] ^ b[1], b[2], b[3]]`.\n\n#### Output expression lengths\n\nLet's `a` -- length of first operand, `b` -- length (value for bitshifts) of\nsecond operand.\n\n| Name           | Notation | Length        |\n| -------------- | -------- | ------------- |\n| Binary invert  | ~        | a             |\n| Bitwise XOR    | ^        | max(a, b)     |\n| Bitwise OR     | \\|       | max(a, b)     |\n| Bitwise AND    | \u0026        | min(a, b)     |\n| Sum            | +        | max(a, b) + 1 |\n| Product        | \\*       | a + b         |\n| Right bitshift | \u003e\u003e       | a - b         |\n| Left bitshift  | \u003c\u003c       | a + b         |\n\nLength is the **maximum possible** length of result. Actual length depends on\noptimizer decitions: for example, the length of `a ^ a` will be 0 (no qubits,\nempty expression).\n\n#### Estimating length of expression:\n\n```python\n# you can use builtin python's len to get estimated expression's length\nlength = len(a ^ b + 1)\n```\n\nPlease note that this is an **estimated** length as actual length may vary depending\noptimizer solutions.\n\n#### Debugging expression:\n\n```python\nprint(str(a ^ b + 1))\n```\n\nor, for jupyter:\n\n```python\na ^ b + 1\n```\n\nThis will print `(^ \"a(2)\" (+ 1 \"4(2)\"))` for `a` of length 2 and `b` of length 4.\n\n### Bitwise binary operations\n\n```python\nr = ~a\nr = a ^ b\nr = a | b\nr = a \u0026 b\n```\n\nYou can also do this with constants:\n\n```python\nr = 0b101 ^ a\nb |= 1\nr = b \u0026 0b11\n```\n\n### Bit shifting\n\n```python\nr = a \u003c\u003c 2\nr = b \u003e\u003e 3\n```\n\nPlease note that only constant distance shifting is supported at this time.\n\n### Arithmetic operations\n\n```python\nr = a + b\nr = 2 * a * b\n```\n\n### Ternary operations\n\nIf you want to emulate if statements, i.e.\n\n```python\nif cond:\n    r = a + b\nelse:\n    r = b \u0026 0b11\n```\n\nyou can use ternary operators:\n\n```python\nr = cond.ternary(a + b, b \u0026 0b11)\n```\n\nNote that cond must be an expression exactly 1 qubit long. You can\nachieve this by using bitwise and with 1.\n\n### Compiling\n\nLet's compile something:\n\n```python\nr = a ^ b + 3\n\n# internal circuit representation\ncirc = r.compile()\n\n# QuantumCircuit from qiskit\nqc = quantpiler.circuit_to_qiskit(circ)\n\n# let's draw our circuit\nqc.draw(\"mpl\")\n```\n\n![Compiled a ^ b + 1](https://raw.githubusercontent.com/averyanalex/quantpiler/main/guide.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faveryanalex%2Fquantpiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faveryanalex%2Fquantpiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faveryanalex%2Fquantpiler/lists"}