Skip to content

fix: handle null metadata on multicircuit parent job responses#241

Open
splch wants to merge 1 commit intomainfrom
fix/multicircuit-null-metadata
Open

fix: handle null metadata on multicircuit parent job responses#241
splch wants to merge 1 commit intomainfrom
fix/multicircuit-null-metadata

Conversation

@splch
Copy link
Copy Markdown
Collaborator

@splch splch commented Mar 19, 2026

Summary

  • The IonQ API returns metadata: null and empty stats: {} on parent multicircuit job responses when the job was submitted without qiskit metadata (e.g. via the REST API directly, or any non-qiskit client). This caused IonQJob.status() to crash with AttributeError: 'NoneType' object has no attribute 'get' when retrieving such jobs.
  • Three null-safety fixes in ionq_job.py, plus a fallback that infers qubit count from result data when metadata is entirely absent.
  • Verified against the live IonQ API (v0.4 simulator) with both qiskit-submitted and raw-submitted multicircuit jobs.

Root cause

response.get("metadata", {}).get("qiskit_header") does not guard against a present-but-null value: when the key "metadata" exists with value None, the default {} is not used, and None.get(...) raises AttributeError.

Fixes

  1. status() line 395: response.get("metadata", {}) -> (response.get("metadata") or {}) so None becomes {}
  2. status() line 400: Guard _meas_map_from_header(h or {}, ...) against None header entries
  3. _format_result() line 549: Guard (qiskit_header[i] or {}).get("n_qubits", ...) against None header entries
  4. _format_result() qubit inference: When clbits is empty and result data exists, infer qubit count from the highest result key (max(int(k)).bit_length()) so _build_counts gets a usable measurement map

Test plan

  • New test test_multicircuit_null_metadata_status - verifies status() doesn't crash with null metadata parent
  • New test test_multicircuit_null_metadata_result - verifies end-to-end result() with aggregated results keyed by child job ID
  • New fixture dummy_multicircuit_parent_response matching the real IonQ API shape
  • All 341 existing tests still pass
  • Verified against live IonQ API (v0.4 simulator)

The IonQ API returns `metadata: null` and empty `stats` on parent
multicircuit job responses when the job was submitted without qiskit
metadata (e.g. via the REST API directly).  This caused an
AttributeError in `status()` because `response.get("metadata", {})`
does not guard against a present-but-null value.

Three fixes applied:
- Use `(response.get("metadata") or {})` so null becomes `{}`
- Guard `_meas_map_from_header` and `_format_result` against None
  header entries in the decompressed qiskit_header list
- Infer qubit count from result keys when both qiskit_header and
  stats are absent, so `_build_counts` gets a usable clbits map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant