Local Storage

from mpqp.local_storage import *

The local_storage module is responsible for handling the storage of results and jobs data locally on the user’s device using a SQLite database. The functions defined here are for the most part callable directly on the Result, BatchResult and Job classes.

Functions provided here are decomposed in two broad categories:

  • the ones used to interact with MPQP objects by the end user, presented in sections Saving, Loading and Deleting,

  • the ones used to interact more closely with the database, aimed more at internal use, presented in sections The Setup and Querying.

Saving

Provides functions to insert Job and Result into the local database.

insert_jobs(jobs)[source]

Insert a job in the database.

Method corresponding: save().

Parameters

jobs (mpqp.execution.job.Job | list[mpqp.execution.job.Job]) – The job(s) to be inserted.

Returns

The ID of the newly inserted job.

Return type

list[int]

Example

>>> job = Job(JobType.STATE_VECTOR, QCircuit(2), IBMDevice.AER_SIMULATOR)
>>> insert_jobs(job)
[7]
insert_results(result, reuse_similar_job=True)[source]

Insert a result or batch result into the database.

Methods corresponding: Result.save and BatchResult.save.

Parameters
Returns

List of IDs of the inserted result(s).

Return type

list[int]

Example

>>> result = Result(Job(JobType.STATE_VECTOR, QCircuit(2), IBMDevice.AER_SIMULATOR), StateVector([1, 0, 0, 0]))
>>> insert_results(result)
[8]

Loading

This module provides utility functions retrieving jobs and results from local storage. In the process, they are converted to MPQP objects (Job and Result).

get_all_jobs()[source]

Retrieve all jobs from the local storage and convert them into Job.

Method of the class corresponding: load_all().

Returns

All locally stored jobs.

Return type

list[mpqp.execution.job.Job]

Example

>>> for job in get_all_jobs(): 
...     print(job)
Job(JobType.SAMPLE, QCircuit(...), IBMDevice.AER_SIMULATOR, BasisMeasure(...))
Job(JobType.SAMPLE, QCircuit(...), GOOGLEDevice.CIRQ_LOCAL_SIMULATOR, BasisMeasure(...))
Job(JobType.SAMPLE, QCircuit(...), IBMDevice.AER_SIMULATOR, BasisMeasure(...))
Job(JobType.SAMPLE, QCircuit(...), GOOGLEDevice.CIRQ_LOCAL_SIMULATOR, BasisMeasure(...))
Job(JobType.STATE_VECTOR, QCircuit(...), IBMDevice.AER_SIMULATOR)
Job(JobType.STATE_VECTOR, QCircuit(...), IBMDevice.AER_SIMULATOR)
get_all_results()[source]

Retrieve all results from the local storage and convert them into Result.

Method of the class corresponding: load_all().

Returns

All locally stored results.

Return type

list[mpqp.execution.result.Result]

Example

>>> for result in get_all_results(): 
...     print(repr(result))
Result(Job(JobType.SAMPLE, QCircuit(...), IBMDevice.AER_SIMULATOR, BasisMeasure(...), [Sample(...), Sample(...)], None, 1024)
Result(Job(JobType.SAMPLE, QCircuit(...), IBMDevice.AER_SIMULATOR, BasisMeasure(...), [Sample(...), Sample(...)], None, 1024)
Result(Job(JobType.SAMPLE, QCircuit(...), GOOGLEDevice.CIRQ_LOCAL_SIMULATOR, BasisMeasure(...), [Sample(...), Sample(...)], None, 1024)
Result(Job(JobType.SAMPLE, QCircuit(...), IBMDevice.AER_SIMULATOR, BasisMeasure(...), [Sample(...), Sample(...)], None, 1024)
Result(Job(JobType.SAMPLE, QCircuit(...), GOOGLEDevice.CIRQ_LOCAL_SIMULATOR, BasisMeasure(...), [Sample(...), Sample(...)], None, 1024)
Result(Job(JobType.STATE_VECTOR, QCircuit(...), IBMDevice.AER_SIMULATOR), StateVector(...), 0, 0)
Result(Job(JobType.STATE_VECTOR, QCircuit(...), IBMDevice.AER_SIMULATOR), StateVector(...), 0, 0)
get_jobs_with_id(job_id)[source]

Retrieve jobs with the given ID(s).

Method of the class corresponding: load_by_local_id().

Parameters

job_id (int | list[int]) – ID(s) to search for.

Returns

Job(s) corresponding to the id(s).

Return type

list[mpqp.execution.job.Job]

Example

>>> jobs = get_jobs_with_id([1, 2, 3])
>>> for job in jobs: 
...     print(job)
Job(JobType.SAMPLE, QCircuit(...), IBMDevice.AER_SIMULATOR, BasisMeasure(...))
Job(JobType.SAMPLE, QCircuit(...), GOOGLEDevice.CIRQ_LOCAL_SIMULATOR, BasisMeasure(...))
Job(JobType.SAMPLE, QCircuit(...), IBMDevice.AER_SIMULATOR, BasisMeasure(...))
get_jobs_with_job(job)[source]

Retrieve job(s) matching the given job(s) attributes from the database

  • job type,

  • circuit,

  • device,

  • measure.

Method of the class corresponding: load_similar().

Parameters

job (mpqp.execution.job.Job | list[mpqp.execution.job.Job]) – Job(s) to search for.

Returns

Matching job(s) corresponding to the job(s) attributes

Return type

list[mpqp.execution.job.Job]

Example

>>> job = Job(JobType.STATE_VECTOR, QCircuit([], nb_qubits=2, label="circuit 1"), IBMDevice.AER_SIMULATOR)
>>> print(get_jobs_with_job(job)) 
[Job(JobType.STATE_VECTOR, QCircuit(...), IBMDevice.AER_SIMULATOR)]
get_jobs_with_result(result)[source]

Retrieve job(s) associated with the given result(s) attributes from the database:

  • data,

  • error,

  • shots.

Parameters

result (mpqp.execution.result.Result | list[mpqp.execution.result.Result] | mpqp.execution.result.BatchResult) – Result(s) to find associated jobs for.

Returns

Matching job(s) corresponding to the result(s) attribute and job attribute of the result(s).

Return type

list[mpqp.execution.job.Job]

Example

>>> result = Result(
...     Job(JobType.STATE_VECTOR, QCircuit([], nb_qubits=2, label="circuit 1"), IBMDevice.AER_SIMULATOR),
...     StateVector([1, 0, 0, 0]),
...     0,
...     0,
... )
>>> print(get_jobs_with_result(result)) 
[Job(JobType.STATE_VECTOR, QCircuit(...), IBMDevice.AER_SIMULATOR)]
get_results_with_id(result_id)[source]

Retrieve results with the given ID(s).

Method of the class corresponding: load_by_local_id().

Parameters

result_id (int | list[int]) – ID(s) to search for.

Returns

Matching result(s) corresponding to the id(s).

Return type

list[mpqp.execution.result.Result]

Example

>>> for result in get_results_with_id(1): 
...     print(repr(result))
Result(Job(JobType.SAMPLE, QCircuit(...), IBMDevice.AER_SIMULATOR, BasisMeasure(...), [Sample(...), Sample(...)], None, 1024)
>>> for result in get_results_with_id([2, 3]): 
...     print(repr(result))
Result(Job(JobType.SAMPLE, QCircuit(...), IBMDevice.AER_SIMULATOR, BasisMeasure(...), [Sample(...), Sample(...)], None, 1024)
Result(Job(JobType.SAMPLE, QCircuit(...), GOOGLEDevice.CIRQ_LOCAL_SIMULATOR, BasisMeasure(...), [Sample(...), Sample(...)], None, 1024)
get_results_with_job_id(job_id)[source]

Retrieve results associated with the given job ID(s).

Method of the class corresponding: load_by_local_job_id().

Parameters

job_id (int | list[int]) – ID(s) to search for.

Returns

Results corresponding to the job id(s).

Return type

list[mpqp.execution.result.Result]

Example

>>> results = get_results_with_job_id(1)
>>> for result in results: 
...     print(repr(result))
Result(Job(JobType.SAMPLE, QCircuit(...), IBMDevice.AER_SIMULATOR, BasisMeasure(...), [Sample(...), Sample(...)], None, 1024)
Result(Job(JobType.SAMPLE, QCircuit(...), IBMDevice.AER_SIMULATOR, BasisMeasure(...), [Sample(...), Sample(...)], None, 1024)
get_results_with_result(result)[source]

Retrieve result(s) matching specific result(s) attributes:

  • data,

  • error,

  • shots.

Method of the class corresponding: load_similar().

Parameters

result (mpqp.execution.result.Result | list[mpqp.execution.result.Result] | mpqp.execution.result.BatchResult) – Result(s) to search for.

Returns

Matching result(s) corresponding to the result(s) attribute.

Return type

list[mpqp.execution.result.Result]

Example

>>> result = Result(
...     Job(JobType.STATE_VECTOR, QCircuit([], nb_qubits=2, label="circuit 1"), IBMDevice.AER_SIMULATOR),
...     StateVector([1, 0, 0, 0]),
...     0,
...     0,
... )
>>> for result in get_results_with_result(result): 
...     print(repr(result))
Result(Job(JobType.STATE_VECTOR, QCircuit(...), IBMDevice.AER_SIMULATOR), StateVector(...), 0, 0)
Result(Job(JobType.STATE_VECTOR, QCircuit(...), IBMDevice.AER_SIMULATOR), StateVector(...), 0, 0)
get_results_with_result_and_job(result)[source]

Retrieve result(s) associated with specific result(s) attributes:

  • data,

  • error,

  • shots.

And also with the job attribute of the result(s):

  • job type,

  • circuit,

  • device,

  • measure.

Parameters

result (mpqp.execution.result.Result | list[mpqp.execution.result.Result] | mpqp.execution.result.BatchResult) – Result(s) to search for.

Returns

Matching result(s) corresponding to the result(s) attribute and job attribute of the result(s).

Return type

list[mpqp.execution.result.Result]

Example

>>> result = Result(
...     Job(JobType.STATE_VECTOR, QCircuit([], nb_qubits=2, label="circuit 1"), IBMDevice.AER_SIMULATOR),
...     StateVector([1, 0, 0, 0]),
...     0,
...     0,
... )
>>> for result in get_results_with_result_and_job(result): 
...     print(repr(result))
Result(Job(JobType.STATE_VECTOR, QCircuit(...), IBMDevice.AER_SIMULATOR), StateVector(...), 0, 0)
jobs_local_storage_to_mpqp(jobs)[source]

Convert a dictionary or list of dictionaries representing jobs into MPQP Job objects.

Parameters

jobs (Optional[Union[list[dict[str, Any]], dict[str, Any]]]) – A dictionary or list of dictionaries retrieved from the database.

Returns

A list of MPQP Job objects.

Return type

list[mpqp.execution.job.Job]

Example

>>> job_local_storage = fetch_jobs_with_id(1)
>>> jobs_local_storage_to_mpqp(job_local_storage) 
[Job(JobType.SAMPLE, QCircuit(...), IBMDevice.AER_SIMULATOR, BasisMeasure(...))]
results_local_storage_to_mpqp(results)[source]

Convert a dictionary or list of dictionaries representing results into a Result.

Parameters

results (Optional[Union[list[dict[str, Any]], dict[str, Any]]]) – The results retrieved from the database.

Returns

The converted result(s).

Return type

list[mpqp.execution.result.Result]

Example

>>> result_local_storage = fetch_results_with_id([1, 2])
>>> results = results_local_storage_to_mpqp(result_local_storage)
>>> for result in results:  
...     print(repr(result))
Result(Job(JobType.SAMPLE, QCircuit(...), IBMDevice.AER_SIMULATOR, BasisMeasure(...), [Sample(2, index=0, count=..., probability=0...), ...], None, 1024)
Result(Job(JobType.SAMPLE, QCircuit(...), IBMDevice.AER_SIMULATOR, BasisMeasure(...), [Sample(2, index=0, count=..., probability=0...), ...], None, 1024)

Deleting

clear_local_storage()[source]

Clears all records from the database, including jobs and results.

This function resets the tables and their auto-increment counters.

Example

>>> clear_local_storage()
>>> fetch_all_results()
[]
>>> fetch_all_jobs()
[]
remove_all_with_job_id(job_id)[source]

Removes jobs and their associated results for the specified job IDs.

Parameters

job_id (int | list[int]) – Job ID(s) to remove.

Example

>>> remove_all_with_job_id(1)
>>> fetch_jobs_with_id(1)
[]
>>> fetch_results_with_job_id(1)
[]
>>> remove_all_with_job_id([2, 3])
>>> fetch_jobs_with_id([2, 3])
[]
>>> fetch_results_with_job_id([2, 3])
[]
remove_jobs_with_id(job_id)[source]

Removes jobs with the specified job IDs.

Method of the class corresponding: delete_by_local_id().

Parameters

job_id (int | list[int]) – Job ID(s) to remove.

Example

>>> remove_jobs_with_id(1)
>>> fetch_jobs_with_id(1)
[]
>>> remove_jobs_with_id([2, 3])
>>> fetch_jobs_with_id([2,3])
[]
remove_jobs_with_jobs_local_storage(jobs)[source]

Removes the matching jobs.

Parameters

jobs (Optional[Union[list[dict[str, Any]], dict[str, Any]]]) – Job dictionary(ies) for which the matching database row should be deleted.

Example

>>> jobs = fetch_jobs_with_id(1)
>>> remove_jobs_with_jobs_local_storage(jobs)
>>> fetch_jobs_with_id(1)
[]
remove_results_with_id(result_id)[source]

Removes results with the specified result IDs.

Method of the class corresponding: delete_by_local_id().

Parameters

result_id (int | list[int]) – Result ID(s) to remove.

Example

>>> remove_results_with_id(1)
>>> fetch_results_with_id(1)
[]
>>> remove_results_with_id([2, 3])
>>> fetch_results_with_id([2, 3])
[]
remove_results_with_job(jobs)[source]

Removes results associated with the specified job(s).

Parameters

jobs (mpqp.execution.job.Job | list[mpqp.execution.job.Job]) – Job(s) to remove results for.

Example

>>> job = Job(JobType.STATE_VECTOR, QCircuit(2), IBMDevice.AER_SIMULATOR)
>>> remove_results_with_job(job)
>>> fetch_results_with_job(job)
[]
remove_results_with_job_id(job_id)[source]

Removes results related to the job(s) who’s ID is given as input.

Parameters

job_id (int | list[int]) – Result Job_ID(s) to remove.

Example

>>> remove_results_with_job_id(1)
>>> fetch_results_with_job_id(1)
[]
>>> remove_results_with_job_id([2, 3])
>>> fetch_results_with_job_id([2, 3])
[]
remove_results_with_result(result)[source]

Removes results matching the given result(s).

Parameters

result (mpqp.execution.result.Result | mpqp.execution.result.BatchResult | list[mpqp.execution.result.Result]) – Result(s) to remove.

Example

>>> result = Result(Job(JobType.STATE_VECTOR, QCircuit(2), IBMDevice.AER_SIMULATOR), StateVector([1, 0, 0, 0]))
>>> remove_results_with_result(result)
>>> fetch_results_with_result(result)
[]
remove_results_with_results_local_storage(results)[source]

Removes the matching results.

Parameters

results (Optional[Union[list[dict[str, Any]], dict[str, Any]]]) – Result dictionary(ies) for which the matching database row should be deleted.

Example

>>> results = fetch_results_with_id(1)
>>> remove_results_with_results_local_storage(results)
>>> fetch_results_with_id(1)
[]

The Setup

This module provides utilities for managing a SQLite database for quantum job and result records, as well as functions for removing entries based on various criteria.

It allows storing and managing job and result metadata related to quantum circuit executions.

ensure_local_storage(func)[source]

Decorator for functions needing the database to be present.

Parameters

func (Callable[[...], T]) – The function to be decorated.

Return type

Callable[[…], T]

get_database_version()[source]

Retrieves the current database version from the version table.

Return type

str

setup_local_storage(path=None)[source]

Sets up a SQLite database for storing quantum job and result records.

Two tables will be created, one for jobs and the other for results.

Parameters

path (Optional[str]) – Directory to save the database file. Defaults to the current working directory.

Example

>>> setup_local_storage("~/documents/my_database.db")
>>> os.remove(Path("~/documents/my_database.db").expanduser())
>>> setup_local_storage("my_database.db")
>>> os.remove("my_database.db")
>>> setup_local_storage()

Querying

provides utility functions to query and fetch data from the quantum job and result database. It includes methods to retrieve all records, specific records by ID, and filtered records based on Job or Result objects.

fetch_all_jobs()[source]

Fetch all job records from the database.

Returns

All jobs as dictionaries.

Return type

list[dict[str, Any]]

Examples

>>> jobs = fetch_all_jobs()
>>> for job in jobs:
...    print("job:", job) 
job: {'id': 1, 'type': 'SAMPLE', 'circuit': '"QCircuit(...)"', 'device': 'IBMDevice.AER_SIMULATOR', 'measure': '"BasisMeasure([0, 1], c_targets=[0, 1])"', 'remote_id': None, 'status': None, 'created_at': '...'}
job: {'id': 2, 'type': 'SAMPLE', 'circuit': '"QCircuit(...)"', 'device': 'GOOGLEDevice.CIRQ_LOCAL_SIMULATOR', 'measure': '"BasisMeasure([0, 1], c_targets=[0, 1])"', 'remote_id': None, 'status': None, 'created_at': '...'}
job: {'id': 3, 'type': 'SAMPLE', 'circuit': '"QCircuit(...)"', 'device': 'IBMDevice.AER_SIMULATOR', 'measure': '"BasisMeasure([0], c_targets=[0])"', 'remote_id': None, 'status': None, 'created_at': '...'}
job: {'id': 4, 'type': 'SAMPLE', 'circuit': '"QCircuit(...)"', 'device': 'GOOGLEDevice.CIRQ_LOCAL_SIMULATOR', 'measure': '"BasisMeasure([0], c_targets=[0])"', 'remote_id': None, 'status': None, 'created_at': '...'}
job: {'id': 5, 'type': 'STATE_VECTOR', 'circuit': '"QCircuit(...)"', 'device': 'IBMDevice.AER_SIMULATOR', 'measure': None, 'remote_id': None, 'status': None, 'created_at': '...'}
job: {'id': 6, 'type': 'STATE_VECTOR', 'circuit': '"QCircuit(...)"', 'device': 'IBMDevice.AER_SIMULATOR', 'measure': None, 'remote_id': None, 'status': None, 'created_at': '...'}
fetch_all_results()[source]

Fetch all result records from the database.

Returns

All results as dictionaries.

Return type

list[dict[str, Any]]

Examples

>>> results = fetch_all_results()
>>> for result in results:
...    print("result:", result) 
result: {'id': 1, 'job_id': 1, 'data': '"[Sample(...), Sample(...)]"', 'error': None, 'shots': 1024, 'created_at': '...'}
result: {'id': 2, 'job_id': 1, 'data': '"[Sample(...), Sample(...)]"', 'error': None, 'shots': 1024, 'created_at': '...'}
result: {'id': 3, 'job_id': 2, 'data': '"[Sample(...), Sample(...)]"', 'error': None, 'shots': 1024, 'created_at': '...'}
result: {'id': 4, 'job_id': 3, 'data': '"[Sample(...), Sample(...)]"', 'error': None, 'shots': 1024, 'created_at': '...'}
result: {'id': 5, 'job_id': 4, 'data': '"[Sample(...), Sample(...)]"', 'error': None, 'shots': 1024, 'created_at': '...'}
result: {'id': 6, 'job_id': 5, 'data': '"StateVector([1, 0, 0, 0])"', 'error': '"0"', 'shots': 0, 'created_at': '...'}
result: {'id': 7, 'job_id': 6, 'data': '"StateVector([1, 0, 0, 0])"', 'error': '"0"', 'shots': 0, 'created_at': '...'}
fetch_jobs_with_id(job_id)[source]

Fetch job(s) by their ID(s).

Parameters

job_id (int | list[int]) – The ID(s) of the job(s) to fetch.

Returns

Matching job(s) as dictionaries corresponding to the id(s).

Return type

list[dict[str, Any]]

Examples

>>> jobs = fetch_jobs_with_id(1)
>>> for job in jobs:
...    print("job_id:", job['id'])
job_id: 1
>>> jobs = fetch_jobs_with_id([2, 3])
>>> for job in jobs:
...    print("job_id:", job['id'])
job_id: 2
job_id: 3
fetch_jobs_with_job(job)[source]

Fetch job(s) records matching specific job(s) attributes:

  • job type,

  • circuit,

  • device,

  • measure.

Parameters

job (mpqp.execution.job.Job | list[mpqp.execution.job.Job]) – Job(s) to match.

Returns

Matching job(s) as dictionaries corresponding to the job(s) attributes

Return type

list[dict[str, Any]]

Examples

>>> job = Job(JobType.STATE_VECTOR, QCircuit([], nb_qubits=2, label="circuit 1"), IBMDevice.AER_SIMULATOR)
>>> jobs = fetch_jobs_with_job(job)
>>> for job in jobs:
...    print("job:", job) 
job: {'id': 5, 'type': 'STATE_VECTOR', 'circuit': '"QCircuit(...)"', 'device': 'IBMDevice.AER_SIMULATOR', 'measure': None, 'remote_id': None, 'status': None, 'created_at': '...'}
fetch_jobs_with_result(result)[source]

Fetch job(s) associated with specific results(s) attributes:

  • data,

  • error,

  • shots.

Parameters

result (mpqp.execution.result.Result | mpqp.execution.result.BatchResult | list[mpqp.execution.result.Result]) – Result(s) to match.

Returns

Matching job(s) as dictionaries corresponding to the result(s) attribute.

Return type

list[dict[str, Any]]

Examples

>>> result = Result(Job(JobType.STATE_VECTOR, QCircuit([], nb_qubits=2, label="circuit 1"), IBMDevice.AER_SIMULATOR,), StateVector([1, 0, 0, 0]),0,0)
>>> jobs = fetch_jobs_with_result(result)
>>> for job in jobs:
...    print("job:", job) 
job: {'id': 5, 'type': 'STATE_VECTOR', 'circuit': '"QCircuit(...)"', 'device': 'IBMDevice.AER_SIMULATOR', 'measure': None, 'remote_id': None, 'status': None, 'created_at': '...'}
job: {'id': 6, 'type': 'STATE_VECTOR', 'circuit': '"QCircuit(...)"', 'device': 'IBMDevice.AER_SIMULATOR', 'measure': None, 'remote_id': None, 'status': None, 'created_at': '...'}
fetch_jobs_with_result_and_job(result)[source]

Fetch job(s) associated with specific results(s) attributes:

  • data,

  • error,

  • shots.

And also with the job attribute of the results(s):

  • job type,

  • circuit,

  • device,

  • measure.

Parameters

result (mpqp.execution.result.Result | mpqp.execution.result.BatchResult | list[mpqp.execution.result.Result]) – Result(s) to match.

Returns

Matching job(s) as dictionaries corresponding to the result(s) attribute and job attribute of the result(s).

Return type

list[dict[str, Any]]

Examples

>>> result = Result(Job(JobType.STATE_VECTOR, QCircuit([], nb_qubits=2, label="circuit 1"), IBMDevice.AER_SIMULATOR,), StateVector([1, 0, 0, 0]),0,0)
>>> jobs = fetch_jobs_with_result_and_job(result)
>>> for job in jobs:
...    print("job:", job) 
job: {'id': 5, 'type': 'STATE_VECTOR', 'circuit': '"QCircuit(...)"', 'device': 'IBMDevice.AER_SIMULATOR', 'measure': None, 'remote_id': None, 'status': None, 'created_at': '...'}
fetch_results_with_id(result_id)[source]

Fetch result(s) by their ID(s).

Parameters

result_id (int | list[int]) – The ID(s) of the result(s) to fetch.

Returns

Matching result(s) as dictionaries corresponding to the id(s).

Return type

list[dict[str, Any]]

Examples

>>> results = fetch_results_with_id([1, 2, 3])
>>> for result in results:
...    print("result:", result) 
result: {'id': 1, 'job_id': 1, 'data': '"[Sample(...), Sample(...)]"', 'error': None, 'shots': 1024, 'created_at': '...'}
result: {'id': 2, 'job_id': 1, 'data': '"[Sample(...), Sample(...)]"', 'error': None, 'shots': 1024, 'created_at': '...'}
result: {'id': 3, 'job_id': 2, 'data': '"[Sample(...), Sample(...)]"', 'error': None, 'shots': 1024, 'created_at': '...'}
fetch_results_with_job(jobs)[source]

Fetch result(s) associated with the job attribute of the results(s)

  • job type,

  • circuit,

  • device,

  • measure.

Parameters

jobs (mpqp.execution.job.Job | list[mpqp.execution.job.Job]) – The job(s) to match.

Returns

Matching result(s) as dictionaries corresponding to job attribute of the result(s).

Return type

list[dict[str, Any]]

Examples

>>> job = Job(JobType.STATE_VECTOR, QCircuit([], nb_qubits=2, label="circuit 1"), IBMDevice.AER_SIMULATOR)
>>> results = fetch_results_with_job(job)
>>> for result in results:
...    print("result:", result) 
result: {'id': 6, 'job_id': 5, 'data': '"StateVector([1, 0, 0, 0])"', 'error': '"0"', 'shots': 0, 'created_at': '...'}
fetch_results_with_job_id(job_id)[source]

Fetch result(s) associated with specific job ID(s).

Parameters

job_id (int | list[int]) – The ID(s) of job(s) to which the desired result(s) are attached.

Returns

Matching result(s) as dictionaries corresponding to the job id(s).

Return type

list[dict[str, Any]]

Examples

>>> results = fetch_results_with_job_id(1)
>>> for result in results:
...    print("result_id:", result['id'], ", job_id:", result['job_id'])
result_id: 1 , job_id: 1
result_id: 2 , job_id: 1
fetch_results_with_result(result)[source]

Fetch result(s) matching specific results(s) attributes:

  • data,

  • error,

  • shots.

Parameters

result (mpqp.execution.result.Result | mpqp.execution.result.BatchResult | list[mpqp.execution.result.Result]) – The result(s) to match.

Returns

Matching result(s) as dictionaries corresponding to the result(s) attribute.

Return type

list[dict[str, Any]]

Examples

>>> result = Result(Job(JobType.STATE_VECTOR, QCircuit([], nb_qubits=2, label="circuit 1"), IBMDevice.AER_SIMULATOR), StateVector([1, 0, 0, 0]), 0, 0)
>>> results = fetch_results_with_result(result)
>>> for result in results:
...    print("result:", result) 
result: {'id': 6, 'job_id': 5, 'data': '"StateVector([1, 0, 0, 0])"', 'error': '"0"', 'shots': 0, 'created_at': '...'}
result: {'id': 7, 'job_id': 6, 'data': '"StateVector([1, 0, 0, 0])"', 'error': '"0"', 'shots': 0, 'created_at': '...'}
fetch_results_with_result_and_job(result)[source]

Fetch result(s) associated with specific results(s) attributes:

  • data,

  • error,

  • shots.

And also with the job attribute of the results(s):

  • job type,

  • circuit,

  • device,

  • measure.

Parameters

result (mpqp.execution.result.Result | mpqp.execution.result.BatchResult | list[mpqp.execution.result.Result]) – The Result(s) to match.

Returns

Matching result(s) as dictionaries corresponding to the result(s) attribute and job attribute of the result(s).

Return type

list[dict[str, Any]]

Examples

>>> result = Result(Job(JobType.STATE_VECTOR, QCircuit([], nb_qubits=2, label="circuit 1"), IBMDevice.AER_SIMULATOR), StateVector([1, 0, 0, 0]), 0, 0)
>>> results = fetch_results_with_result_and_job(result)
>>> for result in results:
...    print("result:", result) 
result: {'id': 6, 'job_id': 5, 'data': '"StateVector([1, 0, 0, 0])"', 'error': '"0"', 'shots': 0, 'created_at': '...'}