Skip to content

The QDK Python layer should have knowledge of its initialization state #2998

@wavefunction91

Description

@wavefunction91

Is your feature request related to a problem? Please describe.

As the qsharp state is global and persistent, but must be initialized

from qdk import init as qdk_init
qdk_init(...)

Reinitialization effects the global state. For downstream applications and libraries which use QDK, this can be dangerous, as initializing the qdk in user code, and again in another library, could lead to unexpected behaviour.

Describe the solution you'd like

Some notion of whether QDK has been initialized, e.g. a global variable (as is canonical in many libraries that have stateful initialization):

from qdk import QDK_IS_INITIALIZED
from qdk import init as qdk_init
if NOT QDK_IS_INITIALIZED:
  qdk_init(...)

Describe alternatives you've considered

There is a workaround currently by checking the qdk profile

from qdk import init as qdk_init
from qsharp._qsharp import get_config as get_qdk_profile_config
qdk_config = get_qdk_profile_config()
_QDK_INTERPRETER_PROFILE = qdk_config.get_target_profile()
if _QDK_INTERPRETER_PROFILE == "unrestricted":  # Default by Q# if not set
    qdk_init(target_profile=TargetProfile.Base)

but I think we can all agree that is not great UX.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions