qbraid.runtime.RuntimeOptions
- class RuntimeOptions(**kwargs)[source]
- Manages qBraid-specific options with controlled defaults and dynamic fields. - The RuntimeOptions class allows you to initialize options with default fields, add dynamic fields, and validate the values of specific fields using custom validators. It also provides dictionary-like access to option fields. - Example: - >>> from qbraid.runtime.options import RuntimeOptions # Initialize options with default and custom fields >>> options = RuntimeOptions(check=True, custom_field=42) # Access option fields like dictionary >>> options["check"] True # Add dynamic fields >>> options["new_field"] = "hello" >>> print(options) RuntimeOptions(check=True, custom_field=42, new_field='hello') # Set a validator for a field >>> options.set_validator("check", lambda x: isinstance(x, bool)) # Attempting to set an invalid value will raise a ValueError >>> options.check = False # Valid >>> options.check = "invalid_value" # Raises ValueError # Make a shallow copy of the options >>> options_copy = copy.copy(options) >>> print(options_copy) RuntimeOptions(check=False, custom_field=42, new_field='hello') - Parameters:
- kwargs ( - Any) – Keyword arguments representing the initial options to set. These will form the default fields of the Options instance.
 - _fields
- The internal dictionary storing option fields. - Type:
- dict 
 
 - _validators
- A dictionary storing field validators. - Type:
- dict 
 
 - Methods - __init__(**kwargs)- get(key[, default])- Return the value for the given key, or the default value if not found. - merge(other[, override_validators])- Merges another RuntimeOptions instance into this one. - set_validator(option_name, validator)- Sets a validator for a specific field. - update_options(**new_options)- Updates multiple options with validation. - validate_option(option_name, value)- Validates a field's value using the registered validator, if any.