Results API

class JobResults

Access to the results of a QmJob

This object is created by calling QmJob.result_handles

Assuming you have an instance of JobResults:

job_results:JobResults

This object is iterable:

for name, handle in job_results:
    print(name)

Can detect if a name exists:

if "somename" in job_results:
    print("somename exists!")
    handle = job_results.get("somename")
get(name: str) → Union[qm._results.MultipleNamedJobResult, qm._results.SingleNamedJobResult, None]

Get a handle to a named result from stream_processing

Parameters

name – The named result using in stream_processing

Returns

A handle object to the results MultipleNamedJobResult or SingleNamedJobResult or None if the named results in unknown

get_debug_data(writer: Union[_io.BufferedWriter, _io.BytesIO, str, None] = None)
Returns

debugging data to report to QM

is_processing() → bool

Check if the job is still processing results

Returns

True if results are still being processed, False otherwise

save_to_store(writer: Union[_io.BufferedWriter, _io.BytesIO, str, None] = None, **kwargs)

Save all results to store (file system by default) in a single NPZ file

Parameters

writer – An optional writer to be used instead of the pre-populated store passed to qm.QuantumMachinesManager.QuantumMachinesManager

Key flat_struct

results will have a flat structure - dimensions will be

part of the shape and not of the type

wait_for_all_values(timeout: Optional[float] = None) → bool

Wait until we know all values were processed for all named results

Parameters

timeout – Timeout for waiting in seconds

Returns

True if all finished successfully, False if any result was closed before done

class MultipleNamedJobResult

A handle to a result of a pipeline terminating with save_all

count_so_far() → int

also len(handle)

Returns

The number of values this result has so far

fetch(item: Union[int, slice], **kwargs) → numpy.array

Fetch a result from the current result stream saved in server memory. The result stream is populated by the save() and save_all() statements. Note that if save_all() statements are used, calling this function twice with the same item index may give different results.

Parameters

item – The index of the result in the saved results stream.

Key flat_struct

results will have a flat structure - dimensions will be

part of the shape and not of the type :return: a single result if item is integer or multiple results if item is Python slice object.

Example:: >>>res.fetch(0) #return the item in the top position >>>res.fetch(1) #return the item in position number 2 >>>res.fetch(slice(1,6))# return items from position 1 to position 6 inclusive

fetch_all(**kwargs)

Fetch a result from the current result stream saved in server memory. The result stream is populated by the save() and save_all() statements. Note that if save_all() statements are used, calling this function twice

may give different results.

Key flat_struct

results will have a flat structure - dimensions will be

part of the shape and not of the type

Returns

all result of current result stream

has_dataloss() → bool
Returns

if there was data loss during job execution

property job_id

The job id this result came from

property name

The name of result this handle is connected to

save_to_store(writer: Union[_io.BufferedWriter, _io.BytesIO, str, None] = None, **kwargs) → int

Saving to persistent store the NPY data of this result handle

Parameters

writer – An optional writer to override the store defined in QuantumMachinesManager

Key flat_struct

results will have a flat structure - dimensions will be

part of the shape and not of the type :return: The number of items saved

wait_for_all_values(timeout: Optional[float] = None) → bool

Wait until we know all values were processed for this named result

Parameters

timeout – Timeout for waiting in seconds

Returns

True if job finished successfully and False if job has closed before done

wait_for_values(count: int = 1, timeout: Optional[float] = None)

Wait until we know at least count values were processed for this named result

Parameters
  • count – The number of items to wait for

  • timeout – Timeout for waiting in seconds

Returns

class SingleNamedJobResult

A handle to a result of a pipeline terminating with save

count_so_far() → int

also len(handle)

Returns

The number of values this result has so far

fetch(item: Union[int, slice], **kwargs)

Fetch a single result from the current result stream saved in server memory. The result stream is populated by the save().

Parameters

item – ignored

Key flat_struct

results will have a flat structure - dimensions will be

part of the shape and not of the type

Returns

the current result

Example:: >>>res.fetch() #return the item in the top position

fetch_all(**kwargs)

Fetch a result from the current result stream saved in server memory. The result stream is populated by the save() and save_all() statements. Note that if save_all() statements are used, calling this function twice

may give different results.

Key flat_struct

results will have a flat structure - dimensions will be

part of the shape and not of the type

Returns

all result of current result stream

has_dataloss() → bool
Returns

if there was data loss during job execution

property job_id

The job id this result came from

property name

The name of result this handle is connected to

save_to_store(writer: Union[_io.BufferedWriter, _io.BytesIO, str, None] = None, **kwargs) → int

Saving to persistent store the NPY data of this result handle

Parameters

writer – An optional writer to override the store defined in QuantumMachinesManager

Key flat_struct

results will have a flat structure - dimensions will be

part of the shape and not of the type :return: The number of items saved

wait_for_all_values(timeout: Optional[float] = None) → bool

Wait until we know all values were processed for this named result

Parameters

timeout – Timeout for waiting in seconds

Returns

True if job finished successfully and False if job has closed before done

wait_for_values(count: int = 1, timeout: Optional[float] = None)

Wait until we know at least count values were processed for this named result

Parameters
  • count – The number of items to wait for

  • timeout – Timeout for waiting in seconds

Returns