diff --git a/source/pip/qsharp/_qsharp.py b/source/pip/qsharp/_qsharp.py index 11fd661a92..a46bd7dee2 100644 --- a/source/pip/qsharp/_qsharp.py +++ b/source/pip/qsharp/_qsharp.py @@ -176,6 +176,12 @@ def _repr_mimebundle_( ) -> Dict[str, Dict[str, str]]: return {"application/x.qsharp-config": self._config} + def get_target_profile(self) -> str: + """ + Returns the target profile as a string, or "unspecified" if not set. + """ + return self._config.get("targetProfile", "unspecified") + class PauliNoise(Tuple[float, float, float]): """ @@ -324,6 +330,19 @@ def get_interpreter() -> Interpreter: return _interpreter +def get_config() -> Config: + """ + Returns the Q# interpreter configuration. + + :returns: The Q# interpreter configuration. + """ + global _config + if _config is None: + init() + assert _config is not None, "Failed to initialize the Q# interpreter." + return _config + + class StateDump: """ A state dump returned from the Q# interpreter. @@ -787,16 +806,16 @@ def compile(entry_expr: Union[str, Callable], *args) -> QirInputData: """ ipython_helper() start = monotonic() - global _config - target_profile = _config._config.get("targetProfile", "unspecified") + interpreter = get_interpreter() + target_profile = get_config().get_target_profile() telemetry_events.on_compile(target_profile) if isinstance(entry_expr, Callable) and hasattr(entry_expr, "__global_callable"): args = python_args_to_interpreter_args(args) - ll_str = get_interpreter().qir( + ll_str = interpreter.qir( entry_expr=None, callable=entry_expr.__global_callable, args=args ) else: - ll_str = get_interpreter().qir(entry_expr=entry_expr) + ll_str = interpreter.qir(entry_expr=entry_expr) res = QirInputData("main", ll_str) durationMs = (monotonic() - start) * 1000 telemetry_events.on_compile_end(durationMs, target_profile)