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

Function upload

dwave/cloud/cli.py:741–792  ·  view source on GitHub ↗

Multipart problem upload with cold restart support.

(config_file, profile, endpoint, region, client_type, solver_def,
           problem_id, format, input_file)

Source from the content-addressed store, hash-verified

739 help='Problem data encoding')
740@click.argument('input_file', metavar='FILE', type=click.File('rb'))
741def upload(config_file, profile, endpoint, region, client_type, solver_def,
742 problem_id, format, input_file):
743 """Multipart problem upload with cold restart support."""
744
745 try:
746 client = Client.from_config(
747 config_file=config_file, profile=profile,
748 endpoint=endpoint, region=region,
749 client=client_type)
750 except Exception as e:
751 click.echo("Invalid configuration: {}".format(e))
752 return 1
753 if config_file:
754 click.echo("Using configuration file: {}".format(config_file))
755 if profile:
756 click.echo("Using profile: {}".format(profile))
757 click.echo("Using endpoint: {}".format(client.config.endpoint))
758
759 click.echo(("Preparing to upload a problem from {!r} "
760 "in {!r} format.").format(input_file.name, format))
761
762 if format == 'coo':
763 click.echo("Transcoding 'coo' to 'dimodbqm'.")
764
765 try:
766 import dimod
767 except ImportError: # pragma: no cover
768 raise RuntimeError("Can't decode 'coo' format without dimod. "
769 "Re-install the library with 'bqm' support.")
770
771 # note: `BQM.from_coo` doesn't support files opened in binary (yet);
772 # fallback to reopen for now
773 with open(input_file.name, 'rt') as fp:
774 bqm = dimod.BinaryQuadraticModel.from_coo(fp)
775 problem_file = bqm.to_file()
776
777 elif format == 'dimodbqm':
778 problem_file = input_file
779
780 click.echo("Uploading...")
781
782 try:
783 future = client.upload_problem_encoded(
784 problem=problem_file, problem_id=problem_id)
785 remote_problem_id = future.result()
786 except Exception as e:
787 click.echo(e)
788 return 2
789 finally:
790 problem_file.close()
791
792 click.echo("Upload done. Problem ID: {!r}".format(remote_problem_id))
793
794
795@cli.command()

Callers

nothing calls this directly

Calls 5

resultMethod · 0.80
from_configMethod · 0.45
formatMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected