44uploaded to Nexus before stability is achieved might not work in the future.
55"""
66
7+ import warnings
78import base64
89from datetime import datetime
910from typing import Any , Literal , Union , cast
@@ -287,6 +288,11 @@ def cost(
287288 """
288289 import qnexus as qnx
289290
291+ warnings .warn (
292+ "hugr.cost() is deprecated. Please update to use hugr.cost_confidence() instead." ,
293+ category = DeprecationWarning ,
294+ )
295+
290296 if isinstance (programs , HUGRRef ):
291297 programs = [programs ]
292298
@@ -302,6 +308,40 @@ def cost(
302308 return cast (float , status .cost )
303309
304310
311+ def cost_confidence (
312+ programs : HUGRRef | list [HUGRRef ],
313+ n_shots : int | list [int ],
314+ project : ProjectRef | None = None ,
315+ system_name : Literal ["Helios-1" ] = "Helios-1" ,
316+ ) -> list [tuple [float , float ]]:
317+ """Estimate the cost (in HQC) of running Hugr programs for n_shots
318+ number of shots on a Quantinuum Helios system.
319+
320+ Returns a list of tuples of (cost, confidence) for each job item.
321+
322+ NB: This will execute a costing job on a dedicated cost estimation device.
323+ Once run, the cost will be visible also in the Nexus web portal
324+ as part of the job.
325+ """
326+ import qnexus as qnx
327+
328+ if isinstance (programs , HUGRRef ):
329+ programs = [programs ]
330+
331+ job_ref = qnx .start_execute_job (
332+ programs = cast (list [ExecutionProgram ], programs ),
333+ n_shots = n_shots ,
334+ # No other parameters matter for cost estimation, so construct a minimal costing config
335+ backend_config = QuantinuumConfig (device_name = f"{ system_name } SC" ),
336+ project = project ,
337+ name = "Circuit cost confidence estimation job" ,
338+ )
339+
340+ qnx .jobs .wait_for (job_ref )
341+
342+ return qnx .jobs .cost_confidence (job_ref )
343+
344+
305345@merge_scope_from_context
306346def _fetch_by_id (
307347 hugr_id : UUID | str , scope : ScopeFilterEnum = ScopeFilterEnum .USER
0 commit comments