-
Notifications
You must be signed in to change notification settings - Fork 169
The QDK Python layer should have knowledge of its initialization state #2998
Copy link
Copy link
Open
Copy link
Labels
Description
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.
Reactions are currently unavailable