Skip to content

Commit d1eee86

Browse files
committed
init: hello world, quantum qrmi-sampler
This is a demo app that will use qrmi-go to run a simple demo workload. I am creating it because I need a quantum workload (in a container) to test with fluence, which now has support for adding quantum devices (err, APIs for now). Signed-off-by: vsoch <vsoch@users.noreply.github.com>
0 parents  commit d1eee86

17 files changed

Lines changed: 622 additions & 0 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Dev environment for qrmi-sampler: Go + Rust + the QRMI native library.
2+
# No flux-sched here — this repo is a standalone quantum workload.
3+
FROM mcr.microsoft.com/devcontainers/base:bookworm
4+
5+
ENV DEBIAN_FRONTEND=noninteractive
6+
RUN apt-get update && apt-get install -y --no-install-recommends \
7+
curl git build-essential pkg-config ca-certificates wget \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
# Go
11+
RUN wget -q https://go.dev/dl/go1.26.0.linux-amd64.tar.gz \
12+
&& tar -C /usr/local -xzf go1.26.0.linux-amd64.tar.gz && rm go1.26.0.linux-amd64.tar.gz
13+
ENV PATH=$PATH:/usr/local/go/bin:/home/vscode/go/bin
14+
15+
# Rust (QRMI pins its toolchain via rust-toolchain.toml)
16+
ENV RUSTUP_HOME=/usr/local/rustup CARGO_HOME=/usr/local/cargo PATH=/usr/local/cargo/bin:$PATH
17+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
18+
| sh -s -- -y --no-modify-path --profile minimal --default-toolchain 1.91 \
19+
&& chmod -R a+rwX /usr/local/rustup /usr/local/cargo
20+
21+
# QRMI native library -> /usr/local/{include,lib}
22+
ARG QRMI_REPO=https://github.com/qiskit-community/qrmi
23+
ARG QRMI_REF=main
24+
RUN git clone ${QRMI_REPO} /opt/qrmi && cd /opt/qrmi && git checkout ${QRMI_REF} \
25+
&& cargo build --locked --release \
26+
&& install -d /usr/local/include /usr/local/lib \
27+
&& install -m 0644 qrmi.h /usr/local/include/qrmi.h \
28+
&& install -m 0644 target/release/libqrmi.a /usr/local/lib/libqrmi.a \
29+
&& install -m 0755 target/release/libqrmi.so /usr/local/lib/libqrmi.so && ldconfig
30+
ENV LD_LIBRARY_PATH=/usr/local/lib

.devcontainer/devcontainer.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "qrmi-sampler",
3+
"build": { "dockerfile": "Dockerfile" },
4+
"remoteEnv": {
5+
"CGO_ENABLED": "1",
6+
"CGO_CFLAGS": "-I/usr/local/include",
7+
"CGO_LDFLAGS": "-L/usr/local/lib"
8+
},
9+
"customizations": {
10+
"vscode": {
11+
"extensions": ["golang.go", "rust-lang.rust-analyzer"]
12+
}
13+
},
14+
"postCreateCommand": "go version && cargo --version"
15+
}

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.git/
2+
.github/
3+
.devcontainer/
4+
*.md
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: build-deploy
2+
3+
on:
4+
push:
5+
branches: [main]
6+
tags: ["v*"]
7+
pull_request:
8+
branches: [main]
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
env:
15+
REGISTRY: ghcr.io
16+
IMAGE_NAME: ${{ github.repository }} # converged-computing/qrmi-sampler
17+
18+
jobs:
19+
build-deploy:
20+
runs-on: ubuntu-latest
21+
permissions:
22+
contents: read
23+
packages: write
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
28+
- name: Set up Docker Buildx
29+
uses: docker/setup-buildx-action@v3
30+
31+
- name: Log in to GHCR
32+
# Skip login on PRs from forks (no package write); still builds below.
33+
if: github.event_name != 'pull_request'
34+
uses: docker/login-action@v3
35+
with:
36+
registry: ${{ env.REGISTRY }}
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Image metadata (tags, labels)
41+
id: meta
42+
uses: docker/metadata-action@v5
43+
with:
44+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
45+
tags: |
46+
type=ref,event=branch
47+
type=ref,event=pr
48+
type=semver,pattern={{version}}
49+
type=sha
50+
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
51+
52+
- name: Build and push
53+
uses: docker/build-push-action@v6
54+
with:
55+
context: .
56+
file: ./Dockerfile
57+
# Push everywhere except pull requests (which only build).
58+
push: ${{ github.event_name != 'pull_request' }}
59+
tags: ${{ steps.meta.outputs.tags }}
60+
labels: ${{ steps.meta.outputs.labels }}
61+
cache-from: type=gha
62+
cache-to: type=gha,mode=max

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor
2+
bin

COPYRIGHT

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Intellectual Property Notice
2+
----------------------------
3+
4+
HPCIC DevTools is licensed under the MIT license (LICENSE).
5+
6+
Copyrights and patents in this project are retained by
7+
contributors. No copyright assignment is required to contribute to
8+
HPCIC DevTools.
9+
10+
SPDX usage
11+
------------
12+
13+
Individual files contain SPDX tags instead of the full license text.
14+
This enables machine processing of license information based on the SPDX
15+
License Identifiers that are available here: https://spdx.org/licenses/

Dockerfile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# qrmi-sampler image: build QRMI (Rust) + the Go workload (cgo_qrmi). Links
2+
# libqrmi only — no flux, no Kubernetes libraries. The scheduler is a separate
3+
# concern; this is just a quantum workload container.
4+
5+
# ---------- builder ----------
6+
FROM golang:1.26-bookworm AS builder
7+
RUN apt-get update && apt-get install -y --no-install-recommends \
8+
curl git build-essential pkg-config ca-certificates \
9+
&& rm -rf /var/lib/apt/lists/*
10+
11+
ENV RUSTUP_HOME=/usr/local/rustup CARGO_HOME=/usr/local/cargo PATH=/usr/local/cargo/bin:$PATH
12+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
13+
| sh -s -- -y --no-modify-path --profile minimal --default-toolchain 1.91 \
14+
&& chmod -R a+rwX /usr/local/rustup /usr/local/cargo
15+
16+
ARG QRMI_REPO=https://github.com/qiskit-community/qrmi
17+
ARG QRMI_REF=main
18+
RUN git clone ${QRMI_REPO} /opt/qrmi && cd /opt/qrmi && git checkout ${QRMI_REF} \
19+
&& cargo build --locked --release \
20+
&& install -d /usr/local/include /usr/local/lib \
21+
&& install -m 0644 qrmi.h /usr/local/include/qrmi.h \
22+
&& install -m 0644 target/release/libqrmi.a /usr/local/lib/libqrmi.a \
23+
&& install -m 0755 target/release/libqrmi.so /usr/local/lib/libqrmi.so && ldconfig
24+
25+
WORKDIR /src
26+
COPY go.mod go.sum* ./
27+
RUN go mod download || true
28+
COPY . .
29+
RUN CGO_ENABLED=1 CGO_CFLAGS="-I/usr/local/include" CGO_LDFLAGS="-L/usr/local/lib" \
30+
go build -tags cgo_qrmi -ldflags '-w' -o /bin/qrmi-sampler .
31+
32+
# ---------- runtime ----------
33+
FROM debian:bookworm-slim AS runtime
34+
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates \
35+
&& rm -rf /var/lib/apt/lists/*
36+
COPY --from=builder /usr/local/lib/libqrmi.so /usr/local/lib/libqrmi.so
37+
RUN ldconfig
38+
COPY --from=builder /bin/qrmi-sampler /bin/qrmi-sampler
39+
# Default job: tiny single-qubit sx circuit. Override by mounting your own input
40+
# and setting QRMI_SAMPLER_INPUT.
41+
COPY testdata/sampler_input.json /etc/sampler/sampler_input.json
42+
ENTRYPOINT ["/bin/qrmi-sampler"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022-2023 LLNS, LLC and other HPCIC DevTools Developers.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# qrmi-sampler — a standalone quantum workload (qrmi-go, no flux, no k8s libs).
2+
QRMI_PREFIX ?= /usr/local
3+
IMG ?= ghcr.io/converged-computing/qrmi-sampler:latest
4+
5+
CGO_CFLAGS = -I$(QRMI_PREFIX)/include
6+
CGO_LDFLAGS = -L$(QRMI_PREFIX)/lib
7+
8+
.PHONY: build
9+
build: ## Build the qrmi-sampler binary (needs the QRMI native library)
10+
CGO_ENABLED=1 CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" \
11+
go build -tags cgo_qrmi -o bin/qrmi-sampler .
12+
13+
.PHONY: test
14+
test: ## Pure-Go unit tests (no QRMI library needed)
15+
go test ./...
16+
17+
.PHONY: image
18+
image: ## Build the container image
19+
docker build -t $(IMG) .
20+
21+
.PHONY: run
22+
run: build ## Build and run locally (set QRMI_BACKEND + IBM creds first)
23+
QRMI_SAMPLER_INPUT=testdata/sampler_input.json ./bin/qrmi-sampler
24+
25+
.PHONY: help
26+
help:
27+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
28+
awk 'BEGIN{FS=":.*?## "}{printf " %-10s %s\n", $$1, $$2}'

NOTICE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
This work was produced under the auspices of the U.S. Department of
2+
Energy by Lawrence Livermore National Laboratory under Contract
3+
DE-AC52-07NA27344.
4+
5+
This work was prepared as an account of work sponsored by an agency of
6+
the United States Government. Neither the United States Government nor
7+
Lawrence Livermore National Security, LLC, nor any of their employees
8+
makes any warranty, expressed or implied, or assumes any legal liability
9+
or responsibility for the accuracy, completeness, or usefulness of any
10+
information, apparatus, product, or process disclosed, or represents that
11+
its use would not infringe privately owned rights.
12+
13+
Reference herein to any specific commercial product, process, or service
14+
by trade name, trademark, manufacturer, or otherwise does not necessarily
15+
constitute or imply its endorsement, recommendation, or favoring by the
16+
United States Government or Lawrence Livermore National Security, LLC.
17+
18+
The views and opinions of authors expressed herein do not necessarily
19+
state or reflect those of the United States Government or Lawrence
20+
Livermore National Security, LLC, and shall not be used for advertising
21+
or product endorsement purposes.

0 commit comments

Comments
 (0)