azure-quantum 3.1.1.dev2__tar.gz → 3.3.0__tar.gz

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.
Files changed (82) hide show
  1. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/PKG-INFO +2 -2
  2. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/_client/_version.py +1 -1
  3. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/job/job.py +2 -2
  4. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/target/__init__.py +0 -1
  5. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/target/rigetti/target.py +5 -0
  6. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/version.py +1 -1
  7. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure_quantum.egg-info/PKG-INFO +2 -2
  8. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure_quantum.egg-info/SOURCES.txt +0 -4
  9. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure_quantum.egg-info/requires.txt +1 -1
  10. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/requirements.txt +1 -1
  11. azure_quantum-3.1.1.dev2/azure/quantum/target/microsoft/elements/__init__.py +0 -1
  12. azure_quantum-3.1.1.dev2/azure/quantum/target/microsoft/elements/dft/__init__.py +0 -6
  13. azure_quantum-3.1.1.dev2/azure/quantum/target/microsoft/elements/dft/job.py +0 -171
  14. azure_quantum-3.1.1.dev2/azure/quantum/target/microsoft/elements/dft/target.py +0 -316
  15. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/README.md +0 -0
  16. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/__init__.py +0 -0
  17. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/_authentication/__init__.py +0 -0
  18. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/_authentication/_chained.py +0 -0
  19. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/_authentication/_default.py +0 -0
  20. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/_authentication/_token.py +0 -0
  21. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/_client/__init__.py +0 -0
  22. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/_client/_client.py +0 -0
  23. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/_client/_configuration.py +0 -0
  24. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/_client/_model_base.py +0 -0
  25. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/_client/_patch.py +0 -0
  26. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/_client/_serialization.py +0 -0
  27. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/_client/models/__init__.py +0 -0
  28. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/_client/models/_enums.py +0 -0
  29. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/_client/models/_models.py +0 -0
  30. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/_client/models/_patch.py +0 -0
  31. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/_client/operations/__init__.py +0 -0
  32. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/_client/operations/_operations.py +0 -0
  33. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/_client/operations/_patch.py +0 -0
  34. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/_constants.py +0 -0
  35. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/_workspace_connection_params.py +0 -0
  36. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/argument_types/__init__.py +0 -0
  37. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/argument_types/types.py +0 -0
  38. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/cirq/__init__.py +0 -0
  39. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/cirq/job.py +0 -0
  40. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/cirq/service.py +0 -0
  41. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/cirq/targets/__init__.py +0 -0
  42. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/cirq/targets/ionq.py +0 -0
  43. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/cirq/targets/quantinuum.py +0 -0
  44. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/cirq/targets/target.py +0 -0
  45. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/job/__init__.py +0 -0
  46. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/job/base_job.py +0 -0
  47. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/job/filtered_job.py +0 -0
  48. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/job/job_failed_with_results_error.py +0 -0
  49. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/job/session.py +0 -0
  50. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/job/workspace_item.py +0 -0
  51. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/job/workspace_item_factory.py +0 -0
  52. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/qiskit/__init__.py +0 -0
  53. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/qiskit/backends/__init__.py +0 -0
  54. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/qiskit/backends/backend.py +0 -0
  55. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/qiskit/backends/ionq.py +0 -0
  56. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/qiskit/backends/qci.py +0 -0
  57. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/qiskit/backends/quantinuum.py +0 -0
  58. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/qiskit/backends/rigetti.py +0 -0
  59. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/qiskit/job.py +0 -0
  60. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/qiskit/provider.py +0 -0
  61. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/storage.py +0 -0
  62. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/target/ionq.py +0 -0
  63. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/target/params.py +0 -0
  64. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/target/pasqal/__init__.py +0 -0
  65. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/target/pasqal/result.py +0 -0
  66. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/target/pasqal/target.py +0 -0
  67. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/target/quantinuum.py +0 -0
  68. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/target/rigetti/__init__.py +0 -0
  69. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/target/rigetti/result.py +0 -0
  70. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/target/target.py +0 -0
  71. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/target/target_factory.py +0 -0
  72. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure/quantum/workspace.py +0 -0
  73. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure_quantum.egg-info/dependency_links.txt +0 -0
  74. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/azure_quantum.egg-info/top_level.txt +0 -0
  75. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/requirements-cirq.txt +0 -0
  76. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/requirements-dev.txt +0 -0
  77. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/requirements-pulser.txt +0 -0
  78. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/requirements-qiskit.txt +0 -0
  79. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/requirements-qsharp.txt +0 -0
  80. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/requirements-quil.txt +0 -0
  81. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/setup.cfg +0 -0
  82. {azure_quantum-3.1.1.dev2 → azure_quantum-3.3.0}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: azure-quantum
3
- Version: 3.1.1.dev2
3
+ Version: 3.3.0
4
4
  Summary: Python client for Azure Quantum
5
5
  Home-page: https://github.com/microsoft/azure-quantum-python
6
6
  Author: Microsoft
@@ -14,7 +14,7 @@ Requires-Dist: azure-core<2.0,>=1.30
14
14
  Requires-Dist: azure-identity<2.0,>=1.17
15
15
  Requires-Dist: azure-storage-blob==12.20
16
16
  Requires-Dist: msrest<1.0,>=0.7.1
17
- Requires-Dist: numpy>=1.21.0
17
+ Requires-Dist: numpy<2.0,>=1.21.0
18
18
  Requires-Dist: deprecated<2.0,>=1.2.12
19
19
  Requires-Dist: Markdown>=3.4.1
20
20
  Requires-Dist: python-markdown-math>=0.8
@@ -6,4 +6,4 @@
6
6
  # Changes may cause incorrect behavior and will be lost if the code is regenerated.
7
7
  # --------------------------------------------------------------------------
8
8
 
9
- VERSION = "3.1.1.dev2"
9
+ VERSION = "3.3.0"
@@ -111,7 +111,7 @@ class Job(BaseJob, FilteredJob):
111
111
  Raises :class:`ValueError` if job output is malformed or output format is not compatible.
112
112
 
113
113
  Raises :class:`azure.quantum.job.JobFailedWithResultsError` if job execution fails,
114
- but failure results could still be retrieved (e.g. for jobs submitted against "microsoft.dft" target).
114
+ but failure results could still be retrieved.
115
115
 
116
116
  :param timeout_secs: Timeout in seconds, defaults to 300
117
117
  :type timeout_secs: float
@@ -274,7 +274,7 @@ class Job(BaseJob, FilteredJob):
274
274
  Raises :class:`ValueError` if job output is malformed or output format is not compatible.
275
275
 
276
276
  Raises :class:`azure.quantum.job.JobFailedWithResultsError` if job execution fails,
277
- but failure results could still be retrieved (e.g. for jobs submitted against "microsoft.dft" target).
277
+ but failure results could still be retrieved.
278
278
 
279
279
  :param timeout_secs: Timeout in seconds, defaults to 300
280
280
  :type timeout_secs: float
@@ -10,7 +10,6 @@ from .ionq import IonQ
10
10
  from .quantinuum import Quantinuum
11
11
  from .rigetti import Rigetti
12
12
  from .pasqal import Pasqal
13
- from .microsoft.elements.dft import MicrosoftElementsDft, MicrosoftElementsDftJob
14
13
 
15
14
  # Default targets to use when there is no target class
16
15
  # associated with a given target ID
@@ -32,6 +32,8 @@ class RigettiTarget(str, Enum):
32
32
 
33
33
  ANKAA_3 = "rigetti.qpu.ankaa-3"
34
34
 
35
+ CEPHEUS_1_36Q = "rigetti.qpu.cepheus-1-36q"
36
+
35
37
  def simulators() -> List[str]:
36
38
  """Returns a list of simulator targets"""
37
39
  return [
@@ -42,6 +44,7 @@ class RigettiTarget(str, Enum):
42
44
  """Returns a list of QPU targets"""
43
45
  return [
44
46
  RigettiTarget.ANKAA_3.value,
47
+ RigettiTarget.CEPHEUS_1_36Q
45
48
  ]
46
49
 
47
50
  def num_qubits(target_name) -> int:
@@ -51,6 +54,8 @@ class RigettiTarget(str, Enum):
51
54
  return 20
52
55
  elif target_name == RigettiTarget.ANKAA_3.value:
53
56
  return 84
57
+ elif target_name == RigettiTarget.CEPHEUS_1_36Q.value:
58
+ return 36
54
59
  else:
55
60
  raise ValueError(f"Unknown target {target_name}")
56
61
 
@@ -5,4 +5,4 @@
5
5
  # Copyright (c) Microsoft Corporation. All rights reserved.
6
6
  # Licensed under the MIT License.
7
7
  ##
8
- __version__ = "3.1.1.dev2"
8
+ __version__ = "3.3.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: azure-quantum
3
- Version: 3.1.1.dev2
3
+ Version: 3.3.0
4
4
  Summary: Python client for Azure Quantum
5
5
  Home-page: https://github.com/microsoft/azure-quantum-python
6
6
  Author: Microsoft
@@ -14,7 +14,7 @@ Requires-Dist: azure-core<2.0,>=1.30
14
14
  Requires-Dist: azure-identity<2.0,>=1.17
15
15
  Requires-Dist: azure-storage-blob==12.20
16
16
  Requires-Dist: msrest<1.0,>=0.7.1
17
- Requires-Dist: numpy>=1.21.0
17
+ Requires-Dist: numpy<2.0,>=1.21.0
18
18
  Requires-Dist: deprecated<2.0,>=1.2.12
19
19
  Requires-Dist: Markdown>=3.4.1
20
20
  Requires-Dist: python-markdown-math>=0.8
@@ -63,10 +63,6 @@ azure/quantum/target/params.py
63
63
  azure/quantum/target/quantinuum.py
64
64
  azure/quantum/target/target.py
65
65
  azure/quantum/target/target_factory.py
66
- azure/quantum/target/microsoft/elements/__init__.py
67
- azure/quantum/target/microsoft/elements/dft/__init__.py
68
- azure/quantum/target/microsoft/elements/dft/job.py
69
- azure/quantum/target/microsoft/elements/dft/target.py
70
66
  azure/quantum/target/pasqal/__init__.py
71
67
  azure/quantum/target/pasqal/result.py
72
68
  azure/quantum/target/pasqal/target.py
@@ -2,7 +2,7 @@ azure-core<2.0,>=1.30
2
2
  azure-identity<2.0,>=1.17
3
3
  azure-storage-blob==12.20
4
4
  msrest<1.0,>=0.7.1
5
- numpy>=1.21.0
5
+ numpy<2.0,>=1.21.0
6
6
  deprecated<2.0,>=1.2.12
7
7
  Markdown>=3.4.1
8
8
  python-markdown-math>=0.8
@@ -4,7 +4,7 @@ azure-identity>=1.17,<2.0
4
4
  # More than one match for "https://mystorage.blob.core.windows.net/.../rawOutputData"
5
5
  azure-storage-blob==12.20
6
6
  msrest>=0.7.1,<1.0
7
- numpy>=1.21.0
7
+ numpy>=1.21.0,<2.0
8
8
  deprecated>=1.2.12,<2.0
9
9
  Markdown>=3.4.1
10
10
  python-markdown-math>=0.8
@@ -1 +0,0 @@
1
- """Defines classes for interacting with Microsoft Elements services"""
@@ -1,6 +0,0 @@
1
- """Defines classes for interacting with Microsoft Elements DFT service"""
2
-
3
- from .target import MicrosoftElementsDft
4
- from .job import MicrosoftElementsDftJob
5
-
6
- __all__ = ["MicrosoftElementsDft", "MicrosoftElementsDftJob"]
@@ -1,171 +0,0 @@
1
- import collections.abc
2
- import logging
3
- from typing import Any, Dict, Union, Optional
4
- from azure.quantum.job import JobFailedWithResultsError
5
- from azure.quantum.job.base_job import BaseJob, ContentType
6
- from azure.quantum.job.job import Job, DEFAULT_TIMEOUT
7
- from azure.quantum._client.models import JobDetails
8
- from azure.quantum.workspace import Workspace
9
-
10
- logger = logging.getLogger(__name__)
11
-
12
- class MicrosoftElementsDftJob(Job):
13
- """
14
- A dedicated job class for jobs from the microsoft.dft target.
15
- """
16
-
17
- def __init__(self, workspace, job_details: JobDetails, **kwargs):
18
- """Azure Quantum Job that is submitted to a given Workspace.
19
-
20
- :param workspace: Workspace instance to submit job to
21
- :type workspace: Workspace
22
- :param job_details: Job details model,
23
- contains Job ID, name and other details
24
- :type job_details: JobDetails
25
- """
26
- super().__init__(workspace, job_details, **kwargs)
27
-
28
-
29
- def get_results(self, timeout_secs: float = DEFAULT_TIMEOUT) -> Dict[str, Any]:
30
- """Get job results by downloading the results blob from the
31
- storage container linked via the workspace.
32
-
33
- :param timeout_secs: Timeout in seconds, defaults to 300
34
- :type timeout_secs: float
35
- :raises: :class:`RuntimeError` if job execution failed.
36
- :raises: :class:`azure.quantum.job.JobFailedWithResultsError` if job execution failed,
37
- but failure results could still be retrieved.
38
- :return: Results dictionary.
39
- """
40
-
41
- try:
42
- job_results = super().get_results(timeout_secs)
43
- return job_results
44
- except JobFailedWithResultsError as e:
45
- failure_results = e.get_failure_results()
46
- if MicrosoftElementsDftJob._is_dft_failure_results(failure_results):
47
- error = failure_results["results"][0]["error"]
48
- message = f'{e.get_message()} Error type: {error["error_type"]}. Message: {error["error_message"]}'
49
- raise JobFailedWithResultsError(message, failure_results) from None
50
-
51
-
52
- @classmethod
53
- def _allow_failure_results(cls) -> bool:
54
- """
55
- Allow to download job results even if the Job status is "Failed".
56
- """
57
- return True
58
-
59
-
60
- @staticmethod
61
- def _is_dft_failure_results(failure_results: Union[Dict[str, Any], str]) -> bool:
62
- return isinstance(failure_results, dict) \
63
- and "results" in failure_results \
64
- and isinstance(failure_results["results"], collections.abc.Sequence) \
65
- and len(failure_results["results"]) > 0 \
66
- and isinstance(failure_results["results"][0], dict) \
67
- and "error" in failure_results["results"][0] \
68
- and isinstance(failure_results["results"][0]["error"], dict) \
69
- and "error_type" in failure_results["results"][0]["error"] \
70
- and "error_message" in failure_results["results"][0]["error"]
71
-
72
- @classmethod
73
- def from_input_data_container(
74
- cls,
75
- workspace: "Workspace",
76
- name: str,
77
- target: str,
78
- input_data: bytes,
79
- batch_input_blobs: Dict[str, bytes],
80
- content_type: ContentType = ContentType.json,
81
- blob_name: str = "inputData",
82
- encoding: str = "",
83
- job_id: str = None,
84
- container_name: str = None,
85
- provider_id: str = None,
86
- input_data_format: str = None,
87
- output_data_format: str = None,
88
- input_params: Dict[str, Any] = None,
89
- session_id: Optional[str] = None,
90
- **kwargs
91
- ) -> "BaseJob":
92
- """Create a new Azure Quantum job based on a list of input_data.
93
-
94
- :param workspace: Azure Quantum workspace to submit the input_data to
95
- :type workspace: Workspace
96
- :param name: Name of the job
97
- :type name: str
98
- :param target: Azure Quantum target
99
- :type target: str
100
- :param input_data: Raw input data to submit
101
- :type input_data: Dict
102
- :param blob_name: Dict of Input data json to gives a table of contents
103
- :type batch_input_blobs: Dict
104
- :param blob_name: Dict of QcSchema Data where the key is the blob name to store it in the container
105
- :type blob_name: str
106
- :param content_type: Content type, e.g. "application/json"
107
- :type content_type: ContentType
108
- :param encoding: input_data encoding, e.g. "gzip", defaults to empty string
109
- :type encoding: str
110
- :param job_id: Job ID, defaults to None
111
- :type job_id: str
112
- :param container_name: Container name, defaults to None
113
- :type container_name: str
114
- :param provider_id: Provider ID, defaults to None
115
- :type provider_id: str
116
- :param input_data_format: Input data format, defaults to None
117
- :type input_data_format: str
118
- :param output_data_format: Output data format, defaults to None
119
- :type output_data_format: str
120
- :param input_params: Input parameters, defaults to None
121
- :type input_params: Dict[str, Any]
122
- :param input_params: Input params for job
123
- :type input_params: Dict[str, Any]
124
- :return: Azure Quantum Job
125
- :rtype: Job
126
- """
127
- # Generate job ID if not specified
128
- if job_id is None:
129
- job_id = cls.create_job_id()
130
-
131
- # Create container if it does not yet exist
132
- container_uri = workspace.get_container_uri(
133
- job_id=job_id,
134
- container_name=container_name
135
- )
136
- logger.debug(f"Container URI: {container_uri}")
137
-
138
- # Upload Input Data
139
- input_data_uri = cls.upload_input_data(
140
- container_uri=container_uri,
141
- input_data=input_data,
142
- content_type=content_type,
143
- blob_name=blob_name,
144
- encoding=encoding,
145
- )
146
-
147
- # Upload data to container
148
- for blob_name, input_data_item in batch_input_blobs.items():
149
- cls.upload_input_data(
150
- container_uri=container_uri,
151
- input_data=input_data_item,
152
- content_type=content_type,
153
- blob_name=blob_name,
154
- encoding=encoding,
155
- )
156
-
157
- # Create and submit job
158
- return cls.from_storage_uri(
159
- workspace=workspace,
160
- job_id=job_id,
161
- target=target,
162
- input_data_uri=input_data_uri,
163
- container_uri=container_uri,
164
- name=name,
165
- input_data_format=input_data_format,
166
- output_data_format=output_data_format,
167
- provider_id=provider_id,
168
- input_params=input_params,
169
- session_id=session_id,
170
- **kwargs
171
- )
@@ -1,316 +0,0 @@
1
- import warnings
2
-
3
- from azure.quantum.job.base_job import ContentType
4
- from azure.quantum.job.job import Job
5
- from azure.quantum.target.target import Target
6
- from azure.quantum.workspace import Workspace
7
- from azure.quantum.target.params import InputParams
8
- from typing import Any, Dict, Type, Union, List
9
- from .job import MicrosoftElementsDftJob
10
- from pathlib import Path
11
- import copy
12
- import json
13
- from collections import defaultdict
14
-
15
-
16
- class MicrosoftElementsDft(Target):
17
- """
18
- Microsoft Elements Dft target from the microsoft-elements provider.
19
- """
20
-
21
- target_names = [
22
- "microsoft.dft"
23
- ]
24
-
25
-
26
- def __init__(
27
- self,
28
- workspace: "Workspace",
29
- name: str = "microsoft.dft",
30
- **kwargs
31
- ):
32
- """
33
- Initializes a new DFT target.
34
-
35
- :param workspace: Associated workspace
36
- :type workspace: Workspace
37
- :param name: Target name
38
- """
39
- # There is only a single target name for this target
40
- assert name == self.target_names[0]
41
-
42
- # make sure to not pass argument twice
43
- kwargs.pop("provider_id", None)
44
-
45
- super().__init__(
46
- workspace=workspace,
47
- name=name,
48
- input_data_format="microsoft.xyz.v1",
49
- output_data_format="microsoft.dft-results.v1",
50
- provider_id="microsoft-elements",
51
- content_type=ContentType.text_plain,
52
- **kwargs
53
- )
54
-
55
-
56
- def submit(self,
57
- input_data: Any,
58
- name: str = "azure-quantum-dft-job",
59
- shots: int = None,
60
- input_params: Union[Dict[str, Any], InputParams, None] = None,
61
- **kwargs) -> MicrosoftElementsDftJob:
62
- """
63
- Submit DFT job to Azure Quantum Services.
64
-
65
- :param input_data: Input data
66
- :type input_data: Any
67
- :param name: Job name
68
- :type name: str
69
- :param shots: Number of shots. Ignored in DFT job. Defaults to None
70
- :type shots: int
71
- :param input_params: Input parameters
72
- :type input_params: Dict[str, Any]
73
- :return: Azure Quantum job
74
- :rtype: Job
75
- """
76
-
77
- if shots is not None:
78
- warnings.warn("The 'shots' parameter is ignored in Microsoft Elements Dft job.")
79
-
80
- if isinstance(input_data, list):
81
-
82
- if len(input_data) < 1:
83
- raise ValueError("Input data list has no elements.")
84
-
85
- if all(isinstance(task,str) for task in input_data):
86
- qcschema_data = self.assemble_qcschema_from_files(input_data, input_params)
87
-
88
- qcschema_blobs = {}
89
- for i in range(len(qcschema_data)):
90
- qcschema_blobs[f"inputData_{i}"] = self._encode_input_data(qcschema_data[i])
91
-
92
- toc_str = self._create_table_of_contents(input_data, list(qcschema_blobs.keys()))
93
- elif all(isinstance(task,dict) for task in input_data):
94
- qcschema_blobs = {}
95
- for i in range(len(input_data)):
96
- qcschema_blobs[f"inputData_{i}"] = self._encode_input_data(input_data[i])
97
- toc_str = '{"description": "QcSchema Objects were given for input."}'
98
- else:
99
- raise ValueError(f"Unsupported batch submission. Please use List[str] or List[dict].")
100
- toc = self._encode_input_data(toc_str)
101
-
102
- input_params = {} if input_params is None else input_params
103
- return self._get_job_class().from_input_data_container(
104
- workspace=self.workspace,
105
- name=name,
106
- target=self.name,
107
- input_data=toc,
108
- batch_input_blobs=qcschema_blobs,
109
- input_params={ 'numberOfFiles': len(input_data), "inputFiles": list(qcschema_blobs.keys()), **input_params },
110
- content_type=kwargs.pop('content_type', self.content_type),
111
- encoding=kwargs.pop('encoding', self.encoding),
112
- provider_id=self.provider_id,
113
- input_data_format=kwargs.pop('input_data_format', 'microsoft.qc-schema.v1'),
114
- output_data_format=kwargs.pop('output_data_format', self.output_data_format),
115
- session_id=self.get_latest_session_id(),
116
- **kwargs
117
- )
118
- else:
119
- return super().submit(
120
- input_data=input_data,
121
- name=name,
122
- shots=shots,
123
- input_params=input_params,
124
- **kwargs
125
- )
126
-
127
-
128
-
129
- @classmethod
130
- def assemble_qcschema_from_files(self, input_data: Union[List[str]], input_params: Dict) -> List[Dict]:
131
- """
132
- Convert a list of files to a list of QcSchema objects that are ready for submission.
133
-
134
- :param input_data: Input data
135
- :type input_data: List[str]
136
- :param input_params: Input parameters
137
- :type input_params: Dict[str, Any]
138
- :rtype: List[Dict]
139
- """
140
-
141
- self._check_file_paths(input_data)
142
-
143
- qcshema_objects = []
144
- for file in input_data:
145
- file_path = Path(file)
146
-
147
- file_data = file_path.read_text()
148
- if file_path.suffix == '.xyz':
149
- mol = self._xyz_to_qcschema_mol(file_data)
150
- new_qcschema = self._new_qcshema( input_params, mol )
151
- qcshema_objects.append(new_qcschema)
152
- elif file_path.suffix == '.json':
153
- if input_params is not None and len(input_params.keys()) > 0:
154
- warnings.warn('Input parameters were given along with a QcSchema file which contains parameters, using QcSchema parameters as is.')
155
- with open(file_path, 'r') as f:
156
- qcshema_objects.append( json.load(f) )
157
- else:
158
- raise ValueError(f"File type '{file_path.suffix}' for file '{file_path}' is not supported.")
159
-
160
- return qcshema_objects
161
-
162
- @classmethod
163
- def _check_file_paths( self, input_data: List[str]):
164
- """Check the file types and make sure they are supported by our parsers."""
165
-
166
- warn_task_count = 1000
167
- if len(input_data) >= warn_task_count:
168
- warnings.warn(f'Number of tasks is greater than {warn_task_count}.')
169
-
170
- supported_ext = ['.xyz', '.json']
171
- prev_ext = None
172
- for path_str in input_data:
173
- path = Path(path_str)
174
-
175
- if not path.exists():
176
- raise FileNotFoundError(f"File {path_str} does not exist.")
177
-
178
- if path.suffix not in supported_ext:
179
- raise ValueError(f"'{path.suffix}' file type is not supported. Please use one of {supported_ext}.")
180
-
181
- if prev_ext is not None and prev_ext != path.suffix:
182
- raise ValueError(f"Multiple file types were provided ('{path.suffix}', '{prev_ext}'). Please submit only one file type.")
183
- else:
184
- prev_ext = path.suffix
185
-
186
-
187
- @classmethod
188
- def _new_qcshema( self, input_params: Dict[str,Any], mol: Dict[str,Any], ) -> Dict[str, Any]:
189
- """
190
- Create a new default qcshema object.
191
- """
192
-
193
- self._sanity_check_params(input_params, mol)
194
-
195
- if input_params.get("driver").lower() == "go":
196
- copy_input_params = copy.deepcopy(input_params)
197
- copy_input_params["driver"] = "gradient"
198
- new_object = {
199
- "schema_name": "qcschema_optimization_input",
200
- "schema_version": 1,
201
- "initial_molecule": mol,
202
- }
203
- if copy_input_params.get("go_keywords"):
204
- new_object["keywords"] = copy_input_params.pop("go_keywords")
205
- new_object["input_specification"] = copy_input_params
206
- return new_object
207
- elif input_params.get("driver").lower() == "bomd":
208
- copy_input_params = copy.deepcopy(input_params)
209
- copy_input_params["driver"] = "gradient"
210
- new_object = {
211
- "schema_name": "madft_molecular_dynamics_input",
212
- "schema_version": 1,
213
- "initial_molecule": mol,
214
- }
215
- if copy_input_params.get("bomd_keywords"):
216
- new_object["keywords"] = copy_input_params.pop("bomd_keywords")
217
- new_object["input_specification"] = copy_input_params
218
- return new_object
219
- else:
220
- new_object = copy.deepcopy(input_params)
221
- new_object.update({
222
- "schema_name": "qcschema_input",
223
- "schema_version": 1,
224
- "molecule": mol,
225
- })
226
- return new_object
227
-
228
- @classmethod
229
- def _sanity_check_params(self, input_params, mol):
230
-
231
- # QM/MM is not supported for GO, BOMD and Hessian.
232
- driver = input_params.get("driver",'').lower()
233
- if driver in ["go", "bomd", "hessian"]:
234
- if "extras" in mol and "mm_charges" in mol["extras"]:
235
- raise ValueError(f"'{driver}' does not support QM/MM.")
236
-
237
- # Top level params
238
- self._check_dict_for_required_keys(input_params, 'input_params', ['driver', 'model'])
239
-
240
- # Check Model params
241
- self._check_dict_for_required_keys(input_params['model'], 'input_params["model"]', ['method', 'basis'])
242
-
243
-
244
- @classmethod
245
- def _check_dict_for_required_keys(self, input_params: dict, dict_name: str, required_keys: list[str]):
246
- """Check dictionary for required keys and if it doesn't have then raise ValueError."""
247
-
248
- for required_key in required_keys:
249
- if required_key not in input_params.keys():
250
- raise ValueError(f"Required key ({required_key}) was not provided in {dict_name}.")
251
-
252
- @classmethod
253
- def _xyz_to_qcschema_mol(self, file_data: str ) -> Dict[str, Any]:
254
- """
255
- Convert xyz format to qcschema molecule.
256
- """
257
-
258
- lines = file_data.split("\n")
259
- if len(lines) < 3 or not lines[0]:
260
- raise ValueError("Invalid xyz format.")
261
- n_atoms = int(lines.pop(0))
262
- comment = lines.pop(0)
263
- mol = defaultdict(list)
264
- mol['extras'] = defaultdict(list)
265
- bohr_to_angstrom = 0.52917721092
266
- for line in lines:
267
- if line:
268
- elements = line.split()
269
- if len(elements) == 4:
270
- symbol, x, y, z = elements
271
- mol["symbols"].append(symbol)
272
- mol["geometry"] += [float(x)/bohr_to_angstrom, float(y)/bohr_to_angstrom, float(z)/bohr_to_angstrom]
273
- elif len(elements) == 5:
274
- symbol, x, y, z, q = elements
275
- if symbol[0] != '-':
276
- raise ValueError("Invalid xyz format. Molecular Mechanics atoms requires '-' at the beginning of the atom type.")
277
- mol["extras"]["mm_symbols"].append(symbol.replace('-', ''))
278
- mol["extras"]["mm_geometry"] += [float(x)/bohr_to_angstrom, float(y)/bohr_to_angstrom, float(z)/bohr_to_angstrom]
279
- mol["extras"]["mm_charges"].append(float(q))
280
- else:
281
- raise ValueError("Invalid xyz format.")
282
- else:
283
- break
284
-
285
- # Convert defaultdict to dict
286
- mol = dict(mol)
287
- mol["extras"] = dict(mol["extras"])
288
-
289
- if len(mol["symbols"])+len(mol["extras"].get("mm_symbols",[])) != n_atoms:
290
- raise ValueError("Number of inputs does not match the number of atoms in xyz file.")
291
-
292
- return mol
293
-
294
- @classmethod
295
- def _get_job_class(cls) -> Type[Job]:
296
- return MicrosoftElementsDftJob
297
-
298
- @classmethod
299
- def _create_table_of_contents(cls, input_files: List[str], input_blobs: List[str]) -> Dict[str,Any]:
300
- """Create the table of contents for a batched job that contains a description of file and the mapping between the file names and the blob names"""
301
-
302
- assert len(input_files) == len(input_blobs), "Internal error: number of blobs is not that same as the number of files."
303
-
304
- toc = []
305
- for i in range(len(input_files)):
306
- toc.append(
307
- {
308
- "inputFileName": input_files[i],
309
- "qcschemaBlobName": input_blobs[i],
310
- }
311
- )
312
-
313
- return {
314
- "description": "This files contains the mapping between the xyz file name that were submitted and the qcschema blobs that are used for the calculation.",
315
- "tableOfContents": toc,
316
- }