Skip to content

Commit

Permalink
re-add calls for RE and compilation telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
sezna committed Oct 30, 2024
1 parent c4abf72 commit 21b32dc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
24 changes: 19 additions & 5 deletions pip/qsharp/_qsharp.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from time import monotonic

_interpreter = None
_config = None

# Check if we are running in a Jupyter notebook to use the IPython display function
_in_jupyter = False
Expand Down Expand Up @@ -163,6 +164,7 @@ def init(
from ._http import fetch_github

global _interpreter
global _config

if isinstance(target_name, str):
target = target_name.split(".")[0].lower()
Expand Down Expand Up @@ -200,9 +202,10 @@ def init(
fetch_github,
)

_config = Config(target_profile, language_features, manifest_contents, project_root)
# Return the configuration information to provide a hint to the
# language service through the cell output.
return Config(target_profile, language_features, manifest_contents, project_root)
return _config


def get_interpreter() -> Interpreter:
Expand Down Expand Up @@ -374,10 +377,15 @@ def compile(entry_expr: str) -> QirInputData:
file.write(str(program))
"""
ipython_helper()

start = monotonic()
global _config
target_profile = _config._config.get("targetProfile", "unspecified")
telemetry_events.on_compile(target_profile)
ll_str = get_interpreter().qir(entry_expr)
return QirInputData("main", ll_str)

res = QirInputData("main", ll_str)
durationMs = (monotonic() - start) * 1000
telemetry_events.on_compile_end(durationMs, target_profile)
return res

def circuit(
entry_expr: Optional[str] = None, *, operation: Optional[str] = None
Expand Down Expand Up @@ -429,9 +437,15 @@ def _coerce_estimator_params(

params = _coerce_estimator_params(params)
param_str = json.dumps(params)

telemetry_events.on_estimate()
start = monotonic()
res_str = get_interpreter().estimate(entry_expr, param_str)
res = json.loads(res_str)

qubits = res[0]["logicalCounts"]["numQubits"]

durationMs = (monotonic() - start) * 1000
telemetry_events.on_estimate_end(durationMs, qubits)
return EstimatorResult(res)


Expand Down
5 changes: 4 additions & 1 deletion pip/qsharp/telemetry_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ def get_shots_bucket(shots: int) -> int:


# gets the order of magnitude for the number of qubits
def get_qubits_bucket(qubits: int) -> int:
def get_qubits_bucket(qubits: str) -> str:
if qubits == "unknown":
return "unknown"
qubits = int(qubits)
if qubits <= 1:
return 1
elif qubits >= 50:
Expand Down

0 comments on commit 21b32dc

Please sign in to comment.