Skip to main content

A python-to-quantum compiler

Project description

Qlasskit

Logo

Unitary Fund CI Status PyPI - Version License: Apache 2.0 Discord Codacy Badge Downloads

Qlasskit is a Python library that allows quantum developers to write classical algorithms in pure Python and translate them into unitary operators (gates) for use in quantum circuits, using boolean expressions as intermediate form.

This tool will be useful for any algorithm that relies on a 'blackbox' function and for describing the classical components of a quantum algorithm.

Qlasskit implements circuit / gate exporters for Qiskit, Cirq, Qasm, Sympy and Pennylane.

Qlasskit also support exporting to Binary Quadratic Models (bqm, ising and qubo) ready to be used in quantum annealers, ising machines, simulators, etc.

Transformations

pip install qlasskit

For a quickstart, read the quickstart and examples notebooks from the documentation: https://dakk.github.io/qlasskit.

from qlasskit import qlassf, Qint 

@qlassf
def h(k: Qint[4]) -> bool:
    h = True
    for i in range(4):
        h = h and k[i]
    return h

Qlasskit will take care of translating the function to boolean expressions, simplify them and translate to a quantum circuit.

Grover

Then, we can use grover to find which h(k) returns True:

from qlasskit.algorithms import Grover

algo = Grover(h, True)
qc = algo.circuit().export("circuit", "qiskit")

And that's the result:

Grover

Qlasskit also offers type abstraction for encoding inputs and decoding results:

counts_readable = algo.decode_counts(counts)
plot_histogram(counts_readable)

Decoded counts

You can also use other functions inside a qlassf:

@qlassf
def equal_8(n: Qint[4]) -> bool:
  return equal_8 == 8

@qlassfa(defs=[equal_8])
def f(n: Qint[4]) -> bool:
  n = n+1 if equal_8(n) else n
  return n

Qlasskit supports complex data types, like tuples and fixed size lists:

@qlassf
def f(a: Tuple[Qint[8], Qint[8]]) -> Tuple[bool, bool]:
  return a[0] == 42, a[1] == 0
@qlassf
def search(alist: Qlist[Qint[2], 4], to_search: Qint[2]):
  for x in alist:
    if x == to_search:
      return True
  return False

Qlasskit function can be parameterized, and the parameter can be bind before compilation:

@qlassf
def test(a: Parameter[bool], b: bool) -> bool:
    return a and b

qf = test.bind(a=True)

Contributing

Read CONTRIBUTING for details.

License

This software is licensed with Apache License 2.0.

Cite

@software{qlasskit2023,
  author = {Davide Gessa},
  title = {qlasskit: a python-to-quantum circuit compiler},
  url = {https://github.com/dakk/qlasskit},
  year = {2023},
}

About the author

Davide Gessa (dakk)

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

qlasskit-0.1.35.tar.gz (61.8 kB view details)

Uploaded Source

Built Distribution

qlasskit-0.1.35-py3-none-any.whl (95.7 kB view details)

Uploaded Python 3

File details

Details for the file qlasskit-0.1.35.tar.gz.

File metadata

  • Download URL: qlasskit-0.1.35.tar.gz
  • Upload date:
  • Size: 61.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for qlasskit-0.1.35.tar.gz
Algorithm Hash digest
SHA256 cb166bfe2b3b3c3890fd52145f7a80c7a47a69bd6923239087a8123c898f1abe
MD5 fb11d396e9b7968000287d6d26538215
BLAKE2b-256 c200eb8bcbd022cda47365ada10f2734ed04accaeb0b948bd11457b7850d50fe

See more details on using hashes here.

File details

Details for the file qlasskit-0.1.35-py3-none-any.whl.

File metadata

  • Download URL: qlasskit-0.1.35-py3-none-any.whl
  • Upload date:
  • Size: 95.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for qlasskit-0.1.35-py3-none-any.whl
Algorithm Hash digest
SHA256 bf9a52dda433e739d8b78d01dc17b0133022a1b9b17e5c4440783a0118db6008
MD5 da94a4686e6342aa159cc5bd801dfbfe
BLAKE2b-256 31ec6c1198a27824df2b59f618e3ddbc5b9ef322fcf33fbcb7eeff9a43bc1ea6

See more details on using hashes here.

Supported by

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