@@ -407,12 +407,11 @@ def _serialize_measurements(self, meas_ops: Iterator) -> dict[str, str]:
407407 and targets into a form that is suitable for passing through IonQ's metadata field
408408 for a job.
409409
410- Each key and targets are serialized into a string of the form `key` + the ASCII unit
411- separator (chr(31)) + targets as a comma separated value. These are then combined
412- into a string with a separator character of the ASCII record separator (chr(30)).
413- Finally this full string is serialized as the values in the metadata dict with keys
414- given by `measurementX` for X = 0,1, .. 9 and X large enough to contain the entire
415- string.
410+ Measurements are encoded as a compact JSON array of objects with keys:
411+ `{"k": <measurement_key:str>, "t": <list[int] of target qubit indices>}`.
412+ The resulting JSON string is split into chunks and stored under
413+ `measurement0`, `measurement1`, ... to respect the IonQ metadata
414+ value-size limit.
416415
417416 Args:
418417 A list of the result of serializing the measurement (not supported by the API).
@@ -423,8 +422,13 @@ def _serialize_measurements(self, meas_ops: Iterator) -> dict[str, str]:
423422 Raises:
424423 ValueError: if the
425424 """
426- key_values = [f'{ op ["key" ]} { chr (31 )} { op ["targets" ]} ' for op in meas_ops ]
427- full_str = chr (30 ).join (key_values )
425+ # Encode as JSON (no control chars) and keep measurement0..N chunking.
426+ json_array = [
427+ {"k" : op ["key" ], "t" : [int (t ) for t in op ["targets" ].split ("," )]} for op in meas_ops
428+ ]
429+ if not json_array :
430+ return {}
431+ full_str = json .dumps (json_array , separators = ("," , ":" ))
428432 # IonQ maximum value size for metadata.
429433 max_value_size = 40
430434 split_strs = [
0 commit comments