Skip to main content

Qlasskit

Logo

Unitary Fund CI Status PyPI - Version License: GPL 3.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 General Public License v3.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)

Metadata

Release files for qlasskit 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qlasskit 0.2.1
File Size Uploaded Provenance Actions
qlasskit-0.2.1.tar.gz 74.0 kB Without provenance Details for qlasskit-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for qlasskit 0.2.1
File Interpreter ABI Platform Actions
qlasskit-0.2.1-py3-none-any.whl Python 3 none any Details for qlasskit-0.2.1-py3-none-any.whl

Total release size: 185.0 kB

Release files / qlasskit-0.2.1.tar.gz

Download URL qlasskit-0.2.1.tar.gz
Size 74.0 kB
Tags Source
SHA-256 checksum
How to use checksums
544b536f9ff0ec9ff31a0a02734a39da744c2f0bfda2a797c0a4eccaf450a120
BLAKE2b-256 checksum
How to use checksums
0d514d004e46c824d364771f6ce11c78ed80dea36378d194f2086d69726ab235
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.18

Release files / qlasskit-0.2.1-py3-none-any.whl

Download URL qlasskit-0.2.1-py3-none-any.whl
Size 111.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9e94ae5275cb38ceb1c0ae19512e22febc9a35f27bb41faccb3b80b5e4d9c73c
BLAKE2b-256 checksum
How to use checksums
580313b7762d5abfa7f37e2429d11004c365d566dbdb87cb0c9b7ff2656b0ccf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.18

Security for qlasskit 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page