quri_parts.riqu.backend package#

class quri_parts.riqu.backend.RiquConfig(url: str, api_token: str)#

Bases: object

A configuration information class for using riqu backend.

Parameters
  • url – Base URL for riqu server.

  • api_token – API token for riqu server.

Raises

ValueError – If url or api_token is None.

property url: str#
property api_token: str#
static from_file(section: str = 'default', path: str = '~/.riqu') quri_parts.riqu.backend.sampling.RiquConfig#

Reads configuration information from a file.

Parameters
  • section – A RiquConfig for circuit execution.

  • path – A path for config file.

Returns

Configuration information RiquConfig .

Examples

The riqu configuration file describes configuration information for each section. A section has a header in the form [section]. The default file path is ~/.riqu and the default section name is default. Each section describes a setting in the format key=value. An example of a configuration file description is as below:

[default]
url=<base URL>
api_token=<API token>

[sectionA]
url=<base URL>
api_token=<API token>

[sectioB]
url=<base URL>
api_token=<API token>

If sectionA settings are to be used, initialize RiquSamplingBackend as follows

backend = RiquSamplingBackend(RiquConfig.from_file("sectionA"))
class quri_parts.riqu.backend.RiquSamplingBackend(config: Optional[quri_parts.riqu.backend.sampling.RiquConfig] = None)#

Bases: quri_parts.backend.SamplingBackend

A riqu backend for a sampling measurement.

Parameters

config – A RiquConfig for circuit execution. If this parameter is None, default section in ~/.riqu file is read.

sample(circuit: quri_parts.circuit.circuit.NonParametricQuantumCircuit, n_shots: int, transpiler: Optional[str] = 'normal', remark: Optional[str] = None) quri_parts.backend.SamplingJob#

Perform a sampling measurement of a circuit.

The circuit is transpiled on riqu server. The QURI Parts transpiling feature is not supported. The circuit is converted to OpenQASM 3.0 format and sent to riqu server.

Parameters
  • circuit – The circuit to be sampled.

  • n_shots – Number of repetitions of each circuit, for sampling.

  • transpiler – The transpiler setting.

  • remark – The remark to be assigned to the job.

Returns

The job to be executed.

Raises
  • ValueError – If n_shots is not a positive integer.

  • BackendError – If job is wrong or if an authentication error occurred, etc.

sample_qasm(qasm: str, n_shots: int, transpiler: Optional[str] = 'normal', remark: Optional[str] = None) quri_parts.backend.SamplingJob#

Perform a sampling measurement of a OpenQASM 3.0 program.

The OpenQASM 3.0 program is transpiled on riqu server. The QURI Parts transpiling feature is not supported.

Parameters
  • qasm – The OpenQASM 3.0 program to be sampled.

  • n_shots – Number of repetitions of each circuit, for sampling.

  • transpiler – The transpiler setting.

  • remark – The remark to be assigned to the job.

Returns

The job to be executed.

Raises
  • ValueError – If n_shots is not a positive integer.

  • BackendError – If job is wrong or if an authentication error occurred, etc.

retrieve_job(job_id: str) quri_parts.riqu.backend.sampling.RiquSamplingJob#

Retrieves the job with the given id from riqu server.

Parameters

job_id – The id of the job to retrieve.

Returns

The job with the given job_id.

Raises

BackendError – If job cannot be found or if an authentication error occurred, etc.

class quri_parts.riqu.backend.RiquSamplingJob(job: quri_parts.riqu.rest.models.job.Job, job_api: quri_parts.riqu.rest.api.job_api.JobApi)#

Bases: quri_parts.backend.SamplingJob

A job for a riqu sampling measurement.

Parameters
  • Job – A result of dict type.

  • job_api – A result of dict type.

Raises

ValueError – If job or job_api is None.

property id: str#

The id of the job.

property qasm: str#

The circuit converted to OpenQASM 3.0 format.

property transpiled_qasm: str#

The circuit in OpenQASM 3.0 format transpiled by riqu server.

property transpiler: str#

The transpiler setting.

property shots: int#

Number of repetitions of each circuit, for sampling.

property status: str#

The status of Job.

property created: datetime.datetime#

datetime when riqu server received the new job.

property in_queue: datetime.datetime#

datetime when the job is in queue.

property out_queue: datetime.datetime#

datetime when the job is out queue.

property ended: datetime.datetime#

datetime when the job is ended.

property remark: str#

The remark to be assigned to the job.

refresh() None#

Retrieves the latest job information from riqu server.

wait_for_completion(timeout: Optional[float] = None, wait: float = 10.0) Optional[quri_parts.riqu.rest.models.job.Job]#

Waits until the job progress to the end such as success or failure, cancelled.

Parameters
  • timeout – The number of seconds to wait for job.

  • wait – Time in seconds between queries.

result(timeout: Optional[float] = None, wait: float = 10.0) quri_parts.backend.SamplingResult#

Waits until the job progress to the end and returns the result of the job.

If the status of job is not success, failure, or cancelled, the job is retrieved from riqu server at intervals of wait seconds. If the job does not progress to the end after timeout seconds, raise BackendError.

Parameters
  • timeout – The number of seconds to wait for job.

  • wait – Time in seconds between queries.

Raises

BackendError – If job cannot be found or if an authentication error occurred or timeout occurs, etc.

cancel() None#

Cancels the job.

If the job statuses are success, failure, or cancelled, then cannot be cancelled and an error occurs.

Raises

BackendError – If job cannot be found or if an authentication error occurred or if job cannot be cancelled, etc.

class quri_parts.riqu.backend.RiquSamplingResult(result: Dict[str, Any])#

Bases: quri_parts.backend.SamplingResult

A result of a riqu sampling job.

Parameters

result

A result of dict type. This dict should have the key counts. The value of counts is the dict input for the counts. Where the keys represent a measured classical value and the value is an integer the number of shots with that result.

If the keys of counts is expressed as a bit string, then properties is a mapping from the index of bit string to the index of the quantum circuit.

Raises

ValueError – If counts or properties does not exist in result.

Examples

An example of a dict of result is as below:

{
    "counts": {
        0: 600,
        1: 300,
        3: 100,
    },
    "properties": {
        0: {
            "qubit_index": 0,
            "measurement_window_index": 0
        },
        1: {
            "qubit_index": 1,
            "measurement_window_index": 0
        }
    }
}

In the above case, the bit string representation of 0, 1, and 3 in the keys of counts is “00”, “01”, and “11” respectively. The index of these 2 bits is the key of properties and the index of the quantum circuit is qubit_index. The LSB (Least Significant Bit) of the bit string representation is index=0.

If the same qubit_index is measured multiple times in one quantum circuit, measurement_window_index are set to 0, 1, 2, …

property counts: collections.abc.Mapping[int, int]#

Returns the dict input for the counts.

property properties: Dict#

Returns properties.

Submodules#