uniqc.config module#

UnifiedQuantum configuration management module.

This module provides centralized configuration management for quantum cloud platforms including OriginQ (本源量子), Quafu (夸父), and IBM Quantum.

Configuration file location: ~/.uniqc/uniqc.yml

Example configuration structure:

default:
  originq:
    token: xxx
  quafu:
    token: xxx
  ibm:
    token: xxx
    proxy:
      http: http://proxy:8080
      https: https://proxy:8080
exception uniqc.config.ConfigError[source]#

Bases: Exception

Configuration-related error.

exception uniqc.config.ConfigValidationError[source]#

Bases: ConfigError

Configuration validation error.

exception uniqc.config.PlatformNotFoundError[source]#

Bases: ConfigError

Platform configuration not found error.

exception uniqc.config.ProfileNotFoundError[source]#

Bases: ConfigError

Profile not found error.

uniqc.config.create_default_config(config_path=None)[source]#

Create default configuration file if it doesn’t exist.

Parameters:

config_path (str | Path | None) – Path to configuration file. If None, uses default path.

Return type:

None

uniqc.config.get_active_profile(config_path=None)[source]#

Get the active profile from configuration.

First checks UNIQC_PROFILE environment variable, then falls back to ‘default’.

Parameters:

config_path (str | Path | None) – Path to configuration file. If None, uses default path.

Returns:

Active profile name.

Return type:

str

uniqc.config.get_ibm_config(profile='default')[source]#

Get IBM Quantum configuration.

Parameters:

profile (str) – Configuration profile name (default: “default”).

Returns:

IBM Quantum configuration dictionary.

Return type:

dict[str, Any]

uniqc.config.get_originq_config(profile='default')[source]#

Get OriginQ (本源量子) configuration.

Parameters:

profile (str) – Configuration profile name (default: “default”).

Returns:

OriginQ configuration dictionary.

Return type:

dict[str, Any]

uniqc.config.get_platform_config(platform_name, profile='default', config_path=None)[source]#

Get configuration for a specific platform.

Parameters:
  • platform_name (str) – Name of the quantum cloud platform (originq, quafu, ibm).

  • profile (str) – Configuration profile name (default: “default”).

  • config_path (str | Path | None) – Path to configuration file. If None, uses default path.

Returns:

Platform configuration dictionary.

Raises:
Return type:

dict[str, Any]

uniqc.config.get_quafu_config(profile='default')[source]#

Get Quafu (夸父) configuration.

Parameters:

profile (str) – Configuration profile name (default: “default”).

Returns:

Quafu configuration dictionary.

Return type:

dict[str, Any]

uniqc.config.load_config(config_path=None)[source]#

Load configuration from YAML file.

Parameters:

config_path (str | Path | None) – Path to configuration file. If None, uses default path.

Returns:

Configuration dictionary.

Raises:

ConfigError – If configuration file cannot be read.

Return type:

dict[str, Any]

uniqc.config.save_config(config, config_path=None)[source]#

Save configuration to YAML file.

Parameters:
  • config (dict[str, Any]) – Configuration dictionary to save.

  • config_path (str | Path | None) – Path to configuration file. If None, uses default path.

Raises:

ConfigError – If configuration file cannot be written.

Return type:

None

uniqc.config.set_active_profile(profile, config_path=None)[source]#

Set the active profile in configuration.

Parameters:
  • profile (str) – Profile name to set as active.

  • config_path (str | Path | None) – Path to configuration file. If None, uses default path.

Raises:

ProfileNotFoundError – If profile does not exist in configuration.

Return type:

None

uniqc.config.sync_tokens_to_env(profile='default')[source]#

Sync API tokens from the YAML config file into environment variables.

Call this before instantiating adapters that read from env vars (ORIGINQ_API_KEY, QUAFU_API_TOKEN, IBM_TOKEN) so that tokens stored in the config file are picked up.

Idempotent: only overwrites an env var if the config file has a non-empty token for that platform.

Parameters:

profile (str)

Return type:

None

uniqc.config.update_platform_config(platform_name, platform_config, profile='default', config_path=None)[source]#

Update configuration for a specific platform.

Parameters:
  • platform_name (str) – Name of the quantum cloud platform.

  • platform_config (dict[str, Any]) – Platform configuration dictionary.

  • profile (str) – Configuration profile name (default: “default”).

  • config_path (str | Path | None) – Path to configuration file. If None, uses default path.

Raises:

PlatformNotFoundError – If platform is not supported.

Return type:

None

uniqc.config.validate_config(config=None, config_path=None)[source]#

Validate configuration structure and required fields.

Parameters:
  • config (dict[str, Any] | None) – Configuration dictionary to validate. If None, loads from file.

  • config_path (str | Path | None) – Path to configuration file. Used if config is None.

Returns:

List of validation error messages. Empty list if valid.

Return type:

list[str]