IterationTracker#

Module: iqm.iqm_client.iqm_client

class iqm.iqm_client.iqm_client.IterationTracker(client: IQMClient, iteration_data: IterationData)#

Bases: object

Context and lifecycle manager for an iteration on IQM Server.

An iteration is an exclusive timeslot for a particular quantum computer on IQM Server, during which only the jobs the iteration owner submits to the iteration-specific job queue are being executed on that quantum computer. Hence it e.g. enables workflows based on quick quantum-classical iteration, such as various quantum optimization algorithms. Unlike the normal timeslots which are reserved in advance and take place during a fixed time interval, iterations can be requested on demand, and can be ended at any time.

  • A new iteration is requested using IQMClient.request_iteration(), which returns an instance of this class if successful. The request goes into the normal server job queue, and once it reaches the front of the queue the iteration becomes active.

  • An existing iteration can be queried using IQMClient.get_iteration().

The user is billed for the entire time from when the iteration becomes active, until either the iteration or the last executed job in the iteration ends, whichever comes last. This means that keeping the iteration active costs, whether jobs are executing in it or not, since it reserves the quantum computer for your exclusive use.

The user can end the iteration anytime (even before it has become active) using end(). This will also cancel the jobs submitted into the iteration that have not started executing yet. The same happens if the iteration ends on its own when it reaches its maximum duration. The currently executing job(s) are allowed to finish. IterationTracker can be used as a context manager, in which case it ends the iteration automatically when you exit the context.

For the exact description on how the iteration workflow and billing works, see the IQM Server API documentation on IQM Resonance.

Parameters:
  • client (IQMClient) – Client used to connect to the server.

  • iteration_data (IterationData) – Properties of the iteration, obtained from IQM Server.

Attributes

iteration_id

Unique ID of the iteration.

status

Last queried status of the iteration.

client

IQMClient used to connect to the server where the iteration takes place.

iteration_data

Last known status and other properties of the iteration.

Methods

end

End the iteration.

jobs

Get trackers for all the jobs submitted to the given iteration.

submit_circuits

Submit a batch of quantum circuits for execution in the iteration.

submit_playlist

Submit a run definition for execution.

update

Refresh iteration_data by querying the server, unless the status is already terminal.

wait_until_active

Poll the server for the iteration status until it is no longer WAITING, or until we hit a timeout.

client#

IQMClient used to connect to the server where the iteration takes place.

iteration_data#

Last known status and other properties of the iteration. Updated by update(), wait_until_active() and end().

property iteration_id: UUID#

Unique ID of the iteration.

property status: IterationStatus#

Last queried status of the iteration.

Note

This is not necessarily the same as the current status of the iteration, unless the status is terminal! To get the current status, use update().

update() → IterationStatus#

Refresh iteration_data by querying the server, unless the status is already terminal.

Once the iteration reaches a terminal status (see IterationStatus.terminal_statuses()), iteration_data no longer changes, so this method skips the server query and returns the cached status instead.

Returns:

Current status of the iteration (included in the refreshed iteration data).

Return type:

IterationStatus

wait_until_active(*, timeout_secs: float = 10800.0, polling_interval: float = 1.0) → IterationStatus#

Poll the server for the iteration status until it is no longer WAITING, or until we hit a timeout.

The iteration stops waiting either by becoming IterationStatus.ACTIVE, or by reaching a terminal status (see IterationStatus.terminal_statuses()) without ever becoming active, e.g. if it is ended before its turn comes up.

Will stop the polling (but does not end the iteration) upon receiving a KeyboardInterrupt (Ctrl-C). If you want to end the iteration, call end().

Updates iteration_data.

Parameters:
  • timeout_secs (float) – Maximum time to wait (in seconds). If nonzero, the method will return the last polled status after this period even if it is still IterationStatus.WAITING.

  • polling_interval (float) – Time to wait (in seconds) between successive polling requests.

Returns:

Last seen iteration status. Not necessarily IterationStatus.ACTIVE, see above.

Raises:

KeyboardInterrupt – Received Ctrl-C while waiting for the iteration to become active.

Return type:

IterationStatus

jobs() → Iterator[JobTracker]#

Get trackers for all the jobs submitted to the given iteration.

Returns:

Trackers for each job submitted to the iteration.

Return type:

Iterator[JobTracker]

end() → None#

End the iteration.

See IQMServerExecutor.end_iteration() for the exact semantics of ending an iteration, and the statuses involved.

Updates iteration_data.

Return type:

None

submit_circuits(circuits: list[Circuit | _Circuit | str], *, qubit_mapping: WithJsonSchema(json_schema={'anyOf': [{'type': 'array', 'items': {'type': 'object', 'required': ['logical_name', 'physical_name'], 'properties': {'logical_name': {'type': 'string'}, 'physical_name': {'type': 'string'}}, 'additionalProperties': False}}, {'type': 'null'}]}, mode=None)] | None = None, calibration_set_id: UUID | None = None, shots: int = 1, options: CircuitCompilationOptions | None = None) → CircuitJobTracker#

Submit a batch of quantum circuits for execution in the iteration.

See IQMClient.submit_circuits().

Parameters:
  • circuits (list[Circuit | _Circuit | str])

  • qubit_mapping (Annotated[dict[str, str], BeforeValidator(func=~iqm.station_control.interface.models.circuit._parse_legacy_qubit_mapping, json_schema_input_type=PydanticUndefined), PlainSerializer(func=~iqm.station_control.interface.models.circuit._serialize_as_legacy_qubit_mapping, return_type=PydanticUndefined, when_used=always), WithJsonSchema(json_schema={'anyOf': [{'type': 'array', 'items': {'type': 'object', 'required': ['logical_name', 'physical_name'], 'properties': {'logical_name': {'type': 'string'}, 'physical_name': {'type': 'string'}}, 'additionalProperties': False}}, {'type': 'null'}]}, mode=None)] | None)

  • calibration_set_id (UUID | None)

  • shots (int)

  • options (CircuitCompilationOptions | None)

Return type:

CircuitJobTracker

submit_playlist(run_definition: RunDefinition, *, context: dict[str, Any]) → RunJobTracker#

Submit a run definition for execution.

See IQMClient.submit_playlist().

Parameters:
  • run_definition (RunDefinition)

  • context (dict[str, Any])

Return type:

RunJobTracker

Inheritance

Inheritance diagram of iqm.iqm_client.iqm_client.IterationTracker