Skip to main content

Сompiler of classical algorithms into oracles for quantum computing

Project description

CI License Version

Сompiler of classical algorithms into oracles for quantum computing

Achievements:

  • CRC32 hash function (4 byte input) - 318 qubits.

Architecture:

  1. Building expression.
  2. Optimizing expression.
  3. Constructing list of logical gates (logical expressions) for each bit of optimized expression.
  4. Logical gates optimization (minimizing unique logic operations and qubit allocations).
  5. Generation of a quantum circuit from a DAG of logical gates.

Authors:

  • Alexander Averyanov - author
  • Evgeny Kiktenko - mentor
  • Dmitry Ershov - helped with the optimizer design

Example:

import quantpiler

x_len = 4
x = quantpiler.argument("x", x_len)

a = 6
# N = 2**4

prod = 1
for i in range(x_len):
    prod = ((x >> i) & 1).ternary(prod * a**(2**i), prod) & 0b1111

circ = prod.compile()
qc = quantpiler.circuit_to_qiskit(circ)

qc.draw("mpl")

Resulting circuit

# returning ancillas and arguments to their original state
rqc = quantpiler.circuit_to_qiskit(circ, rev=True)

rqc.draw("mpl")

Resulting reversed circuit

User guide

Installation

pip install quantpiler

Binary releases on PyPI only available for Windows (x86, x86_64) and GNU/Linux (x86_64).

Now you can import library in Python:

import quantpiler

Creating input variables

a = quantpiler.argument("a", 2)
b = quantpiler.argument("b", 4)

This will create argument "a" with length of 2 qubits and "b" with length of 4 qubits. You can't use arguments with same name but with different lengths.

Expressions

Any argument variable, constant, or combination thereof is an expression. Expressions are actually lists of logic gates representing each bit. For example, a ^ b is effectively [[a[0] ^ b[0], [a[1] ^ b[1], b[2], b[3]].

Output expression lengths

Let's a -- length of first operand, b -- length (value for bitshifts) of second operand.

Name Notation Length
Binary invert ~ a
Bitwise XOR ^ max(a, b)
Bitwise OR | max(a, b)
Bitwise AND & min(a, b)
Sum + max(a, b) + 1
Product * a + b
Right bitshift >> a - b
Left bitshift << a + b

Length is the maximum possible length of result. Actual length depends on optimizer decitions: for example, the length of a ^ a will be 0 (no qubits, empty expression).

Estimating length of expression:

# you can use builtin python's len to get estimated expression's length
length = len(a ^ b + 1)

Please note that this is an estimated length as actual length may vary depending optimizer solutions.

Debugging expression:

print(str(a ^ b + 1))

or, for jupyter:

a ^ b + 1

This will print (^ "a(2)" (+ 1 "4(2)")) for a of length 2 and b of length 4.

Bitwise binary operations

r = ~a
r = a ^ b
r = a | b
r = a & b

You can also do this with constants:

r = 0b101 ^ a
b |= 1
r = b & 0b11

Bit shifting

r = a << 2
r = b >> 3

Please note that only constant distance shifting is supported at this time.

Arithmetic operations

r = a + b
r = 2 * a * b

Ternary operations

If you want to emulate if statements, i.e.

if cond:
    r = a + b
else:
    r = b & 0b11

you can use ternary operators:

r = cond.ternary(a + b, b & 0b11)

Note that cond must be an expression exactly 1 qubit long. You can achieve this by using bitwise and with 1.

Compiling

Let's compile something:

r = a ^ b + 3

# internal circuit representation
circ = r.compile()

# QuantumCircuit from qiskit
qc = quantpiler.circuit_to_qiskit(circ)

# let's draw our circuit
qc.draw("mpl")

Compiled a ^ b + 1

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quantpiler-0.3.5.tar.gz (116.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

quantpiler-0.3.5-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded PyPymanylinux: glibc 2.28+ x86-64

quantpiler-0.3.5-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded PyPymanylinux: glibc 2.28+ x86-64

quantpiler-0.3.5-pp38-pypy38_pp73-manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded PyPymanylinux: glibc 2.28+ x86-64

quantpiler-0.3.5-cp312-none-win_amd64.whl (521.1 kB view details)

Uploaded CPython 3.12Windows x86-64

quantpiler-0.3.5-cp312-none-win32.whl (465.0 kB view details)

Uploaded CPython 3.12Windows x86

quantpiler-0.3.5-cp312-cp312-manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

quantpiler-0.3.5-cp311-none-win_amd64.whl (516.5 kB view details)

Uploaded CPython 3.11Windows x86-64

quantpiler-0.3.5-cp311-none-win32.whl (466.8 kB view details)

Uploaded CPython 3.11Windows x86

quantpiler-0.3.5-cp311-cp311-manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

quantpiler-0.3.5-cp310-none-win_amd64.whl (516.6 kB view details)

Uploaded CPython 3.10Windows x86-64

quantpiler-0.3.5-cp310-none-win32.whl (466.9 kB view details)

Uploaded CPython 3.10Windows x86

quantpiler-0.3.5-cp310-cp310-manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

quantpiler-0.3.5-cp39-none-win_amd64.whl (517.2 kB view details)

Uploaded CPython 3.9Windows x86-64

quantpiler-0.3.5-cp39-none-win32.whl (466.8 kB view details)

Uploaded CPython 3.9Windows x86

quantpiler-0.3.5-cp39-cp39-manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

quantpiler-0.3.5-cp38-none-win_amd64.whl (516.4 kB view details)

Uploaded CPython 3.8Windows x86-64

quantpiler-0.3.5-cp38-none-win32.whl (467.4 kB view details)

Uploaded CPython 3.8Windows x86

quantpiler-0.3.5-cp38-cp38-manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.28+ x86-64

File details

Details for the file quantpiler-0.3.5.tar.gz.

File metadata

  • Download URL: quantpiler-0.3.5.tar.gz
  • Upload date:
  • Size: 116.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.4.0

File hashes

Hashes for quantpiler-0.3.5.tar.gz
Algorithm Hash digest
SHA256 ec91eb86061310c5c96143e3a2169fc5afb1a4ecefea8629e467e12efb2bf752
MD5 1aea4e51a457fa60f6d3f92a4c57a699
BLAKE2b-256 359e5431bc679b612802daf4cba52766327ece0624c5bb5014816343056ffef8

See more details on using hashes here.

File details

Details for the file quantpiler-0.3.5-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for quantpiler-0.3.5-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 661b72d1fcaddd376af8f0f02d91792cfef13c0646c1b6b7bea52e0c0458a021
MD5 522727b4d04de7f5184b4f1b40123500
BLAKE2b-256 37fa32eb2a4983b0278617d644215fb4767dee87f35d32416e6401190ba6710a

See more details on using hashes here.

File details

Details for the file quantpiler-0.3.5-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for quantpiler-0.3.5-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fa4c3ff0a8c2e017690b50531ed129f4688e6f80cfdf7de55142069558bfed8c
MD5 acdf5878a1bf06f1a826e6f625c08e5a
BLAKE2b-256 7d09033b6ccb6650b9c89f1c6e5ef08f85b1a5194722f42b1f0320875bcd32e0

See more details on using hashes here.

File details

Details for the file quantpiler-0.3.5-pp38-pypy38_pp73-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for quantpiler-0.3.5-pp38-pypy38_pp73-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cc0ac3779b4fb5c5f36279d2182f035f8457e6ae80829b149c74d9464e7537c8
MD5 d7ceb670ad96d7e8b04c73ca983293fe
BLAKE2b-256 9f005d9e0bcf5b2fb5b6401987a5d41720b437ed188af19f4012eb0de3865a18

See more details on using hashes here.

File details

Details for the file quantpiler-0.3.5-cp312-none-win_amd64.whl.

File metadata

File hashes

Hashes for quantpiler-0.3.5-cp312-none-win_amd64.whl
Algorithm Hash digest
SHA256 13cc96d33b503d4df44402bfef87bf283b48ee696fa081109692ab327e4c2e44
MD5 b903649cf835eb70c0c112dc2f61bb1b
BLAKE2b-256 423eff632fdaf068b808c708539da0948b62244d5cc53d7b206aa595dd143c1a

See more details on using hashes here.

File details

Details for the file quantpiler-0.3.5-cp312-none-win32.whl.

File metadata

  • Download URL: quantpiler-0.3.5-cp312-none-win32.whl
  • Upload date:
  • Size: 465.0 kB
  • Tags: CPython 3.12, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.4.0

File hashes

Hashes for quantpiler-0.3.5-cp312-none-win32.whl
Algorithm Hash digest
SHA256 526a3a6517482ac4570fdff72a1456dd257a17dce2878fa708240f1c8c35f8d8
MD5 15fb0b277567a8a2336fb4058f7e9dde
BLAKE2b-256 5706b524ca12a254816004eb0781df796bebed89cfc180bec6718ccd789e7770

See more details on using hashes here.

File details

Details for the file quantpiler-0.3.5-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for quantpiler-0.3.5-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 856774670ce5c4f303498db961e3d28f6c1f0cd37d01d6b856a058f129f742e9
MD5 383805863a103ea33acf5f690eb7e5bc
BLAKE2b-256 7331b86a60cb51dd6f521c7ed05d9de44bb39d0efd649cb1080bb5e30212e02f

See more details on using hashes here.

File details

Details for the file quantpiler-0.3.5-cp311-none-win_amd64.whl.

File metadata

File hashes

Hashes for quantpiler-0.3.5-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 24e6f2a56da1284d03c53f7c7e21a10243f6806de0bf3125a35072b252f8ee06
MD5 75a61cec8379b2f19469643278deea4b
BLAKE2b-256 c0cfc3c784b8c198c683918ded03ac651ec465366d09e3edea69667bc58e2abf

See more details on using hashes here.

File details

Details for the file quantpiler-0.3.5-cp311-none-win32.whl.

File metadata

  • Download URL: quantpiler-0.3.5-cp311-none-win32.whl
  • Upload date:
  • Size: 466.8 kB
  • Tags: CPython 3.11, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.4.0

File hashes

Hashes for quantpiler-0.3.5-cp311-none-win32.whl
Algorithm Hash digest
SHA256 509d17f0a49f7f3fa551c1b8e9b6ce79537d00b1898671d98f2951224518d083
MD5 c3701afe12774c97215ad59b4a77d8e1
BLAKE2b-256 c9e10fae8350dfa4e4f8487a91629125a82705af1643a99f1dcfe531db777f4a

See more details on using hashes here.

File details

Details for the file quantpiler-0.3.5-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for quantpiler-0.3.5-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 01f6fd8f4152da243f9b540e63eeebf37355ec66d1c4f38cefdb552f299fc1f3
MD5 fe32dfbfb7ad4dde20b625bc1a2fba97
BLAKE2b-256 97aa5e340750cf9f45903a062fc3cd1808db1bf9eba7ecd4156611824eb2edbd

See more details on using hashes here.

File details

Details for the file quantpiler-0.3.5-cp310-none-win_amd64.whl.

File metadata

File hashes

Hashes for quantpiler-0.3.5-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 609f23537d48800f4dfcbe1a4b17f8f9f5e3bca588b00ad0bc2069f045451dc0
MD5 37130b168efa5c50ed9e01f73aa0d47b
BLAKE2b-256 e04fe96c1c93ff9af30a5ca40ea515f1311033d75df16b5908f5f7bb548239c0

See more details on using hashes here.

File details

Details for the file quantpiler-0.3.5-cp310-none-win32.whl.

File metadata

  • Download URL: quantpiler-0.3.5-cp310-none-win32.whl
  • Upload date:
  • Size: 466.9 kB
  • Tags: CPython 3.10, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.4.0

File hashes

Hashes for quantpiler-0.3.5-cp310-none-win32.whl
Algorithm Hash digest
SHA256 e662671ab7e011b5a8a308e9b5ed4b9a8bca3147925ae207da0a56e9af831751
MD5 7e4704763b59771d22588445f4d8db13
BLAKE2b-256 2e8673e6feff03dd9026db70154760d24843b30b4e2ff07758b686a51a9c1a39

See more details on using hashes here.

File details

Details for the file quantpiler-0.3.5-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for quantpiler-0.3.5-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b6721ff8b19047af2046fa134ad69b1fb1360ca1715ce6d933c344a8369fb4c9
MD5 227c9a8426af6f0ddca2f8eb77d1320f
BLAKE2b-256 517a00eba2ee3b8dfbceace2de757a8b295e48b991fac01b2b8f1e9f80f30b4b

See more details on using hashes here.

File details

Details for the file quantpiler-0.3.5-cp39-none-win_amd64.whl.

File metadata

File hashes

Hashes for quantpiler-0.3.5-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 c57b3219a234386db2bcc55bbc3ec0a3f40828a61ed3bd0f44764f12f3e71200
MD5 ed8ce9195fa0835a1b5c95deb4deb9b6
BLAKE2b-256 8837b128a1098ab63a8721bf525ff44da1d69e1fd398770a09f99745f6674f99

See more details on using hashes here.

File details

Details for the file quantpiler-0.3.5-cp39-none-win32.whl.

File metadata

  • Download URL: quantpiler-0.3.5-cp39-none-win32.whl
  • Upload date:
  • Size: 466.8 kB
  • Tags: CPython 3.9, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.4.0

File hashes

Hashes for quantpiler-0.3.5-cp39-none-win32.whl
Algorithm Hash digest
SHA256 f25627729fa4b7b9c1f1ffab76f50c974f90ccfedab0586b510da656359f632e
MD5 14f7259a07e9d66684212f9fcc51ad97
BLAKE2b-256 eaf1272858ff3cc43a81d8a86f5cf80c4915ad1284531d6238ad0636cbbf3f1d

See more details on using hashes here.

File details

Details for the file quantpiler-0.3.5-cp39-cp39-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for quantpiler-0.3.5-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fd12909d3172a81ba6b3c880fdd51b9422dd35618569f69b6c74af32ab53dd6b
MD5 b695c77730a6fd9d863b9b1ba68b6f64
BLAKE2b-256 24b6c6a026f285a58b335b5dfb8cac50e2989da51981fa1e829763e852da183d

See more details on using hashes here.

File details

Details for the file quantpiler-0.3.5-cp38-none-win_amd64.whl.

File metadata

File hashes

Hashes for quantpiler-0.3.5-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 bd7e696eae8982106949fddb327d37cc4f0bafba0fef755f12afe3682c28fcc6
MD5 97039845a65f3a2144e5fe8ab424bf24
BLAKE2b-256 60e88e4a7331a1fd0c216980750f57301b672a5d1c05af2476aefa5d60e2181e

See more details on using hashes here.

File details

Details for the file quantpiler-0.3.5-cp38-none-win32.whl.

File metadata

  • Download URL: quantpiler-0.3.5-cp38-none-win32.whl
  • Upload date:
  • Size: 467.4 kB
  • Tags: CPython 3.8, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.4.0

File hashes

Hashes for quantpiler-0.3.5-cp38-none-win32.whl
Algorithm Hash digest
SHA256 da71dd6dc59489640a5140d01b1602ae3578097219eb79219f22c33a27d74610
MD5 aeae91f90956da4071c55a4125249563
BLAKE2b-256 1e04bc3d09682551a9b0eb615bd7197b77934f98c7861831301ba224291c5dbf

See more details on using hashes here.

File details

Details for the file quantpiler-0.3.5-cp38-cp38-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for quantpiler-0.3.5-cp38-cp38-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 73ba24f431e47b4827654d9d6d3c083f4194fcc8d379287b8202ee51f304f427
MD5 a821207ec5ab6f1ba66755eb46a607eb
BLAKE2b-256 d2d98b6412e135ff391bad3378cd6719b0ad1ccdd6a8e6c217c712387b78bcd3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page