Skip to content

Backend Service

The ColliderML backend is a FastAPI application that accepts simulation requests, manages user credits, dispatches jobs to NERSC Perlmutter via the Superfacility API, and hosts benchmark leaderboards.

Source: colliderml-production/backend/

Technology stack

LayerChoice
FrameworkFastAPI 0.115+
DatabaseSupabase (PostgreSQL 14+) via asyncpg
AuthenticationHuggingFace OAuth bearer tokens
Job dispatchNERSC SFAPI (sfapi-client>=0.1.0)
Container runtimeShifter on Perlmutter
Output storageHuggingFace Datasets
TemplatingJinja2 (sbatch scripts)
Emailaiosmtplib (optional)

Routes

User routes (/v1/*)

All require Authorization: Bearer <hf-token>.

MethodPathPurpose
POST/v1/simulateSubmit a simulation request
GET/v1/requests/{request_id}Status + output URI for one request
GET/v1/requestsList current user's requests (paginated, limit=50)
GET/v1/meUser profile: username, email, credits, timestamps
GET/v1/me/transactionsCredit ledger entries (paginated, limit=100)
GET/v1/datasetsStatic catalogue of 21 dataset variants

Benchmark routes (/v1/benchmark/*)

MethodPathPurpose
GET/v1/benchmark/tasksList all benchmark tasks with metrics
POST/v1/benchmark/{task}/submitUpload predictions (Parquet), auto-score, award credits
POST/v1/benchmark/{task}/reproduce/{id}Reproduce a submission; earn 20 credits if within 2%
GET/v1/leaderboard/{task}Leaderboard for a task (limit=100)

Admin routes (/admin/*)

Require X-Admin-Token: <shared-secret> header.

MethodPathPurpose
POST/admin/freeze?frozen={bool}Kill switch — pause all new submissions
POST/admin/grantGrant/deduct credits: {hf_username, delta, reason}
POST/admin/banBan/unban a user: {hf_username, banned}
GET/admin/usage?limit=20Top users by node-hours this month
GET/admin/analytics/channelsRequest count + node-hours per channel
GET/admin/analytics/daily?days=30Daily node-hours time series
GET/admin/analytics/failuresFailure rate this month

Webhook routes (/webhooks/*)

MethodPathPurpose
POST/webhooks/githubGitHub PR-merged webhook (HMAC-SHA256 verified)

Health

MethodPathPurpose
GET/healthzReadiness probe

Database schema

Six core tables, one view:

users

ColumnTypeNotes
hf_usernametext PKHuggingFace username
emailtextnullable
creditsnumeric(10,3)Current balance
bannedbooldefault false
created_attimestamptz
last_seen_attimestamptzUpdated on every auth
notestextOperator notes

credit_transactions

Append-only ledger. Every credit movement is recorded.

ColumnTypeNotes
idbigserial PK
hf_usernametext FK
deltanumeric(10,3)Positive = credit, negative = debit
reasontextsignup, spent_on_request, reconciliation_refund, refund_submit_failed, refund_job_failed, beat_<task>, github_pr_merged, admin_grant
metadatajsonbRequest hash, submission ID, PR URL, etc.
created_attimestamptz

simulation_requests

ColumnTypeNotes
iduuid PK
hf_usernametext FK
channeltextPhysics channel name
eventsint1–100,000
pileupint0–200
seedintdefault 42
config_hashtextSHA-256 of (channel, events, pileup, seed)
statetextqueuedsubmittedrunningcompleted | failed | cancelled
nersc_jobidtextSLURM job ID
estimated_node_hoursnumeric(10,3)
actual_node_hoursnumeric(10,3)
credits_chargednumeric(10,3)
output_hf_repotextCERN/ColliderML-Service-<id>
error_messagetext
created_at, updated_attimestamptz

Unique constraint on config_hash where state in (queued, submitted, running, completed) — prevents duplicate in-flight requests.

global_config

Single-row table (id=1).

ColumnDefaultPurpose
monthly_node_hours_cap500Global monthly ceiling
submissions_frozenfalseKill switch
seed_credits10Credits granted on first sign-in

benchmark_submissions, benchmark_bests, benchmark_reproductions

Leaderboard tables tracking per-task submissions, current bests per metric, and reproduction attempts.

gh_hf_mapping

Maps GitHub usernames to HuggingFace usernames for automated credit grants on PR merges.

monthly_usage (view)

Aggregates node_hours and n_requests per user for the current calendar month.

Authentication flow

  1. Extract Authorization: Bearer <token> header
  2. Verify against https://huggingface.co/api/whoami-v2
  3. First sign-in: create user row, grant seed_credits, record signup transaction
  4. Check banned flag — reject with 403 if true
  5. Update last_seen_at, return user dict

Credit system

Unit: 1 credit = 1 node-hour on Perlmutter CPU queue.

Cost formula:

base_seconds = channel_base[channel]   # 5s–90s per event
pileup_factor = 1 + pileup / 50
overhead = madgraph_overhead[channel]   # 0 or 300s
node_hours = (overhead + base_seconds * events * pileup_factor) / 3600

Pre-submission gates (checked in order):

  1. Banned? → 403
  2. Frozen? → 503
  3. Burst: ≥10 submissions in 5 min → 429
  4. Duplicate: same config_hash completed in 7 days → 409
  5. Monthly cap: used + est > cap → 503
  6. Balance: credits < est → 402
  7. Atomic deduction inside a database transaction

Refunds: Automatic on submission failure, job failure, or over-estimation (reconciliation).

Earning credits:

  • Beat a leaderboard metric: 30–50 credits per metric
  • Reproduce a submission (within 2%): 20 credits
  • GitHub PR merged with recognized labels: 10–200 credits
  • Admin grant: arbitrary

Last updated:

Released under the MIT License.