IBMQ Executor
This quantum executor accesses IBM Quantum backends through Pennylane's "qiskit.ibmq"
device. IBMQExecutor
introduces thread-based parallelism for circuit execution on the "qiskit.ibmq" device. Note that the more efficient QiskitExecutor
is recommended over IBMQExecutor
for production use.
1. Installation
The IBMQ executor is included with Covalent. No additional installation is required.
2. Usage Example
Using IBMQExecutor requires specifying an IBM Quantum backend through the backend
argument. The ibmqx_token
is required if not specified in the configuration (see next section).
import covalent as ct
import pennylane as qml
# IBMQ executor that uses "ibmq_qasm_simulator" (default).
ibmq_qasm = ct.executor.IBMQExecutor()
# IBMQ executor that uses the "ibmq_lima" QPU.
ibmq_lima = ct.executor.IBMQExecutor(
backend="ibmq_lima",
ibmqx_token="<token>",
)
@ct.qelectron(executors=[ibmq_qasm, ibmq_lima])
@qml.qnode(qml.device("default.qubit", wires=2, shots=1024), interface="jax")
def circuit(x):
qml.IQPEmbedding(features=x, wires=[0, 1])
qml.Hadamard(wires=1)
return qml.probs(wires=range(2))
As a QElectron, the circuit can be called either normally or asynchronously using circuit.run_later()
. With the default "cyclic"
selector, circuit calls will alternate between the executors, [ibmq_qasm, ibmq_lima]
.
A synchronous example is shown below.
>>> print(circuit([0.5, 0.1])) # ibmq_qasm_simulator
DeviceArray([0.51660156, 0.00097656, 0.4814453 , 0.00097656], dtype=float32)
>>> print(circuit([0.5, 0.1])) # ibmq_lima
DeviceArray([0.5048828 , 0.00195312, 0.49316406, 0. ], dtype=float32)
>>> print(circuit([0.5, 0.1])) # ibmq_qasm_simulator (again)
DeviceArray([0.5097656 , 0.00292969, 0.4873047 , 0. ], dtype=float32)
Doing this asynchronously:
>>> x = [0.6, -1.57]
>>> # Queue jobs for all three circuit calls simultaneously on IBM Quantum.
>>> # Uses same executor order as above (qasm, lima, qasm, ...).
>>> futs = [circuit.run_later(x) for _ in range(3)]
>>> # Wait for all circuits to finish.
>>> [fut.result() for fut in futs]
[DeviceArray([0.51660156, 0.00097656, 0.4814453 , 0.00097656], dtype=float32),
DeviceArray([0.5048828 , 0.00195312, 0.49316406, 0. ], dtype=float32),
DeviceArray([0.5097656 , 0.00292969, 0.4873047 , 0. ], dtype=float32)]
3. Overview of Configuration
The IBMQExecutor
configuration is found under [qelectron.IBMQExecutor]
in the Covalent configuration file.
Config | Is Required | Default | Description |
---|---|---|---|
backend | Yes | ibm_qasm_simulator | The name of an IBM Quantum system or simulator. |
ibmqx_token | Yes/No | An access token obtained from IBM Quantum. Required for non-local execution. | |
hub | No | ibm-q | Hub name for IBM Quantum. |
group | No | open | Group name for IBM Quantum. |
project | No | main | Project name for IBM Quantum. |
4. Required Cloud Resources
In order to access IBM backends, users must acquire an access token from IBM Quantum. This can be done by creating a free account on the IBM Quantum Experience.
A quantum executor that uses the Pennylane native 'qiskit.ibmq'
device to run circuits on IBM Quantum backends. The attributes backend
, ibmqx_token
, hub
, group
, and project
are taken from the Covalent configuration file by default, if available.
Keyword Arguments
max_jobs
The maximum number of jobs that can be submitted to the backend concurrently. This number corresponds to the number of threads utilized by this executor. Defaults to 20.
shots
The number of shots to use for the execution device. Overrides the shots
value from the original device if set to None
or a positive int
. The shots setting from the original device is used by default when this argument is 0.
backend
The name of the IBM Quantum backend device. Defaults to 'ibmq_qasm_simulator
'.
ibmqx_token
The IBM Quantum API token.
hub
An IBM Quantum hub name. Defaults to 'ibm-q'
.
group
An IBM Quantum group name. Defaults to 'open'
.
project
An IBM Quantum project name. Defaults to 'main'
.
Show JSON Schema
{
"title": "IBMQExecutor",
"description": "A quantum executor that uses the Pennylane native :code:`\"qiskit.ibmq\"` device to run\ncircuits on IBM Quantum backends. The attributes :code:`backend`, :code:`ibmqx_token`,\n:code:`hub`, :code:`group`, and :code:`project` are taken from the Covalent\nconfiguration file by default, if available.\n\nKeyword Args:\n max_jobs: The maximum number of jobs that can be submitted to the backend\n concurrently. This number corresponds to the number of threads utilized\n by this executor. Defaults to 20.\n shots: The number of shots to use for the execution device. Overrides the\n :code:`shots` value from the original device if set to :code:`None` or\n a positive :code:`int`. The shots setting from the original device is\n is used by default, when this argument is 0.\n backend: The name of the IBM Quantum backend device. Defaults to\n :code:`\"ibmq_qasm_simulator\"`.\n ibmqx_token: The IBM Quantum API token.\n hub: An IBM Quantum hub name. Defaults to :code:`\"ibm-q\"`.\n group: An IBM Quantum group name. Defaults to :code:`\"open\"`.\n project: An IBM Quantum project name. Defaults to :code:`\"main\"`.",
"type": "object",
"properties": {
"persist_data": {
"title": "Persist Data",
"default": true,
"type": "boolean"
},
"qnode_device_import_path": {
"title": "Qnode Device Import Path",
"type": "array",
"minItems": 2,
"maxItems": 2,
"items": [
{
"type": "string"
},
{
"type": "string"
}
]
},
"qnode_device_shots": {
"title": "Qnode Device Shots",
"type": "integer"
},
"qnode_device_wires": {
"title": "Qnode Device Wires",
"type": "integer"
},
"pennylane_active_return": {
"title": "Pennylane Active Return",
"type": "boolean"
},
"device": {
"title": "Device",
"default": "default.qubit",
"type": "string"
},
"num_threads": {
"title": "Num Threads",
"default": 10,
"type": "integer"
},
"max_jobs": {
"title": "Max Jobs",
"default": 20,
"type": "integer"
},
"shots": {
"title": "Shots",
"default": 0,
"type": "integer"
},
"backend": {
"title": "Backend",
"type": "string"
},
"ibmqx_token": {
"title": "Ibmqx Token",
"type": "string"
},
"hub": {
"title": "Hub",
"type": "string"
},
"group": {
"title": "Group",
"type": "string"
},
"project": {
"title": "Project",
"type": "string"
}
}
}
CONFIG
extra: EXTRA = allow
field backend: str [Optional]
Validated by
set_name
field group: str [Optional]
Validated by
set_name
field hub: str [Optional]
Validated by
set_name
field ibmqx_token: str [Optional]
Validated by
set_name
field max_jobs: int = 20
Validated by
set_name
field project: str [Optional]
Validated by
set_name
field shots: int = 20
Validated by
set_name