fix: handle null metadata on multicircuit parent job responses#241
Open
fix: handle null metadata on multicircuit parent job responses#241
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
metadata: nulland emptystats: {}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 causedIonQJob.status()to crash withAttributeError: 'NoneType' object has no attribute 'get'when retrieving such jobs.ionq_job.py, plus a fallback that infers qubit count from result data when metadata is entirely absent.Root cause
response.get("metadata", {}).get("qiskit_header")does not guard against a present-but-null value: when the key"metadata"exists with valueNone, the default{}is not used, andNone.get(...)raisesAttributeError.Fixes
status()line 395:response.get("metadata", {})->(response.get("metadata") or {})soNonebecomes{}status()line 400: Guard_meas_map_from_header(h or {}, ...)againstNoneheader entries_format_result()line 549: Guard(qiskit_header[i] or {}).get("n_qubits", ...)againstNoneheader entries_format_result()qubit inference: Whenclbitsis empty and result data exists, infer qubit count from the highest result key (max(int(k)).bit_length()) so_build_countsgets a usable measurement mapTest plan
test_multicircuit_null_metadata_status- verifiesstatus()doesn't crash with null metadata parenttest_multicircuit_null_metadata_result- verifies end-to-endresult()with aggregated results keyed by child job IDdummy_multicircuit_parent_responsematching the real IonQ API shape