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
Set or get the name of the backend that runs QAOA on the selected device.
Set or get the type of device on which to run QAOA.
The maximum number of available variables.
Get the parameter class of
QiskitClient
.Set or get an API token of your IBM Quantum account.
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, thebackend
will be passed to simulation method option of AerSimulator. See the AerSimulator documentation for the simulation method options that can be specified.If
backend
isNone
with a valid API token, the least busy backend with enough qubits for the given problem size is used. If bothbackend
and the API token areNone
,automatic
method is specified to AerSimulator forCPU
andGPU
devices.Note
The
GPU
device only supports Thestatevector
,densitymatrix
andunitary
methods. Please refer to Qiskit GPU Simulator.- Type:
- 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
orGPU
is selected, QAOA will run on the Qisikit built-in simulator (AerSimulator) with the selected device; ifQPU
is selected, an IBM Quantum machine will be used.Note
To run a simulation using a GPU, the
qiskit-aer
package needs to be uninstalled and replaced with theqiskit-aer-gpu
package, as follows:$ pip uninstall qiskit-aer $ pip install qiskit-aer-gpu
- Type:
- property parameters
Get the parameter class of
QiskitClient
.- Type:
- solve(*args, **kwargs)
Overloaded function.
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)
- Parameters:
poly (
BinaryPoly
,BinaryIntPoly
,IsingPoly
orIsingIntPoly
) –Input polynomial model
matrix (
BinaryMatrix
,BinaryIntMatrix
,IsingMatrix
orIsingIntMatrix
) –Input matrix model
constant (
int
orfloat
, optional) –A constant value to be added to the above matrix. The type is set in accordance with the coefficients of the matrix.
- Returns:
A result class that provides information about execution.
- Return type:
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']
solve(self: amplify.client.QiskitClient, arg0: amplify.BinaryIntPoly) -> libqam::client::ClientResult<libqam::client::QiskitClient, decltype(nullptr)>
solve(self: amplify.client.QiskitClient, arg0: amplify.IsingPoly) -> libqam::client::ClientResult<libqam::client::QiskitClient, decltype(nullptr)>
solve(self: amplify.client.QiskitClient, arg0: amplify.IsingIntPoly) -> libqam::client::ClientResult<libqam::client::QiskitClient, decltype(nullptr)>
solve(self: amplify.client.QiskitClient, matrix: amplify.BinaryMatrix, constant: float = 0.0) -> libqam::client::ClientResult<libqam::client::QiskitClient, decltype(nullptr)>
solve(self: amplify.client.QiskitClient, matrix: amplify.BinaryIntMatrix, constant: int = 0) -> libqam::client::ClientResult<libqam::client::QiskitClient, decltype(nullptr)>
solve(self: amplify.client.QiskitClient, matrix: amplify.IsingMatrix, constant: float = 0.0) -> libqam::client::ClientResult<libqam::client::QiskitClient, decltype(nullptr)>
solve(self: amplify.client.QiskitClient, matrix: amplify.IsingIntMatrix, constant: int = 0) -> libqam::client::ClientResult<libqam::client::QiskitClient, decltype(nullptr)>
solve(self: amplify.client.QiskitClient, arg0: amplify.IsingPoly, arg1: amplify.IsingConstraints) -> libqam::client::ClientResult<libqam::client::QiskitClient, decltype(nullptr)>
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: