Skip to content

bloch-labs/bloch

Repository files navigation

Bloch - A Modern Strongly Typed, Hybrid Quantum Programming

Bloch is a strongly typed, interpreted, hybrid quantum programming language from Bloch Labs. The language is designed to feel familiar to systems developers while staying hardware-agnostic, so you can move from research sketches to production-grade circuits without switching stacks.

Highlights

  • Seamless classical/quantum integration with clear type boundaries.
  • Readable, expressive syntax that stays approachable under load.
  • Hardware-agnostic execution across simulators and future hardware backends.
  • Write once, run anywhere as targets evolve.

See It In Action

Demo Prepare an entangled Bell state, then measure both qubits 8192 times using a tracked array to observe the expected 00 / 11 correlation.

@quantum
function createBellState(qubit a, qubit b) -> void {
    h(a);
    cx(a, b);
}

function main() -> void {
    @tracked qubit[2] qreg;

    createBellState(qreg[0], qreg[1]);

    bit[2] out = {measure qreg[0], measure qreg[1]};

    echo(out);
}

Get Started

Bloch is available as source plus manually produced release archives until the automated pipeline lands. The instructions below cover installing pre-built artifacts as well as building from source (the developer workflow described in CONTRIBUTING.md).

Install a release build

Linux & macOS

curl -fsSL https://raw.githubusercontent.com/bloch-labs/bloch/HEAD/scripts/install.sh | bash -s -- latest

Swap latest for a specific tag (eg v1.0.0). The script downloads the matching archive for your platform, verifies its checksum, installs the bloch binary into a writable directory, and updates your shell profile if needed. Add INSTALL_DIR=/custom/path before bash to override the destination. You can also self-update later with bloch --update; major version jumps will prompt for confirmation and link the changelog.

Windows

powershell -NoProfile -ExecutionPolicy Bypass -Command "iwr https://raw.githubusercontent.com/bloch-labs/bloch/HEAD/scripts/install.ps1 -UseBasicParsing -OutFile $env:TEMP\\bloch-install.ps1; & $env:TEMP\\bloch-install.ps1 -Version latest"

Swap -Version latest for any tag you want. The script downloads the Windows ZIP, verifies its checksum, installs bloch.exe into %LOCALAPPDATA%\Programs\Bloch by default, and adds that directory to your user PATH (opens in new shells). You can self-update later with bloch --update; major version jumps prompt for confirmation and show the changelog link.

Build from source

Linux & macOS

git clone https://github.com/bloch-labs/bloch.git
cd bloch
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --parallel
ctest --test-dir build --output-on-failure

Run the compiler against an example with ./build/bin/bloch examples/02_bell_state.bloch.

Windows (Visual Studio)

git clone https://github.com/bloch-labs/bloch.git
cd bloch
cmake -S . -B build -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release --parallel
ctest --test-dir build --config Release --output-on-failure

This produces a build/Bloch.sln you can open directly in Visual Studio for editing and debugging. The bloch.exe binary is placed in build/bin/Release/.

Additional generator options (Ninja, CLion toolchains, etc.) are covered in CONTRIBUTING.md.

Code Layout

  • bloch::core (src/bloch/core/*): lexer, Pratt parser, AST, and semantic analysis.
  • bloch::runtime (src/bloch/runtime/*): runtime evaluator plus the OpenQASM/statevector simulator.
  • bloch::support (src/bloch/support/*): errors, feature flags, and lightweight helpers shared across layers.
  • bloch::update (src/bloch/update/*): self-update plumbing used by the CLI. Includes now follow this structure (e.g., #include "bloch/core/parser/parser.hpp"), and new components should live in the matching namespace.

User Documentation

docs.bloch-labs.com/bloch/overview

Developer Documenation

Wiki

Releases

v1.0.0 will ship manually while we build the release pipeline. Run the Manual Packager workflow (Actions → “Manual Packager”) against the desired branch/tag to produce Linux, macOS, and Windows archives plus checksums; the GitHub Wiki documents the end-to-end checklist.

VS Code Extension

bloch-labs/bloch-vscode

Contributing

Contributions are welcome! CONTRIBUTING.md covers the development environment, conventions, and the lightweight review process we follow while the language is in active development.

How to Cite

  • If you use Bloch in research, cite it via the repository’s CITATION.cff file (GitHub exposes a “Cite this repository” button) or copy the metadata directly into your BibTeX database. The entry tracks the software release and the forthcoming JOSS article so reviewers can attribute the correct artifact.

Community

Acknowledgements

  • cpp-httplib (MIT) for HTTPS calls used in update checks and downloads.
  • OpenSSL for TLS support during release downloads (prefer statically linked in shipped binaries to avoid runtime deps).

License

Bloch is licensed under the Apache 2.0 license.