Skip to content

Commit

Permalink
Merge branch 'main' into alvaro/merge
Browse files Browse the repository at this point in the history
  • Loading branch information
aorgazf committed Feb 14, 2024
2 parents 9e97a44 + cbd1f19 commit 6b969c5
Show file tree
Hide file tree
Showing 131 changed files with 10,351 additions and 9,479 deletions.
9 changes: 9 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs="
fi

nix_direnv_watch_file flake.nix
nix_direnv_watch_file flake.lock
if ! use flake . --impure; then
echo "devenv could not be built. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2
fi
45 changes: 45 additions & 0 deletions .github/workflows/capi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Test Qibolab C API
name: C API

on:
push:
workflow_dispatch:

jobs:
tests:
strategy:
matrix:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Prepare virtual environment
run: |
python -m venv env
- name: Install dependencies
run: |
# build dependencies
pip install cffi
# runtime dependencies
. env/bin/activate
pip install cffi # also a runtime dep
pip install .
- name: Build & install library
working-directory: capi
run: |
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=$(realpath ../env)
cmake --build build
cmake --install build
- name: Build & run example
working-directory: capi/examples
run: |
. ../../env/bin/activate
export PKG_CONFIG_PATH=${VIRTUAL_ENV}/lib/pkgconfig/:${PKG_CONFIG_PATH}:
export LD_LIBRARY_PATH=${VIRTUAL_ENV}/lib/:${LD_LIBRARY_PATH}:
make
./example
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy docs
name: docs

on:
workflow_dispatch:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rules.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# A single CI script with github workflow
name: Tests without qpu
name: tests

on:
workflow_dispatch:
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/rustapi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Test Qibolab Rust API
name: Rust API

on:
push:
workflow_dispatch:

jobs:
tests:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Prepare virtual environment
run: |
pip install .
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Check and lint
working-directory: crate
run: |
cargo check
cargo clippy --all-targets
- name: Build & run example
working-directory: crate
run: |
cargo run --example example
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,6 @@ data/

# Debugging & Testing
debug/

# Nix
.devenv
12 changes: 8 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ repos:
- id: check-toml
- id: debug-statements
- repo: https://github.com/psf/black
rev: 23.11.0
rev: 24.1.1
hooks:
- id: black
args:
- --line-length=120
- repo: https://github.com/pycqa/isort
rev: 5.13.1
rev: 5.13.2
hooks:
- id: isort
args: ["--profile", "black"]
- repo: https://github.com/PyCQA/docformatter
rev: v1.7.5
hooks:
- id: docformatter
additional_dependencies: [tomli]
args: [--in-place, --config, ./pyproject.toml]
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
Expand Down
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
# Qibolab

![Tests](https://github.com/qiboteam/qibolab/workflows/Tests/badge.svg)
[![codecov](https://codecov.io/gh/qiboteam/qibolab/branch/main/graph/badge.svg?token=11UENAPBPH)](https://codecov.io/gh/qiboteam/qibolab)
[![DOI](https://zenodo.org/badge/241307936.svg)](https://zenodo.org/badge/latestdoi/241307936)
![PyPI - Version](https://img.shields.io/pypi/v/qibolab)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/qibolab)

Qibolab is the dedicated [Qibo](https://github.com/qiboteam/qibo) backend for
the automatic deployment of quantum circuits on quantum hardware.

Some of the key features of Qibolab are:

* Deploy Qibo models on quantum hardware easily.
* Create custom experimental drivers for custom lab setup.
* Support multiple heterogeneous platforms.
* Use existing calibration procedures for experimentalists.
- Deploy Qibo models on quantum hardware easily.
- Create custom experimental drivers for custom lab setup.
- Support multiple heterogeneous platforms.
- Use existing calibration procedures for experimentalists.

## Documentation

[![docs](https://github.com/qiboteam/qibolab/actions/workflows/publish.yml/badge.svg)](https://qibo.science/qibolab/stable/)

The qibolab backend documentation is available at [https://qibo.science/qibolab/stable/](https://qibo.science/qibolab/stable/).

## Minimum working example
Expand Down Expand Up @@ -58,10 +60,6 @@ platform = create_platform("my_platform")

# Connects to lab instruments using the details specified in the calibration settings.
platform.connect()
# Configures instruments using the loaded calibration settings.
platform.setup()
# Turns on the local oscillators
platform.start()

# Execute a pulse sequence
options = ExecutionParameters(nshots=1000)
Expand All @@ -70,8 +68,6 @@ results = platform.execute_pulse_sequence(sequence, options)
# Print the acquired shots
print(results.samples)

# Turn off lab instruments
platform.stop()
# Disconnect from the instruments
platform.disconnect()
```
Expand Down Expand Up @@ -106,4 +102,7 @@ for _ in range(5):

## Citation policy

[![arXiv](https://img.shields.io/badge/arXiv-2308.06313-b31b1b.svg)](https://arxiv.org/abs/2308.06313)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.10572987.svg)](https://doi.org/10.5281/zenodo.10572987)

If you use the package please refer to [the documentation](https://qibo.science/qibo/stable/appendix/citing-qibo.html#publications) for citation instructions.
16 changes: 16 additions & 0 deletions capi/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# compiled
*.dylib
*.so
*.dll

CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
38 changes: 38 additions & 0 deletions capi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
cmake_minimum_required (VERSION 3.0.2...3.28.1)

SET(CMAKE_SKIP_BUILD_RPATH FALSE)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")

project(libqibolab)

set(VERSION "\"0.0.1\"")

find_package(Python3 COMPONENTS Interpreter Development)

# running the cffi builder
if (NOT EXISTS ${PROJECT_SOURCE_DIR/src/cqibolab.cc})
execute_process(COMMAND ${Python3_EXECUTABLE} ${PROJECT_SOURCE_DIR}/src/build.py WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src)
endif()

include_directories(${Python3_INCLUDE_DIRS})
include_directories(src)
add_library(qibolab SHARED ${PROJECT_SOURCE_DIR}/src/cqibolab.c)
target_link_libraries(qibolab ${Python3_LIBRARIES})

# pkg-config
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix "${prefix}")
set(includedir "${prefix}/include")
set(extraincludirs "-I${Python3_INCLUDE_DIRS}")
set(libdir "${prefix}/lib")
set(pythonlibs "${Python3_LIBRARIES}")

configure_file(
"${PROJECT_SOURCE_DIR}/src/qibolab.pc.in"
"${PROJECT_SOURCE_DIR}/src/qibolab.pc"
)

install(FILES ${PROJECT_SOURCE_DIR}/src/qibolab.pc DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/src/qibolab DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
install(TARGETS qibolab LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
30 changes: 30 additions & 0 deletions capi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Qibolab C-API
=============

This repository contains a C library to access Qibolab from programming languages different from Python.

## Installation

Make sure you have installed the `qibolab` module in Python, then in order to install proceed with the usual cmake steps:
```bash
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=<your install prefix>
cmake --build build
cmake --install build
```

## Usage

The compiler flags to include this library in your package can be
retrieved with:
```bash
pkg-config qibolab --cflags
pkg-config qibolab --libs
```

If you installed to a non-standard location, you need to set up the `PKG_CONFIG_PATH` and `LD_LIBRARY_PATH`, e.g.:
```bash
export PKG_CONFIG_PATH=${VIRTUAL_ENV}/lib/pkgconfig/:${PKG_CONFIG_PATH}:
export LD_LIBRARY_PATH=${VIRTUAL_ENV}/lib/:${LD_LIBRARY_PATH}:
```

Sample programs using this library are provided in the `capi/examples/` directory.
16 changes: 16 additions & 0 deletions capi/build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Further compilation instructions

## Shared libraries on MacOS

On MacOS the environment variable `LD_LIBRARY_PATH` is replaced by `DYLD_LIBRARY_PATH`.

## Nix vs Clang

Same of what is specified in the [README](./README.md), but to use the GCC compiler,
which is not necessarily the default (e.g. on MacOS), add a suitable CMake flag

```bash
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=<your install prefix> -D CMAKE_CXX_COMPILER=g++
cmake --build build
cmake --install build
```
2 changes: 2 additions & 0 deletions capi/examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# executable
example
12 changes: 12 additions & 0 deletions capi/examples/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Makefile example

CFLAGS=`pkg-config qibolab --cflags`
LIBS=`pkg-config qibolab --libs`

all: example

%: %.c
$(CC) $(CFLAGS) -o $@ $< $(LIBS)

clean:
rm -rf example
25 changes: 25 additions & 0 deletions capi/examples/example.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// This file is part of Qibolab
#include <stdio.h>
#include "qibolab/qibolab.h"

int main() {

int* qasm_res = execute_qasm(
"OPENQASM 2.0;" \
"include \"qelib1.inc\";" \
"qreg q[3];" \
"creg a[2];" \
"cx q[0],q[2];" \
"x q[1];" \
"swap q[0],q[1];" \
"cx q[1],q[0];" \
"measure q[0] -> a[0];" \
"measure q[2] -> a[1];",
"dummy", 10);

printf("Samples:\n");
for (int i = 0; i < 2*10; i++)
printf("%d\n", qasm_res[i]);

return 0;
}
3 changes: 3 additions & 0 deletions capi/src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# generated
cqibolab.c
qibolab.pc
20 changes: 20 additions & 0 deletions capi/src/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This file is part of Qibolab
import cffi

ffibuilder = cffi.FFI()

with open("qibolab/qibolab.h") as f:
ffibuilder.embedding_api(f.read())

ffibuilder.set_source(
"cqibolab",
r"""
#include "qibolab/qibolab.h"
""",
source_extension=".c",
)

with open("wrapper.py") as f:
ffibuilder.embedding_init_code(f.read())

ffibuilder.emit_c_code("cqibolab.c")
12 changes: 12 additions & 0 deletions capi/src/qibolab.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
includedir=@includedir@
extraincludirs=@extraincludirs@
libdir=@libdir@
pythonlibs=@pythonlibs@

Name: qibolab
Description: The Qibolab C-API library
Version: @VERSION@
Cflags: -I@includedir@ @extraincludirs@
Libs: -L@libdir@ -lqibolab @pythonlibs@
5 changes: 5 additions & 0 deletions capi/src/qibolab/qibolab.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* Qibolab C API
*/

extern int *execute_qasm(const char *circuit, const char *platform, int nshots);
Loading

0 comments on commit 6b969c5

Please sign in to comment.