Skip to main content

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)

Metadata

Release files for qlasskit 0.1.39

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.1.39
File Size Uploaded
qlasskit-0.1.39.tar.gz 63.1 kB Details

Built distribution (wheel)

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

Total release size: 160.0 kB

Release files / qlasskit-0.1.39.tar.gz

Download URL qlasskit-0.1.39.tar.gz
Size 63.1 kB
Tags Source
SHA-256 checksum
How to use checksums
69f0926334f2173fde006947164d72739636a1a4f6e1e2551d36fab0a6ce9aa3
BLAKE2b-256 checksum
How to use checksums
0100e382d5d20a1765de0b6c1315babc1be15da6ec26b9f4836b1dc13e9021d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

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

Download URL qlasskit-0.1.39-py3-none-any.whl
Size 96.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
97dc15e04a6e260cf527631833553b9faa170ec65e4b077fe55638d879d6c117
BLAKE2b-256 checksum
How to use checksums
cc93f64b587eb1510bfb2ede6cf0b942a9a4a551336a459708b29e409f67ac47
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release history Release notifications | RSS feed

This release

0.1.39 This release

2 release files

0.1.38

2 release files

0.1.37

2 release files

0.1.34

2 release files

0.1.31

2 release files

0.1.27

2 release files

0.1.26

1 release file

0.1.20

2 release files

0.1.19

2 release files

0.1.17

2 release files

0.1.16

2 release files

0.1.15

2 release files

0.1.12

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

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