Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
142 commits
Select commit Hold shift + click to select a range
399c704
make compile v3 only return a job id
bharat-thotakura Apr 29, 2026
a0e4132
various nits
bharat-thotakura Apr 29, 2026
c3c982a
add `_map_compile_request_to_client_result` for `css` (+ import nit)
bharat-thotakura Apr 29, 2026
0a00106
add `_map_compile_request_to_client_result` for `qss` (+ various nits)
bharat-thotakura Apr 29, 2026
001c149
wait till terminal state before polling
bharat-thotakura Apr 29, 2026
a2fdc5d
nit: style of error message
bharat-thotakura Apr 14, 2026
d231b9f
docstring nits
bharat-thotakura Apr 29, 2026
5eaeaee
typing overhaul with generics
bharat-thotakura May 1, 2026
5b09ca1
rename to default api version
bharat-thotakura May 1, 2026
9b13b92
do the same thing for `qss`
bharat-thotakura May 1, 2026
71bc63a
add back docstrings
bharat-thotakura May 1, 2026
bacf3ff
delete some tests
bharat-thotakura May 1, 2026
f9b6184
lint check fix
bharat-thotakura May 1, 2026
5210ef5
correct job v3 tests in `css`
bharat-thotakura May 1, 2026
bcfca49
revert breaking change for api version var
bharat-thotakura May 1, 2026
75b482e
renaming to fix build docs error
bharat-thotakura May 1, 2026
2c4e75f
typing fix for Python 3.9
bharat-thotakura May 1, 2026
9e4b09c
thanks Python 3.9
bharat-thotakura May 1, 2026
4f6c71e
update `qss` conftest
bharat-thotakura May 5, 2026
1212ad5
add coverage test for `NotImplementedError`
bharat-thotakura May 5, 2026
0ea00b2
Merge branch 'main' into bt/retire-v3-compileroutput
bharat-thotakura May 5, 2026
613ac39
don't override `__new__` in `css`
bharat-thotakura May 9, 2026
20d234e
don't override `__new__` in `qss`
bharat-thotakura May 9, 2026
d81bf33
Revert "update `qss` conftest"
bharat-thotakura May 9, 2026
e09318c
Merge branch 'main' into bt/retire-v3-compileroutput
bharat-thotakura May 9, 2026
8cbb4ac
fix arg naming after `main` merge
bharat-thotakura May 9, 2026
9f9418c
line too long fix
bharat-thotakura May 9, 2026
299fc64
drop casting in `qss`
bharat-thotakura May 9, 2026
51c11b6
Revert "drop casting in `qss`"
bharat-thotakura May 9, 2026
988556c
docstring update for `css`
bharat-thotakura May 9, 2026
3183414
docstring (+return typing) update for `qss`
bharat-thotakura May 9, 2026
ae53873
docstring typos fix
bharat-thotakura May 9, 2026
cd5f4be
refactor all json read functions into `gss`
bharat-thotakura May 12, 2026
b3d1ecd
expand qubit validation for QASM too
bharat-thotakura May 12, 2026
68eede5
update qubit validation test
bharat-thotakura May 12, 2026
bcf0509
update exception message
bharat-thotakura May 12, 2026
868f154
nit
bharat-thotakura May 12, 2026
eeab332
major `CompilerOutput` refactor
bharat-thotakura May 12, 2026
3f27e5f
typo + nit
bharat-thotakura May 12, 2026
439782e
how far can you go
bharat-thotakura May 12, 2026
39d643f
why be so verbose
bharat-thotakura May 12, 2026
5d8e999
nits
bharat-thotakura May 12, 2026
7219225
change `KeyError` to `TypeError`
bharat-thotakura May 12, 2026
5a9aaec
full coverage for `css`
bharat-thotakura May 12, 2026
7b9cea2
`css` test nits
bharat-thotakura May 12, 2026
e93529c
warning spacing fix
bharat-thotakura May 12, 2026
be77c9e
use `aqt_compile` instead of `compile`
bharat-thotakura May 12, 2026
36db5e2
coverage tests for `qss`
bharat-thotakura May 12, 2026
ebebd1c
spacing fix for ` type: ignore[call-overload]`
bharat-thotakura May 13, 2026
dd837c1
avoid fragile import and simplify ApiVersion typing
bharat-thotakura May 13, 2026
607b2f9
propagate `QssCompileResultT_co:` properly
bharat-thotakura May 13, 2026
349fe8a
`ty` error fix
bharat-thotakura May 13, 2026
975a2c2
resolve circular import issue
bharat-thotakura May 13, 2026
d919889
tighten up some tests
bharat-thotakura May 13, 2026
f473d27
unused import fix
bharat-thotakura May 13, 2026
ab056b3
return to broad ApiV2/V3 typing
bharat-thotakura May 13, 2026
c5dcf02
keep `timeout` and `wait` for `qiskit` parity
bharat-thotakura May 13, 2026
6862dec
Merge branch 'bt/retire-v3-compileroutput' into bt/add-qasm-client
bharat-thotakura May 13, 2026
c1e231d
propagate new parser naming convention
bharat-thotakura May 13, 2026
dbd1303
unused import fix
bharat-thotakura May 13, 2026
2c5b1fd
route `qscout_compile` and `aqt_compile` to `compile` in `css`
bharat-thotakura May 13, 2026
269d20c
route `qscout_compile` and `aqt_compile` to `compile` in `qss`
bharat-thotakura May 13, 2026
257d46b
update tests
bharat-thotakura May 13, 2026
df0f41f
Merge branch 'bt/retire-v3-compileroutput' into bt/add-qasm-client
bharat-thotakura May 13, 2026
26c9a3b
add jaqal program support for V3 jobs
bharat-thotakura May 13, 2026
ab8b51b
coverage for jaqal functionality
bharat-thotakura May 13, 2026
ea5cf80
Merge branch 'bt/retire-v3-compileroutput' into bt/add-qasm-client
bharat-thotakura May 13, 2026
fc35a88
allow `get_job()` to return V3 in `qss`
bharat-thotakura May 13, 2026
ac43ff1
update test for coverage
bharat-thotakura May 13, 2026
23d6b03
update `get_job()` docstring in `css`
bharat-thotakura May 13, 2026
ee333f9
mention `.jaqal_program()` in docstrings
bharat-thotakura May 13, 2026
ab7419c
Docstring typo fixes
bharat-thotakura May 14, 2026
9940aae
maintain `qiskit` parity for `SuperstaqJobV3`
bharat-thotakura May 14, 2026
5c9373d
update test
bharat-thotakura May 14, 2026
e4bfb77
docstring nits
bharat-thotakura May 14, 2026
860bd4c
revert unrelated changes
bharat-thotakura May 14, 2026
023ccfb
Delete duplicate copied test code
bharat-thotakura May 14, 2026
ee1e103
update overloaded signature in `superstaq_job.py`
bharat-thotakura May 14, 2026
c9d0b06
some `Any` to `object`
bharat-thotakura May 14, 2026
d077330
Merge branch 'bt/retire-v3-compileroutput' into bt/add-qasm-client
bharat-thotakura May 14, 2026
9f18c88
nits
bharat-thotakura May 14, 2026
110a4e1
Merge branch 'main' into bt/retire-v3-compileroutput
bharat-thotakura May 14, 2026
31b8076
`ty` import nit
bharat-thotakura May 15, 2026
f4274a2
cast request codes into ints
bharat-thotakura May 15, 2026
986e427
use stdlib `HTTPStatus` instead of request codes
bharat-thotakura May 15, 2026
65e007d
Revert "cast request codes into ints"
bharat-thotakura May 15, 2026
8131bf3
use `http.HTTPStatus` everywhere
bharat-thotakura May 15, 2026
ea2971d
use `dict` for `self.headers`
bharat-thotakura May 15, 2026
7eb4a08
try using `MutableMapping`
bharat-thotakura May 15, 2026
8d02b9c
try just `Mapping`
bharat-thotakura May 15, 2026
c11912d
Revert "try just `Mapping`"
bharat-thotakura May 15, 2026
101d23a
use `http.HTTPStatus` in machine api test
bharat-thotakura May 15, 2026
d9f5f21
use `http.HTTPStatus` in superstaq client
bharat-thotakura May 15, 2026
89cec4f
drop remaining `requests.code`
bharat-thotakura May 15, 2026
6ca1b2c
Drop bytes in type return
bharat-thotakura May 16, 2026
58d4aac
Revert "Drop bytes in type return"
bharat-thotakura May 17, 2026
56a0873
Merge branch 'main' into bt/retire-v3-compileroutput
bharat-thotakura May 20, 2026
b702546
Merge branch 'main' into bt/retire-v3-compileroutput
bharat-thotakura May 20, 2026
a692b88
Merge branch 'main' into bt/retire-v3-compileroutput
bharat-thotakura May 22, 2026
55f2747
Merge branch 'main' into bt/retire-v3-compileroutput
bharat-thotakura May 28, 2026
41c8dc2
avoid extra `wait_for_terminal_state()` call if the `index` is `None`
bharat-thotakura Jun 11, 2026
903dda6
Merge branch 'main' into bt/retire-v3-compileroutput
bharat-thotakura Jun 11, 2026
b8f7451
drop unneeded `typing_extensions` import
bharat-thotakura Jun 11, 2026
ad8f3b7
handle terminal compile states
bharat-thotakura Jun 12, 2026
025061b
update polling test without hardcoded `TimeoutError`
bharat-thotakura Jun 12, 2026
12205b4
drop some TODOs
bharat-thotakura Jun 12, 2026
121cd2f
add a `_check_if_unsuccessful` + docstrings update
bharat-thotakura Jun 12, 2026
dc33be6
rename `treat_as_submit_job` to `check_until_compile`
bharat-thotakura Jun 17, 2026
df117fe
Revert "add a `_check_if_unsuccessful` + docstrings update"
bharat-thotakura Jun 17, 2026
c9a0fce
drop `_check_if_unsuccessful()` in `compiled_circuits()`
bharat-thotakura Jun 17, 2026
e9a4083
Merge branch 'main' into bt/add-qasm-client
bharat-thotakura Jun 23, 2026
7006e8a
Merge branch 'bt/retire-v3-compileroutput' into bt/add-qasm-client
bharat-thotakura Jun 23, 2026
65543cd
type hint for `qaoa_vanilla_proxy.py`
bharat-thotakura Jun 23, 2026
a62fe1a
linestyle type hint
bharat-thotakura Jun 23, 2026
f1a43b7
typing update for `plottting.py`
bharat-thotakura Jun 23, 2026
cf208f6
a problem for branch coverage to deal with
bharat-thotakura Jun 23, 2026
60cd8ae
nit
bharat-thotakura Jun 23, 2026
a4d6779
oh my. didn't go far enough
bharat-thotakura Jun 25, 2026
5ead90b
nit: import style
bharat-thotakura Jun 25, 2026
874402d
finish standardizing imports
bharat-thotakura Jun 25, 2026
0edf1cf
fix failing test
bharat-thotakura Jun 25, 2026
25afa7b
test nit
bharat-thotakura Jun 26, 2026
72c4bc1
add `QasmService` to `__init__`
bharat-thotakura Jun 26, 2026
13db840
move qiskit circuit serialization from `css` to `gss`
bharat-thotakura Jun 26, 2026
a2392e5
include deserialization of pulse gate circuits for `QasmService`
bharat-thotakura Jun 26, 2026
ffb787a
update module from `css` -> `gss`
bharat-thotakura Jun 26, 2026
d89649d
add dedicated `ibmq_compile()` and `cq_compile()` for `QasmService()`
bharat-thotakura Jun 26, 2026
ce8445b
much coverage. much duplication
bharat-thotakura Jun 26, 2026
090c4bf
lint check fix
bharat-thotakura Jun 26, 2026
32d0f02
type check fix
bharat-thotakura Jun 26, 2026
1d19449
add some pragma no covers
bharat-thotakura Jun 26, 2026
f546f89
update flaky test
bharat-thotakura Jun 26, 2026
a0b794e
typo fix
bharat-thotakura Jun 26, 2026
f0bf1c0
corrections
bharat-thotakura Jun 27, 2026
ebcac4d
Merge branch 'bt/type-check-fix' into bt/add-qasm-client
bharat-thotakura Jun 27, 2026
1e7cc5b
try this
bharat-thotakura Jun 27, 2026
5b9be27
Merge branch 'bt/fix-type-check' into bt/add-qasm-client
bharat-thotakura Jun 27, 2026
f93211e
typo fix
bharat-thotakura Jun 27, 2026
4535b8d
update test assertions
bharat-thotakura Jun 27, 2026
0c46a0d
Merge branch 'main' into bt/add-qasm-client
bharat-thotakura Jul 16, 2026
afd9a62
Merge branch 'main' into bt/add-qasm-client
bharat-thotakura Jul 28, 2026
1f97ee4
Merge branch 'main' into bt/add-qasm-client
bharat-thotakura Jul 31, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
240 changes: 28 additions & 212 deletions cirq-superstaq/cirq_superstaq/compiler_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,15 @@

from __future__ import annotations

import importlib.util
import json
import warnings
from typing import Any
from typing import TYPE_CHECKING, Any

import cirq
import general_superstaq as gss

import cirq_superstaq as css

try:
if TYPE_CHECKING:
import qtrl.sequence_utils.readout
except ModuleNotFoundError:
pass


def active_qubit_indices(circuit: cirq.AbstractCircuit) -> list[int]:
Expand All @@ -41,7 +36,7 @@ def active_qubit_indices(circuit: cirq.AbstractCircuit) -> list[int]:
circuit: The input quantum circuit.

Returns:
A list of active qubit indicies.
A list of active qubit indices.

Raises:
TypeError: If qubit indices are requested for non-line qubits.
Expand Down Expand Up @@ -135,214 +130,35 @@ def __init__(
jaqal_programs=jaqal_programs,
)


def read_json(json_dict: dict[str, Any], circuits_is_list: bool) -> CompilerOutput:
"""Reads out returned JSON from Superstaq API's IBMQ compilation endpoint.

Args:
json_dict: A JSON dictionary matching the format returned by /ibmq_compile endpoint
circuits_is_list: A bool flag that controls whether the returned object has a .circuits
attribute (if `True`) or a .circuit attribute (`False`).

Returns:
A `CompilerOutput` object with the compiled circuit(s). If included in the server response,
the returned object also stores the corresponding pulse gate circuit(s) in its
.pulse_gate_circuit(s) attribute (provided qiskit-superstaq is available locally).
"""
compiled_circuits = css.serialization.deserialize_circuits(json_dict["cirq_circuits"])
initial_logical_to_physicals: list[dict[cirq.Qid, cirq.Qid]] = list(
map(dict, cirq.read_json(json_text=json_dict["initial_logical_to_physicals"]))
)
final_logical_to_physicals: list[dict[cirq.Qid, cirq.Qid]] = list(
map(dict, cirq.read_json(json_text=json_dict["final_logical_to_physicals"]))
)

pulse_gate_circuits = None

if "pulse_gate_circuits" in json_dict:
pulse_gate_circuits = css.serialization.deserialize_qiskit_circuits(
json_dict["pulse_gate_circuits"],
circuits_is_list,
pulse_start_times=json_dict.get("pulse_start_times"),
@staticmethod
def _get_deserialized_content(
json_dict: dict[str, Any],
circuits_is_list: bool,
) -> tuple[
list[cirq.Circuit],
list[object] | None,
list[dict[cirq.Qid, cirq.Qid]],
list[dict[cirq.Qid, cirq.Qid]],
]:
compiled_circuits = css.serialization.deserialize_circuits(json_dict["cirq_circuits"])
initial_logical_to_physicals_list: list[dict[cirq.Qid, cirq.Qid]] = list(
map(dict, cirq.read_json(json_text=json_dict["initial_logical_to_physicals"]))
)

if circuits_is_list:
return CompilerOutput(
compiled_circuits,
initial_logical_to_physicals,
final_logical_to_physicals,
pulse_gate_circuits=pulse_gate_circuits,
final_logical_to_physicals_list: list[dict[cirq.Qid, cirq.Qid]] = list(
map(dict, cirq.read_json(json_text=json_dict["final_logical_to_physicals"]))
)
return CompilerOutput(
compiled_circuits[0],
initial_logical_to_physicals[0],
final_logical_to_physicals[0],
pulse_gate_circuits=None if pulse_gate_circuits is None else pulse_gate_circuits[0],
)


def read_json_aqt(
json_dict: dict[str, Any], circuits_is_list: bool, num_eca_circuits: int | None = None
) -> CompilerOutput:
"""Reads out returned JSON from Superstaq API's AQT compilation endpoint.

Args:
json_dict: A JSON dictionary matching the format returned by aqt_compile endpoint.
circuits_is_list: A bool flag that controls whether the returned object has a .circuits
attribute (if `True`) or a .circuit attribute (`False`).
num_eca_circuits: Number of logically equivalent random circuits to generate for each
input circuit.

Returns:
A `CompilerOutput` object with the compiled circuit(s). If `qtrl` is available locally,
the returned object also stores the pulse sequence in the .seq attribute.
"""
compiled_circuits: list[cirq.Circuit] | list[list[cirq.Circuit]]
compiled_circuits = css.serialization.deserialize_circuits(json_dict["cirq_circuits"])

initial_logical_to_physicals_list: list[dict[cirq.Qid, cirq.Qid]] = list(
map(dict, cirq.read_json(json_text=json_dict["initial_logical_to_physicals"]))
)
initial_logical_to_physicals: (
list[dict[cirq.Qid, cirq.Qid]] | list[list[dict[cirq.Qid, cirq.Qid]]]
) = initial_logical_to_physicals_list

final_logical_to_physicals_list: list[dict[cirq.Qid, cirq.Qid]] = list(
map(dict, cirq.read_json(json_text=json_dict["final_logical_to_physicals"]))
)
final_logical_to_physicals: (
list[dict[cirq.Qid, cirq.Qid]] | list[list[dict[cirq.Qid, cirq.Qid]]]
) = final_logical_to_physicals_list

seq = None

if "state_jp" in json_dict:
if not importlib.util.find_spec("qtrl"):
warnings.warn(
"This output only contains compiled circuits. The `qtrl` package must be installed "
"in order to deserialize compiled pulse sequences.",
stacklevel=2,
pulse_gate_circuits = None
if "pulse_gate_circuits" in json_dict:
pulse_gate_circuits = gss.serialization.deserialize_qiskit_circuits(
json_dict["pulse_gate_circuits"],
circuits_is_list,
pulse_start_times=json_dict.get("pulse_start_times"),
)
else: # pragma: no cover, b/c qtrl is not open source so it is not in cirq-superstaq reqs

def _sequencer_from_state(state: dict[str, Any]) -> qtrl.sequencer.Sequence:
seq = qtrl.sequencer.Sequence(n_elements=1)
seq.__setstate__(state)
seq.compile()
return seq

state = gss.serialization.deserialize(json_dict["state_jp"])

if "readout_jp" in json_dict:
readout_state = gss.serialization.deserialize(json_dict["readout_jp"])
readout_seq = _sequencer_from_state(readout_state)

if "readout_qubits" in json_dict:
readout_qubits = json.loads(json_dict["readout_qubits"])
readout_seq._readout = qtrl.sequence_utils.readout._ReadoutInfo(
readout_seq, readout_qubits, n_readouts=len(compiled_circuits)
)

state["_readout"] = readout_seq

seq = _sequencer_from_state(state)

if num_eca_circuits is not None:
compiled_circuits = [
compiled_circuits[i : i + num_eca_circuits]
for i in range(0, len(compiled_circuits), num_eca_circuits)
]
initial_logical_to_physicals = [
initial_logical_to_physicals_list[i : i + num_eca_circuits]
for i in range(0, len(initial_logical_to_physicals_list), num_eca_circuits)
]
final_logical_to_physicals = [
final_logical_to_physicals_list[i : i + num_eca_circuits]
for i in range(0, len(final_logical_to_physicals_list), num_eca_circuits)
]

if circuits_is_list:
return CompilerOutput(
return (
compiled_circuits,
initial_logical_to_physicals,
final_logical_to_physicals,
seq=seq,
pulse_gate_circuits,
initial_logical_to_physicals_list,
final_logical_to_physicals_list,
)

return CompilerOutput(
compiled_circuits[0],
initial_logical_to_physicals[0],
final_logical_to_physicals[0],
seq=seq,
)


def read_json_qscout(
json_dict: dict[str, Any], circuits_is_list: bool, num_eca_circuits: int | None = None
) -> CompilerOutput:
"""Reads out returned JSON from Superstaq API's QSCOUT compilation endpoint.

Args:
json_dict: A JSON dictionary matching the format returned by qscout_compile endpoint.
circuits_is_list: A bool flag that controls whether the returned object has a .circuits
attribute (if `True`) or a .circuit attribute (`False`).
num_eca_circuits: Optional number of logically equivalent random circuits to generate for
each input circuit.

Returns:
A `CompilerOutput` object with the compiled circuit(s) and a list of jaqal programs
represented as strings.
"""
compiled_circuits: list[cirq.Circuit] | list[list[cirq.Circuit]]
compiled_circuits = css.serialization.deserialize_circuits(json_dict["cirq_circuits"])

initial_logical_to_physicals_list: list[dict[cirq.Qid, cirq.Qid]] = list(
map(dict, cirq.read_json(json_text=json_dict["initial_logical_to_physicals"]))
)
initial_logical_to_physicals: (
list[dict[cirq.Qid, cirq.Qid]] | list[list[dict[cirq.Qid, cirq.Qid]]]
) = initial_logical_to_physicals_list

final_logical_to_physicals_list: list[dict[cirq.Qid, cirq.Qid]] = list(
map(dict, cirq.read_json(json_text=json_dict["final_logical_to_physicals"]))
)
final_logical_to_physicals: (
list[dict[cirq.Qid, cirq.Qid]] | list[list[dict[cirq.Qid, cirq.Qid]]]
) = final_logical_to_physicals_list

jaqal_programs: list[str] = json_dict["jaqal_programs"]

if num_eca_circuits:
compiled_circuits = [
compiled_circuits[i : i + num_eca_circuits]
for i in range(0, len(compiled_circuits), num_eca_circuits)
]
initial_logical_to_physicals = [
initial_logical_to_physicals_list[i : i + num_eca_circuits]
for i in range(0, len(initial_logical_to_physicals_list), num_eca_circuits)
]
final_logical_to_physicals = [
final_logical_to_physicals_list[i : i + num_eca_circuits]
for i in range(0, len(final_logical_to_physicals_list), num_eca_circuits)
]
jaqal_programs = [
gss.compiler_output._jaqal_programs_to_subcircuits(
jaqal_programs[i : i + num_eca_circuits]
)
for i in range(0, len(jaqal_programs), num_eca_circuits)
]

if circuits_is_list:
return CompilerOutput(
compiled_circuits,
initial_logical_to_physicals,
final_logical_to_physicals,
jaqal_programs=jaqal_programs,
)

return CompilerOutput(
compiled_circuits[0],
initial_logical_to_physicals[0],
final_logical_to_physicals[0],
jaqal_programs=jaqal_programs,
)
Loading