qdk_chemistry.utils.qsharp package

QDK/Chemistry Q# Utilities Module.

qdk_chemistry.utils.qsharp.create_qsharp_context(target_profile=TargetProfile.Base, target_name=None, language_features=None, qdk_config=None)[source]

Create a new, isolated qdk.Context preloaded with the Q# chemistry utilities.

Every call returns a fresh context with its own Q# interpreter. Most users never need this — the library maintains one shared context (see get_qsharp_context()). Reach for this only when you need a context configured differently from the default (for example a non-default target_profile); then register it with set_qsharp_context() if the chemistry builders should use it too.

Parameters:
  • target_profile (TargetProfile) – Target profile the Q# interpreter compiles for. Defaults to TargetProfile.Base.

  • target_name (str | None) – Optional target machine name used to infer a compatible profile.

  • language_features (list[str] | None) – Optional list of experimental Q# language feature flags.

  • qdk_config (dict[str, int | float | str | bool] | None) – Optional configuration values exposed to Q# code via Std.Core.ConfigValue (values must be int, float, str, or bool).

Return type:

Context

project_root is intentionally not exposed: it is fixed to the vendored Q# utility project so the chemistry utilities are always available on the returned context.

qdk_chemistry.utils.qsharp.get_qsharp_context()[source]

Return the shared qdk.Context that QDK/Chemistry uses for all Q# composition.

Call it when you want to define your own Q# operation (e.g. a custom state preparation) and compose it with a chemistry builder. The context is created lazily on first use and access is thread-safe.

Return type:

Context

qdk_chemistry.utils.qsharp.set_qsharp_context(context)[source]

Replace the process-wide shared Q# context (pass None to reset to the default).

Return type:

None

Parameters:

context (Context | None)

qdk_chemistry.utils.qsharp.use_qsharp_context(context)[source]

Temporarily use context as the shared Q# context on the current thread.

Return type:

Iterator[Context]

Parameters:

context (Context)