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.39.tar.gz (63.1 kB view details)

Uploaded Source

Built Distribution

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

qlasskit-0.1.39-py3-none-any.whl (96.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: qlasskit-0.1.39.tar.gz
  • Upload date:
  • Size: 63.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for qlasskit-0.1.39.tar.gz
Algorithm Hash digest
SHA256 69f0926334f2173fde006947164d72739636a1a4f6e1e2551d36fab0a6ce9aa3
MD5 8156455a2e4dfc5ef9dd280c277965ca
BLAKE2b-256 0100e382d5d20a1765de0b6c1315babc1be15da6ec26b9f4836b1dc13e9021d2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: qlasskit-0.1.39-py3-none-any.whl
  • Upload date:
  • Size: 96.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for qlasskit-0.1.39-py3-none-any.whl
Algorithm Hash digest
SHA256 97dc15e04a6e260cf527631833553b9faa170ec65e4b077fe55638d879d6c117
MD5 e825ad372194dab063a058a384dacb5e
BLAKE2b-256 cc93f64b587eb1510bfb2ede6cf0b942a9a4a551336a459708b29e409f67ac47

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