Skip to content

About

Pasqal quantum computer integration with Open Cluster Scheduler / Gridware Cluster Scheduler (fka SGE)

Topics

Resources

Stars

2 stars

Watchers

2 watching

Forks

Repository files navigation

QPU-resource

Pasqal-OCS integration

Copyright 2026 Pasqal, HPC Gridware GmbH and its contributors.

Go CLI for QRMI setup on Gridware Cluster Scheduler (GCS) and Open Cluster Scheduler (OCS).

In this workspace, the documented end-to-end path is OCS local validation with Pasqal Cloud (EMU_FREE).

Who This Is For

  • End users:
    • Submit jobs through OCS with qsub -l qpu=EMU_FREE.
    • Start at: docs/quickinstall-testing.md (sections 2 and 3).
  • Admins:
    • Configure Gridware resource state and queue hooks.
    • Start at:
      • docs/quickinstall-testing.md (primary admin runbook)
      • setup-qrmi-support section below
  • Developers:
    • Work on adapter CLI and queue hook code.
    • Start at:
      • src/cmd/gridware-adapter/main.go
      • src/cmd/qrmi-ocs-prolog/main.c (legacy C hook)
      • src/cmd/qrmi-ocs-epilog/main.c (legacy C hook)
      • src/cmd/qrmi-ocs-prolog-go/main.go (Go port)
      • src/cmd/qrmi-ocs-epilog-go/main.go (Go port)

Repository Layout

qpu-resource
├── LICENSE
├── Makefile
├── README.md
├── consumable-issue.md
├── demo
│   └── qrmi
│       └── quickinstall.sh
├── docs
│   ├── plans/
│   └── quickinstall-testing.md
├── go.mod
├── go.sum
├── scripts
│   └── Dockerfile.hooks
├── src
│   ├── cmd
│   │   ├── gridware-adapter
│   │   │   └── main.go
│   │   ├── qrmi-ocs-epilog
│   │   │   └── main.c
│   │   ├── qrmi-ocs-epilog-go (Go port of the epilog hook)
│   │   │   └── main.go
│   │   ├── qrmi-ocs-prolog
│   │   │   └── main.c
│   │   └── qrmi-ocs-prolog-go (Go port of the prolog hook)
│   │       └── main.go
│   └── internal
│       ├── qrmi          (cgo wrapper around libqrmi)
│       └── qrmiocs       (scheduler-side plumbing, no cgo)

What is where:

  • src/cmd/gridware-adapter/main.go: adapter CLI (setup-qrmi-support, ensure-resource, configure-queue-hooks).
  • src/cmd/qrmi-ocs-load-sensor/main.go: optional OCS Load Sensor for dynamic QPU readiness.
  • src/cmd/qrmi-ocs-prolog/main.c: legacy OCS queue prolog hook (resource/env setup + acquire).
  • src/cmd/qrmi-ocs-epilog/main.c: legacy OCS queue epilog hook (release + accounting fields).
  • src/cmd/qrmi-ocs-prolog-go/main.go: Go port of the prolog hook (preferred for new deployments).
  • src/cmd/qrmi-ocs-epilog-go/main.go: Go port of the epilog hook (preferred for new deployments).
  • src/internal/qrmiocs: scheduler-side glue (env, paths, metadata TSV, RUST_LOG mapping). No cgo. Fully unit-tested.
  • src/internal/qrmi: cgo wrapper around libqrmi.so. Compiled only with -tags qrmi.
  • scripts/Dockerfile.hooks: multi-stage Docker build that produces the Go hook binaries plus libqrmi.so.
  • Makefile: make build-go-hooks, make build-adapter, make test, make vet.
  • docs/quickinstall-testing.md: admin runbook for quickinstall + validation.
  • demo/qrmi/quickinstall.sh: runnable smoke commands for quick checks.
  • go.mod and go.sum: Go module and dependency lock state.

Build

The repository ships a Makefile that wraps the Docker-based build flows.

Adapter (no cgo)

make build-adapter
# binary at bin/adapter/adapter

make build-load-sensor
# binary at bin/adapter/qrmi-ocs-load-sensor

Go OCS hooks (cgo against libqrmi.so)

The Go ports use cgo to link against libqrmi.so. The Docker build in scripts/Dockerfile.hooks clones QRMI from upstream, builds the shared library, then cgo-builds the Go binaries against it. Output is written under bin/go-hooks/:

make build-go-hooks                    # builds against QRMI 0.26.3 by default
make build-go-hooks QRMI_REF=main      # builds against QRMI main

Outputs in bin/go-hooks/:

  • qrmi-ocs-prolog
  • qrmi-ocs-epilog
  • libqrmi.so

The hook binaries embed rpath=$ORIGIN, so as long as libqrmi.so sits beside them on the execution host they will resolve the library without any LD_LIBRARY_PATH mangling.

Legacy C hooks

The legacy C prolog/epilog under src/cmd/qrmi-ocs-prolog/ and src/cmd/qrmi-ocs-epilog/ are kept until the Go ports are validated in production. Build instructions for those are unchanged; see the Build queue hooks section below.

Tests

make test    # runs Go unit tests; no QRMI required (uses stub build)
make vet

Two C-harness tests in src/cmd/gridware-adapter (TestPrologApplyBackendEnvUsesConfiguredValue, TestEpilogStrictMetadataBehavior) compile the C hooks against qrmi.h. Point QRMI_INCLUDE_DIR at a QRMI checkout, or check QRMI out next to this repository (../qrmi). Without either, they fail with required path missing.

End-User Quick Start (OCS)

Admin prerequisite: run setup-qrmi-support once on the target OCS queue.

Submit a quick smoke job:

qsub -b y -terse -l qpu=EMU_FREE /bin/echo OCS_QRMI_OK

For a real Pasqal Cloud Pulser task, follow docs/quickinstall-testing.md section 3.

Pasqal Cloud Access (EMU_FREE)

Pasqal documents free emulator access in the Explorer Offer, including EMU_FREE:

Start from the portal:

Then get your project ID from the same "Join Pasqal Cloud" guide ("Find your project ID"), and configure credentials on submit/exec hosts:

mkdir -p ~/.pasqal
cat > ~/.pasqal/config <<'EOF'
username=<your_email>
password=<your_password_or_token_flow>
project_id=<your_project_id>
auth_endpoint=https://authenticate.pasqal.cloud/oauth/token
EOF
chmod 600 ~/.pasqal/config

Admin Guide

Admin setup and verification details are in docs/quickinstall-testing.md. The key operational model is:

  • Scheduler resource: qpu as STRING with relop ==
  • Consumable policy: qpu is configured as NO (backend selector only)
  • Host assignment: one backend name per host (for example qpu=EMU_FREE)
  • Optional capacity resource: qpu_slots as INT, <=, Consumable=JOB
  • Optional readiness resource: qpu_ready as INT, <=, consumable=NO
  • Job request without Load Sensor: -l qpu=<backend> (for example -l qpu=EMU_FREE)
  • Job request with Load Sensor: -l qpu=<backend>,qpu_slots=1,qpu_ready=1

Admin Quick Checklist

  1. Build and copy adapter binary to scheduler master (/tmp/adapter in quickinstall flow).
  2. Build and copy queue hooks + libqrmi.so to scheduler master.
  3. Run setup-qrmi-support to apply resource, host mapping, queue hooks, and reporting params in one command.
  4. Verify qsub -l qpu=<backend> succeeds.

Adapter Commands (Admin/Advanced Users)

setup-qrmi-support (Default)

Apply all required OCS-side QRMI setup in one command:

  • ensure qpu complex entry (STRING, ==, requestable=YES, consumable=NO)
  • set host complex_values to one backend name per host
  • set queue prolog and epilog
  • ensure global reporting_params contains usage_patterns=qrmi:qrmi_*

The adapter installs the QRMI hooks as <hook-user>@<path> … $job_owner procedures. OCS runs them as that account and passes the job owner's name. --hook-user defaults to the cluster's admin_user from $SGE_ROOT/$SGE_CELL/common/bootstrap, or root when it is none. The hooks need that account for two reasons:

  • They write the QRMI variables and the acquisition metadata into the job's spool directory ($SGE_JOB_SPOOL_DIR/environment), which OCS owns as its admin account. This applies to every QRMI resource type.
  • For Pasqal Local, the prolog opens a Warden session on behalf of the job owner's UID and the epilog revokes it. Warden allows only administrators to do that, so add the hook account's UID to Warden's admin_users (0 for root).

Because the hooks run privileged with the job's environment, they trust only the scheduler:

  • The queue command starts them through qrmi-ocs-launch (<hook-user>@<dir>/qrmi-ocs-launch --sge-root=… --sge-cell=… [--spool-root=…]… [--qmaster-port=…] [--execd-port=…] <hook> … $job_owner; --launcher sets another path). setup-qrmi-support writes the launcher options from its own SGE_ROOT, SGE_CELL and ports, and one --spool-root for the global execd_spool_dir and for each host-local override (qconf -sconf <host>). Run it again after setting a host-local execd_spool_dir. The launcher is statically linked, so no dynamic loader reads the job's environment. It refuses to run, failing the job, when LD_* or GLIBC_TUNABLES is set. Otherwise it changes to / and starts the hook with: JOB_ID, SGE_TASK_ID and SGE_JOB_SPOOL_DIR from OCS, validated (the spool directory must be the job's own …/active_jobs/<job>.<task> below one of the spool roots, without symbolic links); SGE_ROOT, SGE_CELL and the ports from its options; TZ if it is a plain time zone name; a fixed PATH, the hook user's HOME and the C locale. Everything else is dropped: QRMI_* and <BACKEND>_QRMI_* settings, proxy and TLS trust variables, RUST_LOG (the hooks set it from --log-level), shell functions and the job owner's HOME. The hooks repeat the loader check and the reset. Backend settings come only from qrmi_config.json and the hook arguments. The hooks need no Pasqal Cloud credentials; the job reads the job owner's ~/.pasqal/config.
  • The QRMI config path, the absolute qstat path (with qconf next to it), the resource names and the log level are part of the administrator-owned queue command.
  • The prolog reads the job's hard request from qstat -j (hard_resource_list, or master_hard_resource_list for -scope master). Soft requests are ignored, and the backend must match the host's complex_values.

The launcher, hook binaries, qstat/qconf and their parent directories must be writable only by administrators.

Exit codes follow OCS's prolog semantics: 0 when the job is set up or requests no QPU, 100 (job error) when the request cannot be served, for example a backend missing from qrmi_config.json, 99 (reschedule) when the backend is temporarily unavailable, and 1 (queue error) only for host or configuration problems. A failed release in the epilog is logged and recorded in accounting (qrmi_release_failed), but the epilog still exits 0. OCS deletes the job's spool directory after the job, so the epilog moves the metadata file, which holds the acquisition token, to <execd spool>/<host>/qrmi_failed_releases/<job>.<task>.tsv (directory mode 0700, owned by the hook user) for the administrator to release by hand.

./adapter setup-qrmi-support \
  --hosts ocs-master,ocs-worker1,ocs-worker2 \
  --host-value EMU_FREE \
  --queue all.q \
  --prolog /shared/gridware-adapter/bin/qrmi-ocs-prolog \
  --epilog /shared/gridware-adapter/bin/qrmi-ocs-epilog

Optional Load Sensor setup keeps capacity and readiness separate:

./adapter setup-qrmi-support \
  --hosts ocs-master,ocs-worker1,ocs-worker2 \
  --host-value PASQAL_LOCAL \
  --queue all.q \
  --prolog /shared/gridware-adapter/bin/qrmi-ocs-prolog \
  --epilog /shared/gridware-adapter/bin/qrmi-ocs-epilog \
  --enable-qpu-slots \
  --qpu-slots-capacity 0 \
  --enable-load-sensor \
  --load-sensor-host ocs-master \
  --load-sensor-path /shared/gridware-adapter/bin/qrmi-ocs-load-sensor

Use --qpu-slots-capacity 0 for Warden-owned Pasqal Local slots. Use a positive value only when OCS should own static host-local slot capacity. For one statically configured backend shared by several hosts, add --qpu-slots-scope global.

OCS stores load_sensor as an executable path. Put the configuration at /etc/qrmi-ocs-load-sensor.yaml, or set QRMI_OCS_LOAD_SENSOR_CONFIG when running the sensor manually. Load Sensor configuration:

load_sensor:
  enabled: true
  scope: global
  resource_name: qpu_ready
  slots_resource_name: qpu_slots
  provider: warden
  timeout_seconds: 3

warden:
  base_url: http://127.0.0.1:8006
  endpoint: /accessible
  tls_verify: true

static:
  ready: true
  state_file: ""

The static provider either returns static.ready or reads 0/1 from static.state_file. It is a dummy readiness signal for paper/demo use and does not represent Pasqal Cloud queue availability. The warden provider polls GET /accessible, can report qpu_slots_available when Warden is configured with qpu_slots_total, and fails closed on timeouts, HTTP errors, or malformed responses.

The Load Sensor is an early scheduler filter only. The OCS prolog still calls QRMI IsAccessible and Acquire, so a job can still be rejected at dispatch time if another scheduler or user consumed the external QPU after OCS scheduled the job.

For the Pasqal Local setup, including Warden, MUNGE, QRMI config, and the readiness Load Sensor, see load_sensor.md.

ensure-resource (Advanced/Manual)

Ensure the scheduler complex entry exists and set host complex_values.

Use STRING with one backend name per host:

./adapter ensure-resource \
  --qconf qconf \
  --hosts ocs-master,ocs-worker1,ocs-worker2 \
  --host-value EMU_FREE

If hosts target different backends, run per host (or host group):

./adapter ensure-resource \
  --hosts ocs-worker1 \
  --host-value EMU_FREE

./adapter ensure-resource \
  --hosts ocs-worker2 \
  --host-value EMU_FREE

configure-queue-hooks (Advanced/Manual)

Configure prolog, epilog, and reporting_params.

./adapter configure-queue-hooks \
  --queue all.q \
  --prolog /shared/gridware-adapter/bin/qrmi-ocs-prolog \
  --epilog /shared/gridware-adapter/bin/qrmi-ocs-epilog

Build queue hooks

Compile against the QRMI C API (qrmi/qrmi.h) and shared library:

mkdir -p /shared/gridware-adapter/bin

gcc -Wall -Wextra -O2 \
  -I/shared/qrmi \
  -L/shared/qrmi/libqrmi-0.26.3 \
  -Wl,-rpath,'$ORIGIN' \
  -o /shared/gridware-adapter/bin/qrmi-ocs-prolog \
  /shared/gridware-adapter/src/cmd/qrmi-ocs-prolog/main.c \
  -lqrmi

gcc -Wall -Wextra -O2 \
  -I/shared/qrmi \
  -L/shared/qrmi/libqrmi-0.26.3 \
  -Wl,-rpath,'$ORIGIN' \
  -o /shared/gridware-adapter/bin/qrmi-ocs-epilog \
  /shared/gridware-adapter/src/cmd/qrmi-ocs-epilog/main.c \
  -lqrmi

cp /shared/qrmi/libqrmi-0.26.3/libqrmi.so /shared/gridware-adapter/bin/

Hook behavior:

  • Prolog reads granted scheduler resource, resolves one backend name, acquires QRMI token, and writes runtime variables into the job environment.
  • Prolog reads the dispatched job's resource list from the administrator-configured qstat -j command.
  • Acquisition metadata is stored only in the scheduler-owned job spool.
  • Epilog reads acquisition metadata and releases tokens.
  • Epilog expects exactly one metadata record; multiple records are treated as an error.
  • Prolog publishes runtime qrmi_* values in the job environment.
  • Epilog appends numeric qrmi_* values into ${SGE_JOB_SPOOL_DIR}/usage so they are captured by usage_patterns=qrmi:qrmi_* and appear in qacct/accounting JSON.
  • Typical runtime qrmi_* variables from prolog:
    • qrmi_resources: backend/resource names acquired by prolog.
    • qrmi_resource_types: QRMI resource types for acquired backends.
    • qrmi_prolog_status: prolog outcome (success or error).
  • Typical runtime error variable from prolog:
    • QRMI_PLUGIN_ERROR: prolog error text when a failure occurs.
  • Typical accounting qrmi_* fields in qacct / accounting JSON:
    • qrmi_acquired_count: number of acquired resources (published from epilog usage data).
    • qrmi_release_total: number of non-empty metadata records seen before release handling (0 or 1 in strict single-record mode).
    • qrmi_release_success: number of successful releases in epilog.
    • qrmi_release_failed: number of failed releases in epilog.
    • qrmi_release_elapsed_seconds: epilog release-loop elapsed time.
    • qrmi_epilog_status_code: epilog outcome as numeric code (1 success, 0 error).
  • RUST_LOG comes from --hook-log-level (names, or SGE debug levels mapped as 2 -> error, 3 -> info, 4 -> debug, >=5 -> trace), not from the job environment.

Behavior vs SPANK Plugin

This Gridware/OCS adapter mirrors core SPANK behavior in these areas:

  • Loads backend settings from qrmi_config.json and exports backend-prefixed QRMI_* variables.
  • Sets RUST_LOG from the administrator's --hook-log-level.
  • Exports QRMI_JOB_QPU_RESOURCES and QRMI_JOB_QPU_TYPES for runtime compatibility.
  • Acquires in prolog and releases in epilog.

Intentional differences from Slurm SPANK:

  • Single backend per job in this adapter model (-l qpu=<backend>).
  • No comma-separated multi-backend request syntax.

Developer Notes

  • Keep queue hooks aligned with the single-backend scheduler model (-l qpu=<backend>).
  • Use make build-adapter and make build-go-hooks for the standard build flows; see Build above.
  • Compile-check legacy C hook sources:
gcc -Wall -Wextra -fsyntax-only -I./qrmi src/cmd/qrmi-ocs-prolog/main.c
gcc -Wall -Wextra -fsyntax-only -I./qrmi src/cmd/qrmi-ocs-epilog/main.c
  • Run Go unit tests for the new hook plumbing without QRMI:
make test
  • Working on the cgo wrapper itself (src/internal/qrmi)? Build with the qrmi tag and the QRMI artifacts on hand:
CGO_ENABLED=1 \
  CGO_CFLAGS="-I/path/to/qrmi" \
  CGO_LDFLAGS="-L/path/to/qrmi -lqrmi -Wl,-rpath,\$ORIGIN" \
  go build -tags qrmi ./src/cmd/qrmi-ocs-prolog-go

Demo and Docs

  • Runnable quickinstall demo commands: demo/qrmi/quickinstall.sh
  • Full runbook: docs/quickinstall-testing.md

Additional Notes

  • QRMI runtime config is expected at /etc/qrmi/qrmi_config.json on submit and execution hosts.
  • OCS quickinstall containers should provide both python3 and python commands.

License

Apache License 2.0. See LICENSE.

About

Pasqal quantum computer integration with Open Cluster Scheduler / Gridware Cluster Scheduler (fka SGE)

Topics

Resources

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages