azure-quantum 1.1.1.dev0__py3-none-any.whl → 1.1.2.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- azure/quantum/_authentication/_default.py +11 -11
- azure/quantum/_client/_version.py +1 -1
- azure/quantum/_constants.py +9 -7
- azure/quantum/_workspace_connection_params.py +69 -71
- azure/quantum/job/base_job.py +1 -1
- azure/quantum/job/job.py +4 -2
- azure/quantum/qiskit/provider.py +0 -2
- azure/quantum/target/__init__.py +0 -5
- azure/quantum/target/microsoft/elements/dft/job.py +2 -2
- azure/quantum/target/rigetti/target.py +0 -4
- azure/quantum/target/target_factory.py +2 -8
- azure/quantum/version.py +1 -1
- azure/quantum/workspace.py +2 -2
- {azure_quantum-1.1.1.dev0.dist-info → azure_quantum-1.1.2.dev0.dist-info}/METADATA +12 -13
- {azure_quantum-1.1.1.dev0.dist-info → azure_quantum-1.1.2.dev0.dist-info}/RECORD +17 -28
- azure/quantum/optimization/__init__.py +0 -11
- azure/quantum/optimization/online_problem.py +0 -21
- azure/quantum/optimization/problem.py +0 -393
- azure/quantum/optimization/solvers.py +0 -10
- azure/quantum/optimization/streaming_problem.py +0 -387
- azure/quantum/optimization/term.py +0 -203
- azure/quantum/optimization/toshiba/__init__.py +0 -10
- azure/quantum/optimization/toshiba/solvers.py +0 -12
- azure/quantum/target/solvers.py +0 -382
- azure/quantum/target/toshiba/__init__.py +0 -7
- azure/quantum/target/toshiba/solvers.py +0 -130
- {azure_quantum-1.1.1.dev0.dist-info → azure_quantum-1.1.2.dev0.dist-info}/WHEEL +0 -0
- {azure_quantum-1.1.1.dev0.dist-info → azure_quantum-1.1.2.dev0.dist-info}/top_level.txt +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
azure/quantum/__init__.py,sha256=Za8xZY4lzFkW8m4ero-bqrfN437D2NRukM77ukb4GPM,508
|
|
2
|
-
azure/quantum/_constants.py,sha256=
|
|
3
|
-
azure/quantum/_workspace_connection_params.py,sha256=
|
|
2
|
+
azure/quantum/_constants.py,sha256=6FCBpjUK2GHeycKejgGYTvxtlSsfWdbG2iOXGQg8NaM,3219
|
|
3
|
+
azure/quantum/_workspace_connection_params.py,sha256=fGha3ALz1YRnKo07xHCbDzDcmUS7rsaakGvx_pvVINo,21632
|
|
4
4
|
azure/quantum/storage.py,sha256=_4bMniDk9LrB_K5CQwuCivJFZXdmhRvU2b6Z3xxXw9I,12556
|
|
5
|
-
azure/quantum/version.py,sha256
|
|
6
|
-
azure/quantum/workspace.py,sha256=
|
|
5
|
+
azure/quantum/version.py,sha256=-vAeAqsgIjIU8KmFftm1j4jiGOI7BOHvbIG4ovYqcv4,240
|
|
6
|
+
azure/quantum/workspace.py,sha256=QXnIHOOYEGixajbZ8oeEWu-fAUI_Fms4zkA_amurm3g,17607
|
|
7
7
|
azure/quantum/_authentication/__init__.py,sha256=bniNZlS0hMIjO_y7DevGBAS6MixyA5pbPHcdGipUWM4,236
|
|
8
8
|
azure/quantum/_authentication/_chained.py,sha256=0rdohB_fVGFHUhlly9sGxqQTBTZGpGxtlBqNHDFbAqE,4848
|
|
9
|
-
azure/quantum/_authentication/_default.py,sha256=
|
|
9
|
+
azure/quantum/_authentication/_default.py,sha256=RzhK5UNQb6TK95VQI4o8Gm2nxtOaz64yA0J9Tw9zpW4,6625
|
|
10
10
|
azure/quantum/_authentication/_token.py,sha256=mOrvibDiOgkDnqU1OBIw9PyIv-np6DkdxMNC4UtuGkc,3616
|
|
11
11
|
azure/quantum/_client/__init__.py,sha256=kzaVxPfnju-Y_EGMfOVYVB7pHjPvc-IWrkFI2eNk68s,896
|
|
12
12
|
azure/quantum/_client/_client.py,sha256=ZG-zalnITLyBk3BSMjLt4PtnNv8Nky5-kcmnIrk1IkQ,7143
|
|
@@ -14,7 +14,7 @@ azure/quantum/_client/_configuration.py,sha256=5uktKtZxoVVAoSyeL0VNGS9AfPERp-9rU
|
|
|
14
14
|
azure/quantum/_client/_patch.py,sha256=YTV6yZ9bRfBBaw2z7v4MdzR-zeHkdtKkGb4SU8C25mE,694
|
|
15
15
|
azure/quantum/_client/_serialization.py,sha256=KJSS6KWgnKcz-cENQCmWZ9Ziv303lnBbLwFIpYZeKFU,81097
|
|
16
16
|
azure/quantum/_client/_vendor.py,sha256=h8ByiyZ4cCQyFxqnuhTQdv1Rms3dVjKsrgZDzwMcSJ0,996
|
|
17
|
-
azure/quantum/_client/_version.py,sha256=
|
|
17
|
+
azure/quantum/_client/_version.py,sha256=1BvMPpsGTc8vSsVvDoi2TMiSVPtozGm87WOCYKmau7Q,500
|
|
18
18
|
azure/quantum/_client/models/__init__.py,sha256=c1PRpzNsQTcDk4GkrFMMIlwNQQa2c0p5N0Lzd-23YBA,2100
|
|
19
19
|
azure/quantum/_client/models/_enums.py,sha256=omj_B8_E8ONzTHg5hLgDlFYibRRbdr9sEN298im_otA,2977
|
|
20
20
|
azure/quantum/_client/models/_models.py,sha256=wktCM5oBVfwQetNoHobL1wNsC3knXV-HmqBq_Q77Kw4,41810
|
|
@@ -33,24 +33,16 @@ azure/quantum/cirq/targets/ionq.py,sha256=xCabcYklH9wW1TFBzpMdxvipzqhKWCYbtcgNqD
|
|
|
33
33
|
azure/quantum/cirq/targets/quantinuum.py,sha256=t7L5prczDQJlzStth6Rh6r35DX1Z8J_my-VJxLBp2n4,4537
|
|
34
34
|
azure/quantum/cirq/targets/target.py,sha256=1EEog72dFZoiOTQP7obOrCuO3VH0yjXGAIMeO6bm22o,2184
|
|
35
35
|
azure/quantum/job/__init__.py,sha256=bRfMuK8aAQGwggoXF4bwymwBjBumBrQFqw0LjvSMWhI,762
|
|
36
|
-
azure/quantum/job/base_job.py,sha256=
|
|
36
|
+
azure/quantum/job/base_job.py,sha256=NovuhFFH4HCpXRDn2EwlWAxcpY8Kenu58RwbddIbtdA,12882
|
|
37
37
|
azure/quantum/job/filtered_job.py,sha256=qZfxTuDp0hzK4wermn4GRzLxnDy4yM-j6oZQ3D0O4vI,1877
|
|
38
|
-
azure/quantum/job/job.py,sha256=
|
|
38
|
+
azure/quantum/job/job.py,sha256=V69KjIw6QvxlDgnU3xOmfMU2SdU3AwGrqeRd4olvUM4,6151
|
|
39
39
|
azure/quantum/job/job_failed_with_results_error.py,sha256=4NZVUPnCnnJsSmNg9VkIjcRChK118jkCfKlVBlHNE24,1279
|
|
40
40
|
azure/quantum/job/session.py,sha256=EEJVKEEB5g0yyH963aaR0GY0Cd0axrX-49gwDWxBcfE,11961
|
|
41
41
|
azure/quantum/job/workspace_item.py,sha256=lyBIJCtUfIZMGJYJkX7Se8IDnXhXe4JU0RnqzSuhhI4,1380
|
|
42
42
|
azure/quantum/job/workspace_item_factory.py,sha256=QRWyrtgcKZqUucJOFi9V_SYMV3lj6S74tGRrPtk3NE0,1200
|
|
43
|
-
azure/quantum/optimization/__init__.py,sha256=EQbilP4U-XfED1QCBOx8Nz2xapcpHx_CA5o0ZkiXyMg,276
|
|
44
|
-
azure/quantum/optimization/online_problem.py,sha256=6XMnl-5U17CSYsWaplEcuMIBpMzS-QyrcWPxq0Vmt3w,636
|
|
45
|
-
azure/quantum/optimization/problem.py,sha256=UpuMXfk4SRqmfCh68baVSUlEP_ZxtRET-DwPniBbOD8,13570
|
|
46
|
-
azure/quantum/optimization/solvers.py,sha256=m6O_n8-GJbnk_waO4vtZLiQskpGRGjy0BiyVHi6A9-M,319
|
|
47
|
-
azure/quantum/optimization/streaming_problem.py,sha256=tTvw-SRx90Z2XzmOYvxP42X4LGMy5ZecBzni_lwpCEY,13650
|
|
48
|
-
azure/quantum/optimization/term.py,sha256=5OP_XeGN4SjozesvpW9QV7g3pc2xEOINN5uiAW59UWo,5983
|
|
49
|
-
azure/quantum/optimization/toshiba/__init__.py,sha256=wdtNlaOhnN10P631WZvYFIvfUXjpGthNGxNQQAKxhmc,302
|
|
50
|
-
azure/quantum/optimization/toshiba/solvers.py,sha256=s3DceUtsMh1L6AycfFM9fa-eOEiE7tM5hIV3noYbV8U,374
|
|
51
43
|
azure/quantum/qiskit/__init__.py,sha256=7Ok1mrUf-fsVuOJjVBx7OGzXJ7oHAI1Zqm8R2wdjMgE,273
|
|
52
44
|
azure/quantum/qiskit/job.py,sha256=PHgEIY7dOQtpfo-J--frj-PVX3OWr8llfBUv9VClLNg,14370
|
|
53
|
-
azure/quantum/qiskit/provider.py,sha256=
|
|
45
|
+
azure/quantum/qiskit/provider.py,sha256=R9Zx6nSrx8U3iKy0ALoUy01I0pdCKSBvOhomQstFdRo,10789
|
|
54
46
|
azure/quantum/qiskit/backends/__init__.py,sha256=ULX3zXu9eTUX0Tyo-vXp3QMlCbxaV2bHvepRaAM_KBo,1082
|
|
55
47
|
azure/quantum/qiskit/backends/backend.py,sha256=9Rqkac8PN7fwNM2K8zXuoM9UQeM6Xi3ua0KHpoANZHI,20409
|
|
56
48
|
azure/quantum/qiskit/backends/ionq.py,sha256=rxAhWvXrAMuFbdg72qDy_MKIx8EuCV7BvKCgwQwpogY,18024
|
|
@@ -60,30 +52,27 @@ azure/quantum/qiskit/backends/quantinuum.py,sha256=6lm4yWv-3724PBaB9dnJfdeOvlGro
|
|
|
60
52
|
azure/quantum/qiskit/backends/rigetti.py,sha256=QeV_kQveHk9uUZUZLR0CiHhrcVY8twJWLb2Wh1h5Lrk,4248
|
|
61
53
|
azure/quantum/qiskit/results/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
62
54
|
azure/quantum/qiskit/results/resource_estimator.py,sha256=pAP5ZpVxdzNekQ_qXfSdSKYWWuqL_Vq7WK6pWU4wbEQ,814
|
|
63
|
-
azure/quantum/target/__init__.py,sha256=
|
|
55
|
+
azure/quantum/target/__init__.py,sha256=F0nIEJdlbczmxAdtvPDWf8J1Y33_XjPzloliHeWpJos,689
|
|
64
56
|
azure/quantum/target/ionq.py,sha256=f6V_Ce09RHU56NmCdwcupDDjSxA3kDVodjwEBvpWrvg,8130
|
|
65
57
|
azure/quantum/target/params.py,sha256=oI-35HUEMCskNjpxCJU3tjL664K-TxqAg5LA5xU0nso,9130
|
|
66
58
|
azure/quantum/target/quantinuum.py,sha256=2VWng9h-OA7v9GeSsmMFWHVqBITqPrFjQcD5fH8ANHU,7710
|
|
67
|
-
azure/quantum/target/solvers.py,sha256=_Uhz9k7CNJk6cR6fsRrWp_ZhlpEerc3le16j75yg6Pg,14963
|
|
68
59
|
azure/quantum/target/target.py,sha256=X8FLG1sfcdul6tH58XtxQuvRm3B3OjYiI7opPxMfb1M,13850
|
|
69
|
-
azure/quantum/target/target_factory.py,sha256=
|
|
60
|
+
azure/quantum/target/target_factory.py,sha256=5nYFo_PLvnDrsILMd4zzprnjQSJCj2P-as5Z-J8_tnk,5053
|
|
70
61
|
azure/quantum/target/microsoft/__init__.py,sha256=36kM2YlWv69AzAfUA5wMdWyYRSaCMwX2Ajhffpzx67g,570
|
|
71
62
|
azure/quantum/target/microsoft/job.py,sha256=GM4OA-rxFUqQzsH8V59pVc4BmBaPYvd99E26pyPwxto,1249
|
|
72
63
|
azure/quantum/target/microsoft/result.py,sha256=AntJptXKHNRdRR6oxhTlKKPOJVSU7u9fIfH2GXJqfx0,18784
|
|
73
64
|
azure/quantum/target/microsoft/target.py,sha256=D7KS3AH-sjD1MVXL-J0SG61aGdWlrTZNT9JicjJzWeE,17879
|
|
74
65
|
azure/quantum/target/microsoft/elements/__init__.py,sha256=gVVpaN5086iuBnajtvTjSd7MLExtnsR6RDCmcgz6xpE,70
|
|
75
66
|
azure/quantum/target/microsoft/elements/dft/__init__.py,sha256=kCXOA9HT-gb23An-A0eyktlB66VoH6EwNO4gPM97l3U,224
|
|
76
|
-
azure/quantum/target/microsoft/elements/dft/job.py,sha256=
|
|
67
|
+
azure/quantum/target/microsoft/elements/dft/job.py,sha256=0CPe4Xf1iniEBt4--4PsbHUE5NZraP5tMk1H96sZzyM,2854
|
|
77
68
|
azure/quantum/target/microsoft/elements/dft/target.py,sha256=IeFDVh3SqDsQOZmd9UKhl1Qu0ChkOEIHHb5fC5x4YGE,2556
|
|
78
69
|
azure/quantum/target/pasqal/__init__.py,sha256=qbe6oWTQTsnTYwY3xZr32z4AWaYIchx71bYlqC2rQqw,348
|
|
79
70
|
azure/quantum/target/pasqal/result.py,sha256=4hs1SP02bKA73bX2CEKdOyTufLp7Fx6W7K-sCmdUKrc,1458
|
|
80
71
|
azure/quantum/target/pasqal/target.py,sha256=j9xK9chbmo-FL4Y9HBVqtL14Rr6lxQK6UN-lMMo6hME,3966
|
|
81
72
|
azure/quantum/target/rigetti/__init__.py,sha256=I1vyzZBYGI540pauTqJd0RSSyTShGqkEL7Yjo25_RNY,378
|
|
82
73
|
azure/quantum/target/rigetti/result.py,sha256=yDtT1y-JZFU7_mCaN1V_E6LPjJVD2vn4jvHOPT0IP9k,2278
|
|
83
|
-
azure/quantum/target/rigetti/target.py,sha256=
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
azure_quantum-1.1.
|
|
87
|
-
azure_quantum-1.1.
|
|
88
|
-
azure_quantum-1.1.1.dev0.dist-info/top_level.txt,sha256=S7DhWV9m80TBzAhOFjxDUiNbKszzoThbnrSz5MpbHSQ,6
|
|
89
|
-
azure_quantum-1.1.1.dev0.dist-info/RECORD,,
|
|
74
|
+
azure/quantum/target/rigetti/target.py,sha256=hGZm1wkBb1CBtDBWXEFS2Nje6gRXBTjOYgFkjOJ7TZ8,6458
|
|
75
|
+
azure_quantum-1.1.2.dev0.dist-info/METADATA,sha256=Zorh_0O9e8Wlm5o9DWOxLThwb2Evn68rVPmzrct02MU,7309
|
|
76
|
+
azure_quantum-1.1.2.dev0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
77
|
+
azure_quantum-1.1.2.dev0.dist-info/top_level.txt,sha256=S7DhWV9m80TBzAhOFjxDUiNbKszzoThbnrSz5MpbHSQ,6
|
|
78
|
+
azure_quantum-1.1.2.dev0.dist-info/RECORD,,
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
# coding=utf-8
|
|
2
|
-
##
|
|
3
|
-
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
-
# Licensed under the MIT License.
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
from .term import *
|
|
8
|
-
from .problem import *
|
|
9
|
-
from .streaming_problem import *
|
|
10
|
-
from .online_problem import *
|
|
11
|
-
from azure.quantum.target.solvers import *
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import logging
|
|
2
|
-
from typing import TYPE_CHECKING
|
|
3
|
-
from azure.quantum.optimization import Problem
|
|
4
|
-
|
|
5
|
-
logger = logging.getLogger(__name__)
|
|
6
|
-
|
|
7
|
-
__all__ = ["OnlineProblem"]
|
|
8
|
-
|
|
9
|
-
if TYPE_CHECKING:
|
|
10
|
-
from azure.quantum.workspace import Workspace
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class OnlineProblem(object):
|
|
14
|
-
def __init__(self, name: str, blob_uri: str, **kw):
|
|
15
|
-
super(OnlineProblem, self).__init__(**kw)
|
|
16
|
-
self.name = name
|
|
17
|
-
self.uploaded_blob_uri = blob_uri
|
|
18
|
-
|
|
19
|
-
def download(self, workspace: "Workspace") -> Problem:
|
|
20
|
-
logger.warning("The problem will be downloaded to the client")
|
|
21
|
-
return Problem.download(self, workspace)
|
|
@@ -1,393 +0,0 @@
|
|
|
1
|
-
##
|
|
2
|
-
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
# Licensed under the MIT License.
|
|
4
|
-
##
|
|
5
|
-
|
|
6
|
-
from __future__ import annotations
|
|
7
|
-
import logging
|
|
8
|
-
import io
|
|
9
|
-
import gzip
|
|
10
|
-
import json
|
|
11
|
-
import numpy
|
|
12
|
-
import os
|
|
13
|
-
import tarfile
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
from typing import List, Tuple, Union, Dict, Optional, TYPE_CHECKING
|
|
17
|
-
from enum import Enum
|
|
18
|
-
from azure.quantum.optimization import TermBase, Term
|
|
19
|
-
from azure.quantum.storage import (
|
|
20
|
-
ContainerClient,
|
|
21
|
-
download_blob,
|
|
22
|
-
BlobClient,
|
|
23
|
-
download_blob_metadata,
|
|
24
|
-
download_blob_properties
|
|
25
|
-
)
|
|
26
|
-
from azure.quantum.job.base_job import ContentType
|
|
27
|
-
from azure.quantum.job.job import Job
|
|
28
|
-
from azure.quantum.target.target import Target
|
|
29
|
-
|
|
30
|
-
logger = logging.getLogger(__name__)
|
|
31
|
-
|
|
32
|
-
__all__ = ["Problem", "ProblemType"]
|
|
33
|
-
|
|
34
|
-
if TYPE_CHECKING:
|
|
35
|
-
from azure.quantum.workspace import Workspace
|
|
36
|
-
|
|
37
|
-
class ProblemType(str, Enum):
|
|
38
|
-
pubo = 0
|
|
39
|
-
ising = 1
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
class Problem:
|
|
43
|
-
"""Problem to submit to the service.
|
|
44
|
-
|
|
45
|
-
:param name: Problem name
|
|
46
|
-
:type name: str
|
|
47
|
-
When passing None, it will default to "Optimization problem"
|
|
48
|
-
:param terms: Problem terms, depending on solver.
|
|
49
|
-
Defaults to None
|
|
50
|
-
:type terms: Optional[List[TermBase]], optional
|
|
51
|
-
:param init_config: Optional configuration details, depending on solver.
|
|
52
|
-
Defaults to None
|
|
53
|
-
:type init_config: Optional[Dict[str,int]], optional
|
|
54
|
-
:param problem_type: Problem type (ProblemType.pubo or
|
|
55
|
-
ProblemType.ising), defaults to ProblemType.ising
|
|
56
|
-
:type problem_type: ProblemType, optional
|
|
57
|
-
:param content_type: Content type, eg: application/json. Default is application/json
|
|
58
|
-
:type content_type: ContentType, optional
|
|
59
|
-
"""
|
|
60
|
-
|
|
61
|
-
def __init__(
|
|
62
|
-
self,
|
|
63
|
-
name: str,
|
|
64
|
-
terms: Optional[List[TermBase]] = None,
|
|
65
|
-
init_config: Optional[Dict[str, int]] = None,
|
|
66
|
-
problem_type: ProblemType = ProblemType.ising,
|
|
67
|
-
content_type: Optional[ContentType] = ContentType.json
|
|
68
|
-
):
|
|
69
|
-
self.name = name or "Optimization problem"
|
|
70
|
-
self.problem_type = problem_type
|
|
71
|
-
self.init_config = init_config
|
|
72
|
-
self.uploaded_blob_uri = None
|
|
73
|
-
self.uploaded_blob_params = None
|
|
74
|
-
self.content_type = content_type
|
|
75
|
-
|
|
76
|
-
# each type of term has its own section for quicker serialization
|
|
77
|
-
self.terms = []
|
|
78
|
-
|
|
79
|
-
# set the terms
|
|
80
|
-
if terms:
|
|
81
|
-
for term in terms:
|
|
82
|
-
self.terms.append(term)
|
|
83
|
-
|
|
84
|
-
"""
|
|
85
|
-
Constant thresholds used to determine if a problem is "large".
|
|
86
|
-
"""
|
|
87
|
-
NUM_VARIABLES_LARGE = 2500
|
|
88
|
-
NUM_TERMS_LARGE = 1e6
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
def serialize(self) -> Union[str, list]:
|
|
92
|
-
"""Wrapper function for serializing to json
|
|
93
|
-
"""
|
|
94
|
-
return self.to_json()
|
|
95
|
-
|
|
96
|
-
def to_json(self) -> str:
|
|
97
|
-
"""Serializes the problem to a JSON string"""
|
|
98
|
-
result = {
|
|
99
|
-
"metadata": {
|
|
100
|
-
"name": self.name,
|
|
101
|
-
},
|
|
102
|
-
"cost_function": {
|
|
103
|
-
"version": "1.1" if self.init_config else "1.0",
|
|
104
|
-
"type": self.problem_type.name,
|
|
105
|
-
"terms": [term.to_dict() for term in self.terms]
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if self.init_config:
|
|
110
|
-
result["cost_function"]["initial_configuration"] = self.init_config
|
|
111
|
-
|
|
112
|
-
return json.dumps(result)
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
@classmethod
|
|
116
|
-
def from_json(
|
|
117
|
-
cls,
|
|
118
|
-
input_problem: str,
|
|
119
|
-
name: Optional[str] = None
|
|
120
|
-
) -> Problem:
|
|
121
|
-
"""Deserializes the problem from a
|
|
122
|
-
json serialized with Problem.serialize()
|
|
123
|
-
|
|
124
|
-
:param input_problem:
|
|
125
|
-
the json string to be deserialized to a `Problem` instance
|
|
126
|
-
:type problem_msgs: str
|
|
127
|
-
:param
|
|
128
|
-
:param name:
|
|
129
|
-
The name of the problem is optional, since it will try
|
|
130
|
-
to read the serialized name from the json payload.
|
|
131
|
-
If this parameter is not empty, it will use it as the
|
|
132
|
-
problem name ignoring the serialized value.
|
|
133
|
-
:type name: Optional[str]
|
|
134
|
-
"""
|
|
135
|
-
result = json.loads(input_problem)
|
|
136
|
-
|
|
137
|
-
if name is None:
|
|
138
|
-
metadata = result.get("metadata")
|
|
139
|
-
if metadata is not None:
|
|
140
|
-
name = metadata.get("name")
|
|
141
|
-
|
|
142
|
-
terms = [Term.from_dict(t) for t in result["cost_function"]["terms"]] if "terms" in result["cost_function"] else []
|
|
143
|
-
|
|
144
|
-
problem = cls(
|
|
145
|
-
name=name,
|
|
146
|
-
terms=terms,
|
|
147
|
-
problem_type=ProblemType[result["cost_function"]["type"]],
|
|
148
|
-
)
|
|
149
|
-
|
|
150
|
-
if "initial_configuration" in result["cost_function"]:
|
|
151
|
-
problem.init_config = result["cost_function"]["initial_configuration"]
|
|
152
|
-
|
|
153
|
-
return problem
|
|
154
|
-
|
|
155
|
-
@classmethod
|
|
156
|
-
def deserialize(
|
|
157
|
-
cls,
|
|
158
|
-
input_problem: Union[str, list],
|
|
159
|
-
name: Optional[str] = None,
|
|
160
|
-
content_type: Optional[ContentType] = None) -> Problem:
|
|
161
|
-
"""Deserializes the problem from a
|
|
162
|
-
JSON string serialized with Problem.serialize()
|
|
163
|
-
Also used to deserialize the messages downloaded from the blob
|
|
164
|
-
|
|
165
|
-
:param input_problem:
|
|
166
|
-
The json string
|
|
167
|
-
:type input_problem: Union[str,list]
|
|
168
|
-
:param
|
|
169
|
-
:param name:
|
|
170
|
-
The name of the problem is optional, since it will try
|
|
171
|
-
to read the serialized name from the json payload.
|
|
172
|
-
If this parameter is not empty, it will use it as the
|
|
173
|
-
problem name ignoring the serialized value.
|
|
174
|
-
:type name: Optional[str]
|
|
175
|
-
:param content_type: The content type of the input problem data
|
|
176
|
-
:type: Optional, ContentType
|
|
177
|
-
"""
|
|
178
|
-
return cls.from_json(input_problem, name)
|
|
179
|
-
|
|
180
|
-
def add_term(self, c: Union[int, float], indices: List[int]):
|
|
181
|
-
"""Adds a single monomial term to the `Problem` representation
|
|
182
|
-
|
|
183
|
-
:param c: The cost or weight of this term
|
|
184
|
-
:type c: int, float
|
|
185
|
-
:param indices: The variable indices that are in this term
|
|
186
|
-
:type indices: List[int]
|
|
187
|
-
"""
|
|
188
|
-
self.terms.append(Term(indices=indices, c=c))
|
|
189
|
-
self.uploaded_blob_uri = None
|
|
190
|
-
|
|
191
|
-
def add_terms(
|
|
192
|
-
self,
|
|
193
|
-
terms: List[Term]
|
|
194
|
-
):
|
|
195
|
-
"""Adds a list of monomial terms to the `Problem` representation
|
|
196
|
-
|
|
197
|
-
:param terms: The list of terms to add to the problem
|
|
198
|
-
"""
|
|
199
|
-
self.terms += terms
|
|
200
|
-
self.uploaded_blob_uri = None
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
def to_blob(self) -> bytes:
|
|
204
|
-
"""Convert problem data to a binary blob.
|
|
205
|
-
|
|
206
|
-
:return: Blob data
|
|
207
|
-
:rtype: bytes
|
|
208
|
-
"""
|
|
209
|
-
input_problem = self.serialize()
|
|
210
|
-
debug_input_string = input_problem if type(input_problem) is str else b''.join( input_problem).decode('latin-1')
|
|
211
|
-
logger.debug("Input Problem: " + debug_input_string)
|
|
212
|
-
data = io.BytesIO()
|
|
213
|
-
with gzip.GzipFile(fileobj=data, mode="w") as fo:
|
|
214
|
-
fo.write(input_problem.encode())
|
|
215
|
-
|
|
216
|
-
return data.getvalue()
|
|
217
|
-
|
|
218
|
-
def _blob_name(self):
|
|
219
|
-
import uuid
|
|
220
|
-
return "{}-{}".format(self.name, uuid.uuid1())
|
|
221
|
-
|
|
222
|
-
def upload(
|
|
223
|
-
self,
|
|
224
|
-
workspace: "Workspace",
|
|
225
|
-
container_name: str = "optimization-problems",
|
|
226
|
-
blob_name: str = "inputData",
|
|
227
|
-
container_uri: str = None,
|
|
228
|
-
):
|
|
229
|
-
"""Uploads an optimization problem instance to
|
|
230
|
-
the cloud storage linked with the Workspace.
|
|
231
|
-
|
|
232
|
-
:param workspace: interaction terms of the problem.
|
|
233
|
-
:type workspace: Workspace
|
|
234
|
-
:param container_name: Container name, defaults to "optimization-problems"
|
|
235
|
-
:type container_name: str, optional
|
|
236
|
-
:param blob_name: Blob name, defaults to None
|
|
237
|
-
:type blob_name: str, optional
|
|
238
|
-
:param container_uri: Optional container URI
|
|
239
|
-
:type container_uri: str
|
|
240
|
-
:return: uri of the uploaded problem
|
|
241
|
-
:rtype: str
|
|
242
|
-
"""
|
|
243
|
-
blob_params = [workspace, container_name, blob_name]
|
|
244
|
-
if self.uploaded_blob_uri and self.uploaded_blob_params == blob_params:
|
|
245
|
-
return self.uploaded_blob_uri
|
|
246
|
-
|
|
247
|
-
if blob_name is None:
|
|
248
|
-
blob_name = self._blob_name()
|
|
249
|
-
|
|
250
|
-
encoding = "gzip"
|
|
251
|
-
content_type = self.content_type
|
|
252
|
-
|
|
253
|
-
blob = self.to_blob()
|
|
254
|
-
if container_uri is None:
|
|
255
|
-
container_uri = workspace.get_container_uri(
|
|
256
|
-
container_name=container_name
|
|
257
|
-
)
|
|
258
|
-
input_data_uri = Job.upload_input_data(
|
|
259
|
-
input_data=blob,
|
|
260
|
-
blob_name=blob_name,
|
|
261
|
-
container_uri=container_uri,
|
|
262
|
-
encoding=encoding,
|
|
263
|
-
content_type= content_type
|
|
264
|
-
)
|
|
265
|
-
self.uploaded_blob_params = blob_params
|
|
266
|
-
self.uploaded_blob_uri = input_data_uri
|
|
267
|
-
return input_data_uri
|
|
268
|
-
|
|
269
|
-
def set_fixed_variables(
|
|
270
|
-
self, fixed_variables: Union[Dict[int, int], Dict[str, int]]
|
|
271
|
-
) -> Problem:
|
|
272
|
-
"""Transforms the current problem with a set of fixed
|
|
273
|
-
variables and returns the new modified problem.
|
|
274
|
-
The original Problem instance is untouched.
|
|
275
|
-
|
|
276
|
-
:param fixed_variables:
|
|
277
|
-
The dictionary of variable ids and their fixed state
|
|
278
|
-
"""
|
|
279
|
-
if len(fixed_variables) == 0:
|
|
280
|
-
raise RuntimeError(
|
|
281
|
-
"Error: fixed_variables is empty - \
|
|
282
|
-
please specify at least one fixed variable"
|
|
283
|
-
)
|
|
284
|
-
|
|
285
|
-
fixed_transformed = {
|
|
286
|
-
int(k): fixed_variables[k] for k in fixed_variables
|
|
287
|
-
} # if ids are given in string form, convert them to int
|
|
288
|
-
new_terms = []
|
|
289
|
-
|
|
290
|
-
constant = 0
|
|
291
|
-
for term in self.terms:
|
|
292
|
-
reduced_term = term.reduce_by_variable_state(fixed_transformed)
|
|
293
|
-
if reduced_term:
|
|
294
|
-
if not isinstance(reduced_term, Term) or len(reduced_term.ids) > 0:
|
|
295
|
-
new_terms.append(reduced_term)
|
|
296
|
-
else:
|
|
297
|
-
# reduced to a constant term
|
|
298
|
-
constant += reduced_term.c
|
|
299
|
-
|
|
300
|
-
if constant:
|
|
301
|
-
new_terms.append(Term(c=constant, indices=[]))
|
|
302
|
-
|
|
303
|
-
new_init_config = None
|
|
304
|
-
if self.init_config:
|
|
305
|
-
new_init_config = {
|
|
306
|
-
k: self.init_config[k]
|
|
307
|
-
for k in self.init_config
|
|
308
|
-
if int(k) not in fixed_transformed
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
return Problem(
|
|
312
|
-
self.name,
|
|
313
|
-
terms=new_terms,
|
|
314
|
-
init_config=new_init_config,
|
|
315
|
-
problem_type=self.problem_type,
|
|
316
|
-
)
|
|
317
|
-
|
|
318
|
-
def _evaluate(self, configuration, term_list):
|
|
319
|
-
total = 0
|
|
320
|
-
if term_list:
|
|
321
|
-
for term in term_list:
|
|
322
|
-
total += term.evaluate(configuration)
|
|
323
|
-
return total
|
|
324
|
-
|
|
325
|
-
def evaluate(self, configuration: Union[Dict[int, int], Dict[str, int]]) -> float:
|
|
326
|
-
"""Given a configuration/variable assignment,
|
|
327
|
-
return the cost function value of this problem.
|
|
328
|
-
|
|
329
|
-
:param configuration: The dictionary of
|
|
330
|
-
variable ids to their assigned value
|
|
331
|
-
"""
|
|
332
|
-
configuration_transformed = {
|
|
333
|
-
int(k): configuration[k] for k in configuration
|
|
334
|
-
} # if ids are given in string form, convert them to int
|
|
335
|
-
|
|
336
|
-
total_cost = 0
|
|
337
|
-
for terms in self.terms:
|
|
338
|
-
total_cost += self._evaluate(configuration_transformed, terms)
|
|
339
|
-
|
|
340
|
-
return total_cost
|
|
341
|
-
|
|
342
|
-
def is_large(self) -> bool:
|
|
343
|
-
"""Determines if the current problem is large.
|
|
344
|
-
"large" is an arbitrary threshold and can be easily changed.
|
|
345
|
-
Based on usage data, we have defined a
|
|
346
|
-
large problem to be NUM_VARIABLES_LARGE+
|
|
347
|
-
variables AND NUM_TERMS_LARGE+ terms.
|
|
348
|
-
"""
|
|
349
|
-
|
|
350
|
-
set_vars = set()
|
|
351
|
-
total_term_count = 0
|
|
352
|
-
for term in self.terms:
|
|
353
|
-
if isinstance(term, Term):
|
|
354
|
-
set_vars.update(term.ids)
|
|
355
|
-
total_term_count += 1
|
|
356
|
-
|
|
357
|
-
return (
|
|
358
|
-
len(set_vars) >= Problem.NUM_VARIABLES_LARGE
|
|
359
|
-
and total_term_count >= Problem.NUM_TERMS_LARGE
|
|
360
|
-
)
|
|
361
|
-
|
|
362
|
-
def download(self, workspace: "Workspace"):
|
|
363
|
-
"""Downloads the uploaded problem as an instance of `Problem`"""
|
|
364
|
-
if not self.uploaded_blob_uri:
|
|
365
|
-
raise Exception("Problem may not be downloaded before it is uploaded")
|
|
366
|
-
blob_client = BlobClient.from_blob_url(self.uploaded_blob_uri)
|
|
367
|
-
container_client = ContainerClient.from_container_url(
|
|
368
|
-
workspace._get_linked_storage_sas_uri(blob_client.container_name)
|
|
369
|
-
)
|
|
370
|
-
blob_name = blob_client.blob_name
|
|
371
|
-
blob = container_client.get_blob_client(blob_name)
|
|
372
|
-
contents = download_blob(blob.url)
|
|
373
|
-
blob_properties = download_blob_properties(blob.url)
|
|
374
|
-
content_type = blob_properties.content_type
|
|
375
|
-
return Problem.deserialize(contents, self.name, content_type)
|
|
376
|
-
|
|
377
|
-
def get_terms(self, id: int) -> List[TermBase]:
|
|
378
|
-
"""Given an index the function will return
|
|
379
|
-
a list of terms with that index
|
|
380
|
-
"""
|
|
381
|
-
terms = []
|
|
382
|
-
if self.terms != []:
|
|
383
|
-
for term in self.terms:
|
|
384
|
-
if isinstance(term, Term):
|
|
385
|
-
if id in term.ids:
|
|
386
|
-
terms.append(term)
|
|
387
|
-
return terms
|
|
388
|
-
else:
|
|
389
|
-
raise Exception(
|
|
390
|
-
"There are currently no terms in this problem. \
|
|
391
|
-
Please download the problem on the client or add terms to the \
|
|
392
|
-
problem to perform this operation"
|
|
393
|
-
)
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
# coding=utf-8
|
|
2
|
-
##
|
|
3
|
-
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
-
# Licensed under the MIT License.
|
|
5
|
-
##
|
|
6
|
-
import warnings
|
|
7
|
-
warnings.warn("The azure.quantum.optimization.solvers namespace will be deprecated. \
|
|
8
|
-
Please use azure.quantum.target instead.")
|
|
9
|
-
|
|
10
|
-
from azure.quantum.target.solvers import Solver
|