Qx.Hardware.Config (Qx - Quantum Computing Simulator v0.7.1)

View Source

Configuration for Qx.Hardware execution against IBM Quantum via the qxportal transpilation service.

Two independent credential sets live side-by-side in this struct, and the two HTTP clients (Qx.Hardware.Portal and Qx.Hardware.Ibm) consume only their own credentials — the portal token never reaches IBM, and the IBM API key never reaches the portal.

Fields

Required (enforced at struct construction time):

  • :portal_url — base URL for the qxportal transpilation service (e.g. "https://api.qxquantum.com").
  • :portal_token — bearer token for the qxportal API.
  • :ibm_api_key — IBM Quantum API key (used for the IAM exchange).
  • :ibm_crn — IBM Cloud Resource Name for the Quantum service instance.
  • :ibm_region — IBM Cloud region (e.g. "us-east").
  • :backend — IBM backend name (e.g. "ibm_brisbane").

Defaulted:

  • :optimization_level — transpiler optimization level, integer in 0..3. Defaults to 1.
  • :shots — number of shots for sampler jobs, integer in 1..100_000. Defaults to 4096.

Transient (populated by Qx.Hardware during lazy-connect):

  • :identity — qxportal identity returned by /api/v1/me.
  • :backends_list — list of backend names available to this account.

Internal (managed by Qx.Hardware.Ibm; callers should not set these directly except when injecting test/override hooks):

  • :access_token — IBM IAM bearer token. Populated by Qx.Hardware.Ibm.iam_exchange/1.
  • :token_expires_atDateTime for the IAM token's expiry.
  • :iam_url — overrides the IBM IAM endpoint (test hook).
  • :base_url — overrides the IBM Quantum API base URL (test hook).

Construction

iex> {:ok, _config} =
...>   Qx.Hardware.Config.new(
...>     portal_url: "https://api.qxquantum.com",
...>     portal_token: "ptok",
...>     ibm_api_key: "ibm",
...>     ibm_crn: "crn:v1:bluemix:public:quantum-computing:us-east:a/x:y::",
...>     ibm_region: "us-east",
...>     backend: "ibm_brisbane"
...>   )

Invalid input returns an error tuple:

iex> {:error, %Qx.Hardware.ConfigError{field: :optimization_level}} =
...>   Qx.Hardware.Config.new(
...>     portal_url: "https://api.qxquantum.com",
...>     portal_token: "ptok",
...>     ibm_api_key: "ibm",
...>     ibm_crn: "crn",
...>     ibm_region: "us-east",
...>     backend: "ibm_brisbane",
...>     optimization_level: 7
...>   )

The bang variant raises:

iex> Qx.Hardware.Config.new!(
...>   portal_url: "ftp://nope",
...>   portal_token: "ptok",
...>   ibm_api_key: "ibm",
...>   ibm_crn: "crn",
...>   ibm_region: "us-east",
...>   backend: "ibm_brisbane"
...> )
** (Qx.Hardware.ConfigError) Invalid `portal_url`: scheme must be "http" or "https"

Summary

Functions

Builds a t/0 from environment variables.

Same as from_env/1 but raises on failure.

Builds a t/0 from a keyword list or map.

Same as new/1 but raises Qx.Hardware.ConfigError on failure.

Types

t()

@type t() :: %Qx.Hardware.Config{
  access_token: String.t() | nil,
  backend: String.t(),
  backends_list: [String.t()],
  base_url: String.t() | nil,
  iam_url: String.t() | nil,
  ibm_api_key: String.t(),
  ibm_crn: String.t(),
  ibm_region: String.t(),
  identity: String.t() | nil,
  optimization_level: 0..3,
  portal_token: String.t(),
  portal_url: String.t(),
  shots: pos_integer(),
  token_expires_at: DateTime.t() | nil
}

Functions

from_env(opts \\ [])

@spec from_env(keyword()) :: {:ok, t()} | {:error, Qx.Hardware.ConfigError.t()}

Builds a t/0 from environment variables.

Reads:

  • QX_PORTAL_URL
  • QX_PORTAL_TOKEN
  • QX_IBM_API_KEY
  • QX_IBM_CRN
  • QX_IBM_REGION
  • QX_IBM_BACKEND

Optional overrides may be passed via opts (e.g. optimization_level:, shots:).

from_env!(opts \\ [])

@spec from_env!(keyword()) :: t()

Same as from_env/1 but raises on failure.

new(attrs)

@spec new(keyword() | map()) :: {:ok, t()} | {:error, Qx.Hardware.ConfigError.t()}

Builds a t/0 from a keyword list or map.

Returns {:ok, %Qx.Hardware.Config{}} on success or {:error, %Qx.Hardware.ConfigError{}} on validation failure.

new!(attrs)

@spec new!(keyword() | map()) :: t()

Same as new/1 but raises Qx.Hardware.ConfigError on failure.