MCPcopy Create free account
hub / github.com/dwavesystems/dwave-cloud-client / _sample

Function _sample

dwave/cloud/cli.py:409–428  ·  view source on GitHub ↗

Blocking sample call with error handling and using custom printer.

(sample: Callable[[], Future],
            output: Callable[..., None],
            )

Source from the content-addressed store, hash-verified

407
408
409def _sample(sample: Callable[[], Future],
410 output: Callable[..., None],
411 ) -> Future:
412 """Blocking sample call with error handling and using custom printer."""
413
414 try:
415 response = sample()
416 problem_id = response.wait_id()
417 output("Submitted problem ID: {problem_id}", problem_id=problem_id)
418 response.result()
419 except RequestTimeout:
420 raise CLIError("API connection timed out.", 8)
421 except PollingTimeout:
422 raise CLIError("Polling timeout exceeded.", 9)
423 except InvalidAPIResponseError as e:
424 raise CLIError(f"Invalid or unexpected API response: {e!s}", 3)
425 except Exception as e:
426 raise CLIError(f"Sampling error: {e!s}", 10)
427
428 return response
429
430
431def standardized_output(fn):

Callers 2

pingFunction · 0.85
sampleFunction · 0.85

Calls 5

CLIErrorClass · 0.90
sampleFunction · 0.85
outputFunction · 0.85
wait_idMethod · 0.80
resultMethod · 0.80

Tested by

no test coverage detected