Specify Executor options
You can use options to customize the Executor primitive. This section focuses on how to specify Qiskit Runtime primitive options. Consult the API reference for information about the ExecutorOptions class.
Notes about specifying options in the primitives:
- You can see the available options and update option values during or after primitive initialization.
- Use the
update()method to apply changes to theoptionsattribute. - The
optionsattribute is thedataclassPython type. You can use the built-inasdictmethod to convert it to a dictionary.
Set Executor options
You can set options when initializing the primitive or after initializing the primitive. If an option is specified in both locations, the value set after initializing the primitive is used.
Primitive initialization
You can pass in an instance of the options class or a dictionary when initializing Executor, which then makes a copy of those options. Thus, changing the original dictionary or options instance doesn't affect the options owned by the primitive.
Options class
When creating an instance of the Executor class, you can pass in an instance of the options class. Those options will then be applied when you use run() to perform the calculation. Specify the options in this format: options.option.sub-option.sub-sub-option = choice. For example: options.log_level = INFO
See ExecutorOptions for full details about the options class.
Example:
from qiskit_ibm_runtime import QiskitRuntimeService, Executor
from qiskit_ibm_runtime.options import ExecutorOptions
service = QiskitRuntimeService()
backend = service.least_busy(operational=True, simulator=False)
options = ExecutorOptions(
environment={"log_level": INFO},
execution={"init_qubits": True},
)
# or...
options = ExecutorOptions()
options.environment.log_level = INFO
options.execution.init_qubits = True
executor = Executor(mode=backend, options=options)Dictionary
You can specify options as a dictionary when initializing Executor.
from qiskit_ibm_runtime import QiskitRuntimeService, executor
service = QiskitRuntimeService()
backend = service.least_busy(operational=True, simulator=False)
# Setting options during primitive initialization
executor = Executor(
backend,
options={
"environment"={"log_level": INFO},
"execution"={"init_qubits": True},
},
)Update options after initialization
You can specify the options in this format: executor.options.option.sub-option.sub-sub-option = choice to take advantage of auto-complete, or use the update() method to make bulk updates.
Executor's options class (ExecutorOptions) does not need to be instantiated if you are setting options after initializing the primitive.
from qiskit_ibm_runtime import QiskitRuntimeService, Executor
service = QiskitRuntimeService()
backend = service.least_busy(operational=True, simulator=False)
executor = Executor(mode=backend)
# Setting options after primitive initialization
# This uses auto-complete.
executor.options.environment.log_level = INFO
# This does bulk update.
executor.options.update(environment={"log_level": INFO}
)Next steps
- Review the ExecutionOptionsV2 API documentation.
- Review the EnvironmentOptions API documentation.