sf.configuration

This module contains functionality for configuring Strawberry Fields.

Configuration files

When connecting to the Xanadu cloud platform, Strawberry Fields will attempt to load the configuration file config.toml, by scanning the following three directories in order of preference:

  1. The current directory

  2. The path stored in the environment variable SF_CONF (if specified)

  3. The default user configuration directory:

    • On Linux: ~/.config/strawberryfields

    • On Windows: C:\Users\USERNAME\AppData\Local\Xanadu\strawberryfields

    • On MacOS: ~/Library/Application\ Support/strawberryfields

The configuration file config.toml uses the TOML standard, and has the following format:

[api]
# Options for the Strawberry Fields cloud API
authentication_token = "AUTHENTICATION_TOKEN"
hostname = "platform.strawberryfields.ai"
use_ssl = true
port = 443

Configuration options

[api]

Settings for the Xanadu cloud platform.

authentication_token (str) (required)

API token for authentication to the Xanadu cloud platform. This is required for submitting remote jobs using RemoteEngine.

Corresponding environment variable: SF_API_AUTHENTICATION_TOKEN

hostname (str) (optional)

The hostname of the server to connect to. Defaults to platform.strawberryfields.ai. Must be one of the allowed hosts.

Corresponding environment variable: SF_API_HOSTNAME

use_ssl (bool) (optional)

Whether to use SSL or not when connecting to the API. true or false. Defaults to true.

Corresponding environment variable: SF_API_USE_SSL

port (int) (optional)

The port to be used when connecting to the remote service. Defaults to 443.

Corresponding environment variable: SF_API_PORT

Functions

Warning

Unless you are a Strawberry Fields developer, you likely do not need to use the functions in this module directly.

This module contains functions used to load, store, save, and modify configuration options for Strawberry Fields.

Functions

create_config([authentication_token])

Create a configuration object that stores configuration related data organized into sections.

delete_config([filename, directory])

Delete a configuration file.

directories_to_check()

Returns the list of directories that should be checked for a configuration file.

find_config_file([filename])

Get the filepath of the first configuration file found from the defined configuration directories (if any).

get_api_config(loaded_config, filepath)

Gets the API section from the loaded configuration.

get_available_config_paths([filename])

Get the paths for the configuration files available in Strawberry Fields.

keep_valid_options(sectionconfig)

Filters the valid options in a section of a configuration dictionary.

load_config([filename])

Load configuration from keyword arguments, configuration file or environment variables.

load_config_file(filepath)

Load a configuration object from a TOML formatted file.

parse_environment_variable(key, value)

Parse a value stored in an environment variable.

save_config_to_file(config, filepath)

Saves a configuration to a TOML file.

update_from_environment_variables(config)

Updates the current configuration object from data stored in environment variables.

Classes

ConfigurationError

Exception used for configuration errors