amplify.client.QiskitClient

class QiskitClient

A class for using Qiskit IBM Quantum client.

__init__(self: amplify.client.QiskitClient, token: str = '', backend: str = '') None

Methods

__init__(self[, token, backend])

solve(*args, **kwargs)

Overloaded function.

Attributes

backend

Set or get the name of the backend that runs QAOA on the selected device.

device

Set or get the type of device on which to run QAOA.

num_bits

The maximum number of available variables.

parameters

Get the parameter class of QiskitClient.

token

Set or get an API token of your IBM Quantum account.

version

Get the version string of the ampllify.qaoa library.

property backend

Set or get the name of the backend that runs QAOA on the selected device.

The default value is None.

To run QAOA on a real machine or a local simulator that mimics it, specify the IBM Quantum machine name (e.g. ibmq_bogota). Otherwise, the backend will be passed to simulation method option of AerSimulator. See the AerSimulator documentation for the simulation method options that can be specified.

If backend is None with a valid API token, the least busy backend with enough qubits for the given problem size is used. If both backend and the API token are None, automatic method is specified to AerSimulator for CPU and GPU devices.

注釈

The GPU device only supports The statevector, densitymatrix and unitary methods. Please refer to Qiskit GPU Simulator.

Type:

str

property device

Set or get the type of device on which to run QAOA.

Available device types are as follows:

  • CPU

  • GPU

  • QPU

The default value is CPU.

If CPU or GPU is selected, QAOA will run on the Qisikit built-in simulator (AerSimulator) with the selected device; if QPU is selected, an IBM Quantum machine will be used.

注釈

To run a simulation using a GPU, the qiskit-aer package needs to be uninstalled and replaced with the qiskit-aer-gpu package, as follows:

$ pip uninstall qiskit-aer
$ pip install qiskit-aer-gpu
Type:

str

property num_bits

The maximum number of available variables.

Type:

int

property parameters

Get the parameter class of QiskitClient.

Type:

QiskitClientParameters

solve(*args, **kwargs)

Overloaded function.

  1. solve(self: amplify.client.QiskitClient, arg0: amplify.BinaryPoly) -> libqam::client::ClientResult<libqam::client::QiskitClient, decltype(nullptr)>

solve(*args, **kwargs) Solves a given polynomial or matrix model.

Overloads:

  • solve(poly)
  • solve(matrix, constant)
パラメータ:
戻り値:

A result class that provides information about execution.

戻り値の型:

QiskitClientResult

Example

from amplify import BinaryPoly, BinarySymbolGenerator, Solver
from amplify.client import QiskitClient

gen = BinarySymbolGenerator()
q = gen.array(3)
f = -2 * q[0] * q[1] - q[0] - q[1] - q[2] + 1

# solve f with pure simulator in local PC using CPU
client = QiskitClient()
# client.token is set None (default)
client.device = "CPU"
client.backend = "automatic"
client.parameters.shots = 1024
client.parameters.reps = 10

result = client.solve(f)
>>> f
- 2 q_0 q_1 - q_0 - q_1 - q_2 + 1
>>> [f"energy = {s.energy}, q = {q.decode(s.values)}, frequency={s.frequency}" for s in result]
['energy = -4.0, q = [1. 1. 1.], frequency=8', 'energy = -3.0, q = [1. 1. 0.], frequency=15', 'energy = -1.0, q = [1. 0. 1.], frequency=6', 'energy = -1.0, q = [0. 1. 1.], frequency=79', 'energy = 0.0, q = [0. 0. 1.], frequency=438', 'energy = 0.0, q = [0. 1. 0.], frequency=68', 'energy = 0.0, q = [1. 0. 0.], frequency=5', 'energy = 1.0, q = [0. 0. 0.], frequency=405']
  1. solve(self: amplify.client.QiskitClient, arg0: amplify.BinaryIntPoly) -> libqam::client::ClientResult<libqam::client::QiskitClient, decltype(nullptr)>

  2. solve(self: amplify.client.QiskitClient, arg0: amplify.IsingPoly) -> libqam::client::ClientResult<libqam::client::QiskitClient, decltype(nullptr)>

  3. solve(self: amplify.client.QiskitClient, arg0: amplify.IsingIntPoly) -> libqam::client::ClientResult<libqam::client::QiskitClient, decltype(nullptr)>

  4. solve(self: amplify.client.QiskitClient, matrix: amplify.BinaryMatrix, constant: float = 0.0) -> libqam::client::ClientResult<libqam::client::QiskitClient, decltype(nullptr)>

  5. solve(self: amplify.client.QiskitClient, matrix: amplify.BinaryIntMatrix, constant: int = 0) -> libqam::client::ClientResult<libqam::client::QiskitClient, decltype(nullptr)>

  6. solve(self: amplify.client.QiskitClient, matrix: amplify.IsingMatrix, constant: float = 0.0) -> libqam::client::ClientResult<libqam::client::QiskitClient, decltype(nullptr)>

  7. solve(self: amplify.client.QiskitClient, matrix: amplify.IsingIntMatrix, constant: int = 0) -> libqam::client::ClientResult<libqam::client::QiskitClient, decltype(nullptr)>

  8. solve(self: amplify.client.QiskitClient, arg0: amplify.IsingPoly, arg1: amplify.IsingConstraints) -> libqam::client::ClientResult<libqam::client::QiskitClient, decltype(nullptr)>

  9. solve(self: amplify.client.QiskitClient, arg0: amplify.BinaryPoly, arg1: amplify.BinaryConstraints) -> libqam::client::ClientResult<libqam::client::QiskitClient, decltype(nullptr)>

property token

Set or get an API token of your IBM Quantum account.

The default value is None.

A valid API token is required to run QAOA on a real device or a simulator that mimics a real device.

Type:

str

property version

Get the version string of the ampllify.qaoa library.

Type:

str