Bengali
Languages
English
Bengali
French
German
Japanese
Korean
Portuguese
Spanish
Tamil

Options

class Options(**kwargs)[source]

Bases: Mapping

Base options object

This class is what all backend options are based on. The properties of the class are intended to be all dynamically adjustable so that a user can reconfigure the backend on demand. If a property is immutable to the user (eg something like number of qubits) that should be a configuration of the backend class itself instead of the options.

Instances of this class behave like dictionaries. Accessing an option with a default value can be done with the get() method:

>>> options = Options(opt1=1, opt2=2)
>>> options.get("opt1")
1
>>> options.get("opt3", default="hello")
'hello'

Key-value pairs for all options can be retrieved using the items() method:

>>> list(options.items())
[('opt1', 1), ('opt2', 2)]

Options can be updated by name:

>>> options["opt1"] = 3
>>> options.get("opt1")
3

Runtime validators can be registered. See set_validator. Updates through update_options and indexing (__setitem__) validate the new value before peforming the update and raise ValueError if the new value is invalid.

>>> options.set_validator("opt1", (1, 5))
>>> options["opt1"] = 4
>>> options["opt1"]
4
>>> options["opt1"] = 10  
Traceback (most recent call last):
...
ValueError: ...

Methods

get

items

keys

set_validator

Set an optional validator for a field in the options

update_options

Update options with kwargs

values

Attributes

validator