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.Contextpreloaded 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-defaulttarget_profile); then register it withset_qsharp_context()if the chemistry builders should use it too.- Parameters:
target_profile (
TargetProfile) – Target profile the Q# interpreter compiles for. Defaults toTargetProfile.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 viaStd.Core.ConfigValue(values must beint,float,str, orbool).
- Return type:
Context
project_rootis 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.Contextthat 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