-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into alvaro/merge
- Loading branch information
Showing
131 changed files
with
10,351 additions
and
9,479 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Deploy docs | ||
name: docs | ||
|
||
on: | ||
workflow_dispatch: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,3 +136,6 @@ data/ | |
|
||
# Debugging & Testing | ||
debug/ | ||
|
||
# Nix | ||
.devenv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# executable | ||
example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# generated | ||
cqibolab.c | ||
qibolab.pc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.