Skip to main content

Python client for the Symbolic Q cloud simulator REST API

Project description

Symbolic Q API Wrapper

A dependency-light Python client for the Symbolic Q cloud simulator REST API (https://q.symbolicinfo.com). It exposes a familiar backend.run(circuit) -> job -> result.get_counts() workflow while talking to the HTTP API documented in API.md.

  • Build circuits with a concise gate-method API (qc.h(0), qc.cx(0, 1), ...)
  • Submit and poll runs asynchronously (job.result(), job.status(), job.cancel())
  • Local validation against the full supported-gate set (API.md section 12)
  • JSON, CSV, and ZIP request/response helpers for the documented API formats
  • Runtime dependency: requests

Install

pip install symbolicq

From source:

pip install -e .[dev]

Quick Start

from symbolicq import QuantumCircuit, SymbolicQBackend

backend = SymbolicQBackend()           # defaults to https://q.symbolicinfo.com

qc = QuantumCircuit(2, 2, name="bell")
qc.h(0)
qc.cx(0, 1)
qc.measure_all()

job = backend.run(qc, shots=1024, seed=7)
result = job.result()                  # blocks until the job completes

print(result.get_counts())             # {'00': 511, '11': 513}
print(result.get_probabilities())      # {'00': 0.5, '11': 0.5}
print(result.most_frequent())          # '11'

Manual

Start with manual/index.md for the full documentation.

Bit Order

Bitstrings follow the API convention: MSB-left c[n-1] ... c[0], where qubit/clbit index 0 is the least-significant bit. See API.md "Bit Order".

Configuration

base_url and api_key are resolved in this order, first non-empty value wins:

  1. Explicit argument
  2. SYMBOLICQ_API_URL / SYMBOLICQ_API_KEY from environment variables
  3. API_URL / API_KEY from environment variables
  4. Built-in default URL (https://q.symbolicinfo.com); no default key

When set, the key is sent on every request as Authorization: Bearer {API_KEY}.

Environment Variables

export API_URL=https://q.symbolicinfo.com
export API_KEY=your-secret-token

PowerShell:

$env:API_URL = "https://q.symbolicinfo.com"
$env:API_KEY = "your-secret-token"
backend = SymbolicQBackend()   # picks up API_URL / API_KEY from env

Explicit Override

backend = SymbolicQBackend(
    base_url="https://q.symbolicinfo.com",
    api_key="...",
    timeout=60.0,
)

Lower-Level Client

Every JSON REST endpoint is available directly on SymbolicQClient:

from symbolicq import SymbolicQClient

client = SymbolicQClient()
client.health()
created = client.create_circuit(qc.to_dict())
run = client.create_run(created["circuit_id"], shots=1024, seed=7)
client.get_status(run["job_id"])
client.get_result(run["job_id"])
client.list_circuits()
client.list_runs()

Job exposes raw API payloads plus small convenience helpers:

job.status()            # raw GET /runs/{job_id}/status payload
job.status_text()       # e.g. "queued", "running", "completed"
job.progress()          # progress object when the server reports it
job.progress_ratio()    # float or None
job.refresh_result()    # immediate GET /runs/{job_id}/result

CSV and ZIP helpers are also available for API.md's alternate wire formats:

client.create_circuit_csv(qc.to_csv())
client.get_circuit_csv("circuit-id")
client.get_result_csv("job-id")

client.create_circuit_json_zip(qc.to_dict())
client.create_circuit_csv_zip(qc.to_csv())
client.create_circuit_zip(zip_bytes, inner_content_type="application/json")
client.get_circuit_zip("circuit-id")
client.get_result_zip("job-id")
client.request_zip("GET", "/health")  # generic ZIP response helper

Circuits can be round-tripped through the documented CSV circuit format:

csv_text = qc.to_csv()
qc2 = QuantumCircuit.from_csv(csv_text)

CSV or ZIP circuit payloads can also be submitted through the backend:

job = backend.run_csv(qc.to_csv(), shots=1024)
job = backend.run_zip(make_circuit_json_zip(qc), shots=1024)

Completed results can be exported as the documented result CSV:

from symbolicq import Result

csv_text = result.to_csv()
result2 = Result.from_csv(csv_text)

ZIP utilities are exported for local packing and unpacking:

from symbolicq import make_circuit_json_zip, read_first_zip_text

zip_bytes = make_circuit_json_zip(qc)
text = read_first_zip_text(zip_bytes)

Simulator Options

backend.run(
    qc,
    shots=1024,
    seed=7,
    simulator_options={
        "measurement_uses_density": True,
        "settle_after_instruction": True,
    },
)

Supported Gates

symbolicq.SUPPORTED_GATES mirrors API.md section 12: single-qubit, two-qubit/controlled, multi-controlled, and special gates such as measure, reset, barrier, delay, and global_phase.

All supported gates can be emitted through either convenience methods or QuantumCircuit.append(...). Unsupported gates and invalid qubit, clbit, or parameter counts are rejected locally before the request is sent.

Development

pip install -e .[dev]
pytest

Examples:

python examples/bell.py
python examples/csv_and_zip.py

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

symbolicq-0.1.0.tar.gz (32.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

symbolicq-0.1.0-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

Details for the file symbolicq-0.1.0.tar.gz.

File metadata

  • Download URL: symbolicq-0.1.0.tar.gz
  • Upload date:
  • Size: 32.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for symbolicq-0.1.0.tar.gz
Algorithm Hash digest
SHA256 67158429e726a561e7e81ff3f228a5f08dca596b9b42d037f1258538453872c7
MD5 8ca2f3abcb392caf508a4d9c748a4df4
BLAKE2b-256 dfaff323c81bd759804a33ae33670c425fe3869330e7da1f87a3325162187fb7

See more details on using hashes here.

File details

Details for the file symbolicq-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: symbolicq-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for symbolicq-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 70ae0903056dfa9631d5e10c5eae188e8921584e8dede06b8e39f76fd66e5f53
MD5 4129312442d25a02f0a808916000b70b
BLAKE2b-256 755fcf3a7157a3d88e5188f6469df363dfd26f9ce86ec4d3d0e0391bd8239034

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page