Python building blocks for internal domain specific languages.
Project description
blqs: Building Blocks for Domain Specific Languages
Blqs is a framework for building (internal) domain specific language that can be written in Python. It was inspired by TensorFlow's autograph library, and motivated by the state of the art (circa 2021) in quantum programming frameworks like Cirq and Qiskit.
In short blqs let you define domain specific languages and gives you access to use native
Python features like if
, while
, or for
in these languages. This fills in a missing
feature for Python, which while they do have operator overloading, does not allow for
overloading these built in constructions.
Example:
import blqs
H, M, CX = blqs.Op('H'), blqs.Op('M'), blqs.Op('CX')
@blqs.build
def hello_blqs():
a = blqs.Register('a')
H(0)
M(0, 'a')
if a:
CX(0, 1)
else:
CX(1, 0)
Then, if we call this method, we will produce a blqs.Program
that includes both statements,
like H(0)
but also the if
and else
statements.
program = hello_blqs()
for s in program:
print(type(s))
> prints
> <class 'blqs.instruction.Instruction'>
> <class 'blqs.instruction.Instruction'>
> <class 'blqs.conditional.If'>
Where the last statement contains blocks that hold the CX
statements.
Installation
To install blqs one can simply pip install the appropriate package
pip install blqs
See requirements.txt for the dependencies that blqs will pull in.
Documentation
A good place to get started is to read the introduction to blqs. After that, the ideas and abstractions in blqs are described in the concepts guide. To learn about support for capturing native python code, see refer to the protocols section of the docs. For a quick intro via a jupyter notebook, see hello blqs.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file blqs-0.1.0.tar.gz
.
File metadata
- Download URL: blqs-0.1.0.tar.gz
- Upload date:
- Size: 26.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ed9692dde8730389bbf131dd602616f8d5157c2e5f42337338b5636bbf241c0 |
|
MD5 | 540cc726287cc8b94630f992686b4a7e |
|
BLAKE2b-256 | ccb0102f664a0dea29499d25f53f7688d18ad7dc4aed3be6b15476fdfd1fc4fa |
Provenance
File details
Details for the file blqs-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: blqs-0.1.0-py3-none-any.whl
- Upload date:
- Size: 49.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | edd48314e2788199a1bfdb05cbd94235a3194ad43d57a1d82954ea0c79992a5b |
|
MD5 | 3c12abf3bad44ea0324d63004ce2e19c |
|
BLAKE2b-256 | 85c5fedaaec64f33615eb0f93133058f92038c08ae738a249683380a602ae3f5 |