|
1 | 1 | # Copyright (c) Microsoft Corporation.
|
2 | 2 | # Licensed under the MIT License.
|
3 | 3 |
|
| 4 | +from . import telemetry_events |
4 | 5 | from ._native import (
|
5 | 6 | Interpreter,
|
6 | 7 | TargetProfile,
|
|
23 | 24 | from .estimator._estimator import EstimatorResult, EstimatorParams
|
24 | 25 | import json
|
25 | 26 | import os
|
| 27 | +from time import monotonic |
26 | 28 |
|
27 | 29 | _interpreter = None
|
| 30 | +_config = None |
28 | 31 |
|
29 | 32 | # Check if we are running in a Jupyter notebook to use the IPython display function
|
30 | 33 | _in_jupyter = False
|
@@ -161,6 +164,7 @@ def init(
|
161 | 164 | from ._http import fetch_github
|
162 | 165 |
|
163 | 166 | global _interpreter
|
| 167 | + global _config |
164 | 168 |
|
165 | 169 | if isinstance(target_name, str):
|
166 | 170 | target = target_name.split(".")[0].lower()
|
@@ -198,9 +202,10 @@ def init(
|
198 | 202 | fetch_github,
|
199 | 203 | )
|
200 | 204 |
|
| 205 | + _config = Config(target_profile, language_features, manifest_contents, project_root) |
201 | 206 | # Return the configuration information to provide a hint to the
|
202 | 207 | # language service through the cell output.
|
203 |
| - return Config(target_profile, language_features, manifest_contents, project_root) |
| 208 | + return _config |
204 | 209 |
|
205 | 210 |
|
206 | 211 | def get_interpreter() -> Interpreter:
|
@@ -286,6 +291,9 @@ def run(
|
286 | 291 | if shots < 1:
|
287 | 292 | raise QSharpError("The number of shots must be greater than 0.")
|
288 | 293 |
|
| 294 | + telemetry_events.on_run(shots) |
| 295 | + start_time = monotonic() |
| 296 | + |
289 | 297 | results: List[ShotResult] = []
|
290 | 298 |
|
291 | 299 | def print_output(output: Output) -> None:
|
@@ -317,6 +325,9 @@ def on_save_events(output: Output) -> None:
|
317 | 325 | # compilation.
|
318 | 326 | entry_expr = None
|
319 | 327 |
|
| 328 | + durationMs = (monotonic() - start_time) * 1000 |
| 329 | + telemetry_events.on_run_end(durationMs, shots) |
| 330 | + |
320 | 331 | if save_events:
|
321 | 332 | return results
|
322 | 333 | else:
|
@@ -366,10 +377,15 @@ def compile(entry_expr: str) -> QirInputData:
|
366 | 377 | file.write(str(program))
|
367 | 378 | """
|
368 | 379 | ipython_helper()
|
369 |
| - |
| 380 | + start = monotonic() |
| 381 | + global _config |
| 382 | + target_profile = _config._config.get("targetProfile", "unspecified") |
| 383 | + telemetry_events.on_compile(target_profile) |
370 | 384 | ll_str = get_interpreter().qir(entry_expr)
|
371 |
| - return QirInputData("main", ll_str) |
372 |
| - |
| 385 | + res = QirInputData("main", ll_str) |
| 386 | + durationMs = (monotonic() - start) * 1000 |
| 387 | + telemetry_events.on_compile_end(durationMs, target_profile) |
| 388 | + return res |
373 | 389 |
|
374 | 390 | def circuit(
|
375 | 391 | entry_expr: Optional[str] = None, *, operation: Optional[str] = None
|
@@ -421,9 +437,18 @@ def _coerce_estimator_params(
|
421 | 437 |
|
422 | 438 | params = _coerce_estimator_params(params)
|
423 | 439 | param_str = json.dumps(params)
|
424 |
| - |
| 440 | + telemetry_events.on_estimate() |
| 441 | + start = monotonic() |
425 | 442 | res_str = get_interpreter().estimate(entry_expr, param_str)
|
426 | 443 | res = json.loads(res_str)
|
| 444 | + |
| 445 | + try: |
| 446 | + qubits = res[0]["logicalCounts"]["numQubits"] |
| 447 | + except (KeyError, IndexError): |
| 448 | + qubits = "unknown" |
| 449 | + |
| 450 | + durationMs = (monotonic() - start) * 1000 |
| 451 | + telemetry_events.on_estimate_end(durationMs, qubits) |
427 | 452 | return EstimatorResult(res)
|
428 | 453 |
|
429 | 454 |
|
|
0 commit comments