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

Function ping

dwave/cloud/cli.py:501–556  ·  view source on GitHub ↗

Ping a solver by submitting a single-qubit problem. If solver is not specified, a QPU solver is selected by default.

(*, config_file, profile, endpoint, region, client_type, solver_def,
         sampling_params, request_timeout, polling_timeout, label, json_output,
         output)

Source from the content-addressed store, hash-verified

499@json_output
500@standardized_output
501def ping(*, config_file, profile, endpoint, region, client_type, solver_def,
502 sampling_params, request_timeout, polling_timeout, label, json_output,
503 output):
504 """Ping a solver by submitting a single-qubit problem.
505
506 If solver is not specified, a QPU solver is selected by default.
507 """
508
509 # parse params (TODO: move to click validator)
510 params = {}
511 if sampling_params is not None:
512 try:
513 params = orjson.loads(sampling_params)
514 assert isinstance(params, dict)
515 except:
516 raise CLIError("sampling parameters required as JSON-encoded "
517 "map of param names to values", code=99)
518
519 if label:
520 params.update(label=label)
521
522 # gently prefer the least busy QPU
523 def order_by(solver):
524 category = solver.properties.get('category')
525 avg_load = solver.properties.get('avg_load')
526 return (0 if category == 'qpu' else 1, avg_load)
527
528 config = dict(
529 config_file=config_file, profile=profile,
530 endpoint=endpoint, region=region,
531 client=client_type, solver=solver_def,
532 request_timeout=request_timeout, polling_timeout=polling_timeout,
533 defaults=dict(solver=dict(order_by=order_by)))
534
535 t0 = timer()
536 client, solver = _get_client_solver(config, output)
537
538 # generate problem
539 problem, min_params = solver.minimal_problem
540 params = min_params | params
541
542 t1 = timer()
543 sample = partial(solver.sample_problem, problem=problem, **params)
544 response = _sample(sample, output)
545
546 t2 = timer()
547 output("\nWall clock time:")
548 output(" * Solver definition fetch: {wallclock_solver_definition:.3f} ms", wallclock_solver_definition=(t1-t0)*1000.0)
549 output(" * Problem submit and results fetch: {wallclock_sampling:.3f} ms", wallclock_sampling=(t2-t1)*1000.0)
550 output(" * Total: {wallclock_total:.3f} ms", wallclock_total=(t2-t0)*1000.0)
551 if response.timing:
552 output("\nQPU timing:")
553 for component, duration in sorted(response.timing.items()):
554 output(" * %(name)s = {%(name)s} us" % {"name": component}, **{component: duration})
555 else:
556 output("\nQPU timing data not available.")
557
558

Callers

nothing calls this directly

Calls 4

CLIErrorClass · 0.90
_get_client_solverFunction · 0.85
_sampleFunction · 0.85
outputFunction · 0.85

Tested by

no test coverage detected