quapp-braket 0.0.10.dev1__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 (33) hide show
  1. quapp_braket-0.0.10.dev1/LICENSE +8 -0
  2. quapp_braket-0.0.10.dev1/PKG-INFO +38 -0
  3. quapp_braket-0.0.10.dev1/README.md +3 -0
  4. quapp_braket-0.0.10.dev1/pyproject.toml +32 -0
  5. quapp_braket-0.0.10.dev1/qapp_braket/__init__.py +1 -0
  6. quapp_braket-0.0.10.dev1/qapp_braket/async_tasks/__init__.py +0 -0
  7. quapp_braket-0.0.10.dev1/qapp_braket/async_tasks/braket_circuit_export_task.py +22 -0
  8. quapp_braket-0.0.10.dev1/qapp_braket/component/__init__.py +0 -0
  9. quapp_braket-0.0.10.dev1/qapp_braket/component/backend/__init__.py +0 -0
  10. quapp_braket-0.0.10.dev1/qapp_braket/component/backend/braket_invocation.py +61 -0
  11. quapp_braket-0.0.10.dev1/qapp_braket/factory/__init__.py +0 -0
  12. quapp_braket-0.0.10.dev1/qapp_braket/factory/braket_device_factory.py +41 -0
  13. quapp_braket-0.0.10.dev1/qapp_braket/factory/braket_handler_factory.py +25 -0
  14. quapp_braket-0.0.10.dev1/qapp_braket/factory/braket_provider_factory.py +40 -0
  15. quapp_braket-0.0.10.dev1/qapp_braket/handler/__init__.py +0 -0
  16. quapp_braket-0.0.10.dev1/qapp_braket/handler/invocation_handler.py +27 -0
  17. quapp_braket-0.0.10.dev1/qapp_braket/model/__init__.py +0 -0
  18. quapp_braket-0.0.10.dev1/qapp_braket/model/device/__init__.py +0 -0
  19. quapp_braket-0.0.10.dev1/qapp_braket/model/device/aws_braket_device.py +109 -0
  20. quapp_braket-0.0.10.dev1/qapp_braket/model/device/oqc_cloud_device.py +102 -0
  21. quapp_braket-0.0.10.dev1/qapp_braket/model/device/qapp_braket_device.py +85 -0
  22. quapp_braket-0.0.10.dev1/qapp_braket/model/provider/__init__.py +0 -0
  23. quapp_braket-0.0.10.dev1/qapp_braket/model/provider/aws_braket_provider.py +37 -0
  24. quapp_braket-0.0.10.dev1/qapp_braket/model/provider/oqc_cloud_provider.py +25 -0
  25. quapp_braket-0.0.10.dev1/qapp_braket/model/provider/qapp_braket_provider.py +31 -0
  26. quapp_braket-0.0.10.dev1/qapp_braket/util/__init__.py +0 -0
  27. quapp_braket-0.0.10.dev1/qapp_braket/util/circuit_convert_utils.py +32 -0
  28. quapp_braket-0.0.10.dev1/quapp_braket.egg-info/PKG-INFO +38 -0
  29. quapp_braket-0.0.10.dev1/quapp_braket.egg-info/SOURCES.txt +31 -0
  30. quapp_braket-0.0.10.dev1/quapp_braket.egg-info/dependency_links.txt +1 -0
  31. quapp_braket-0.0.10.dev1/quapp_braket.egg-info/requires.txt +13 -0
  32. quapp_braket-0.0.10.dev1/quapp_braket.egg-info/top_level.txt +1 -0
  33. quapp_braket-0.0.10.dev1/setup.cfg +4 -0
@@ -0,0 +1,8 @@
1
+ The MIT License (MIT)
2
+ Copyright © CITYNOW Co. Ltd. All rights reserved.
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ Metadata-Version: 2.4
2
+ Name: quapp-braket
3
+ Version: 0.0.10.dev1
4
+ Summary: Quapp braket library supporting Quapp Platform for Quantum Computing
5
+ Author-email: "CITYNOW Co. Ltd. " <corp@citynow.vn>
6
+ License: The MIT License (MIT)
7
+ Copyright © CITYNOW Co. Ltd. All rights reserved.
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
14
+ Project-URL: Homepage, https://citynow.asia/
15
+ Keywords: quapp,quapp-braket,braket,quantum
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Programming Language :: Python
18
+ Classifier: Programming Language :: Python :: 3
19
+ Requires-Python: >=3.7
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: quapp-common==0.0.10.dev1
23
+ Requires-Dist: amazon-braket-sdk==1.83.0
24
+ Requires-Dist: oqc-qcaas-client==3.7.0
25
+ Requires-Dist: qiskit
26
+ Requires-Dist: pytket
27
+ Requires-Dist: pytket-braket
28
+ Provides-Extra: dev
29
+ Requires-Dist: black; extra == "dev"
30
+ Requires-Dist: bumpver; extra == "dev"
31
+ Requires-Dist: isort; extra == "dev"
32
+ Requires-Dist: pip-tools; extra == "dev"
33
+ Requires-Dist: pytest; extra == "dev"
34
+ Dynamic: license-file
35
+
36
+ # qapp-braket
37
+
38
+ qapp-braket
@@ -0,0 +1,3 @@
1
+ # qapp-braket
2
+
3
+ qapp-braket
@@ -0,0 +1,32 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "quapp-braket"
7
+ version = "0.0.10.dev1"
8
+ description = "Quapp braket library supporting Quapp Platform for Quantum Computing"
9
+ readme = "README.md"
10
+ authors = [{ name = "CITYNOW Co. Ltd. ", email = "corp@citynow.vn" }]
11
+ license = { file = "LICENSE" }
12
+ classifiers = [
13
+ "License :: OSI Approved :: MIT License",
14
+ "Programming Language :: Python",
15
+ "Programming Language :: Python :: 3",
16
+ ]
17
+ keywords = ["quapp", "quapp-braket", "braket", "quantum"]
18
+ dependencies = [
19
+ "quapp-common==0.0.10.dev1",
20
+ "amazon-braket-sdk==1.83.0",
21
+ "oqc-qcaas-client==3.7.0",
22
+ "qiskit",
23
+ "pytket",
24
+ "pytket-braket"
25
+ ]
26
+ requires-python = ">=3.7"
27
+
28
+ [project.optional-dependencies]
29
+ dev = ["black", "bumpver", "isort", "pip-tools", "pytest"]
30
+
31
+ [project.urls]
32
+ Homepage = "https://citynow.asia/"
@@ -0,0 +1 @@
1
+ from .factory.braket_handler_factory import BraketHandlerFactory
@@ -0,0 +1,22 @@
1
+ """
2
+ QApp Platform Project braket_circuit_export_task.py Copyright © CITYNOW Co. Ltd. All rights reserved.
3
+ """
4
+ from braket.circuits import Circuit
5
+
6
+ from qapp_common.async_tasks.export_circuit_task import CircuitExportTask
7
+ from qapp_common.config.logging_config import logger
8
+
9
+ from qapp_braket.util.circuit_convert_utils import CircuitConvertUtils
10
+
11
+
12
+ class BraketCircuitExportTask(CircuitExportTask):
13
+
14
+ def _transpile_circuit(self):
15
+ logger.debug("[BraketCircuitExportTask] _transpile_circuit()")
16
+
17
+ circuit = self.circuit_data_holder.circuit
18
+
19
+ if isinstance(circuit, Circuit):
20
+ return CircuitConvertUtils.braket_to_qiskit(circuit)
21
+
22
+ raise Exception("Invalid circuit type!")
@@ -0,0 +1,61 @@
1
+ """
2
+ QApp Platform Project braket_invocation.py Copyright © CITYNOW Co. Ltd. All rights reserved.
3
+ """
4
+ from braket.circuits import Circuit
5
+
6
+ from qapp_common.component.backend.invocation import Invocation
7
+ from qapp_common.data.async_task.circuit_export.backend_holder import BackendDataHolder
8
+ from qapp_common.data.async_task.circuit_export.circuit_holder import CircuitDataHolder
9
+ from qapp_common.data.request.invocation_request import InvocationRequest
10
+ from qapp_common.model.provider.provider import Provider
11
+ from qapp_common.config.logging_config import logger
12
+ from qapp_common.config.thread_config import circuit_exporting_pool
13
+
14
+ from ...factory.braket_provider_factory import BraketProviderFactory
15
+ from ...factory.braket_device_factory import BraketDeviceFactory
16
+ from ...async_tasks.braket_circuit_export_task import BraketCircuitExportTask
17
+
18
+
19
+ class BraketInvocation(Invocation):
20
+
21
+ def __init__(self, request_data: InvocationRequest):
22
+ super().__init__(request_data)
23
+
24
+ def _export_circuit(self, circuit):
25
+ logger.info("[BraketInvocation] _export_circuit()")
26
+
27
+ circuit_export_task = BraketCircuitExportTask(
28
+ circuit_data_holder=CircuitDataHolder(circuit, self.circuit_export_url),
29
+ backend_data_holder=BackendDataHolder(
30
+ self.backend_information, self.authentication.user_token
31
+ ),
32
+ )
33
+
34
+ circuit_exporting_pool.submit(circuit_export_task.do)
35
+
36
+ def _create_provider(self):
37
+ logger.info("[BraketInvocation] _create_provider()")
38
+
39
+ return BraketProviderFactory.create_provider(
40
+ provider_type=self.backend_information.provider_tag,
41
+ sdk=self.sdk,
42
+ authentication=self.backend_information.authentication,
43
+ )
44
+
45
+ def _create_device(self, provider: Provider):
46
+ logger.info("[BraketInvocation] _create_device()")
47
+
48
+ return BraketDeviceFactory.create_device(
49
+ provider=provider,
50
+ device_specification=self.backend_information.device_name,
51
+ authentication=self.backend_information.authentication,
52
+ sdk=self.sdk,
53
+ )
54
+
55
+ def _get_qubit_amount(self, circuit):
56
+ logger.info("[BraketInvocation] _get_qubit_amount()")
57
+
58
+ if isinstance(circuit, Circuit):
59
+ return circuit.qubit_count
60
+
61
+ raise Exception("Invalid circuit type!")
@@ -0,0 +1,41 @@
1
+ """
2
+ QApp Platform Project braket_device_factory.py Copyright © CITYNOW Co. Ltd. All rights reserved.
3
+ """
4
+ from qapp_common.enum.provider_tag import ProviderTag
5
+ from qapp_common.enum.sdk import Sdk
6
+ from qapp_common.factory.device_factory import DeviceFactory
7
+ from qapp_common.model.provider.provider import Provider
8
+ from qapp_common.config.logging_config import logger
9
+
10
+ from qapp_braket.model.device.aws_braket_device import AwsBraketDevice
11
+ from qapp_braket.model.device.oqc_cloud_device import OqcCloudDevice
12
+ from qapp_braket.model.device.qapp_braket_device import QappBraketDevice
13
+
14
+
15
+ class BraketDeviceFactory(DeviceFactory):
16
+
17
+ @staticmethod
18
+ def create_device(provider: Provider, device_specification: str, authentication: dict, sdk: Sdk):
19
+ logger.info("[BraketDeviceFactory] create_device()")
20
+
21
+ provider_type = ProviderTag.resolve(provider.get_provider_type().value)
22
+
23
+ if ProviderTag.QUAO_QUANTUM_SIMULATOR.__eq__(provider_type) and Sdk.BRAKET.__eq__(sdk):
24
+ logger.debug("[BraketDeviceFactory] Create QappBraketDevice")
25
+
26
+ return QappBraketDevice(provider, device_specification)
27
+
28
+ if ProviderTag.AWS_BRAKET.__eq__(provider_type):
29
+ logger.debug("[BraketDeviceFactory] Create QappBraketDevice")
30
+
31
+ return AwsBraketDevice(
32
+ provider,
33
+ device_specification,
34
+ authentication.get("bucketName"),
35
+ authentication.get("prefix"),
36
+ )
37
+
38
+ if ProviderTag.OQC_CLOUD.__eq__(provider_type):
39
+ return OqcCloudDevice(provider, device_specification)
40
+
41
+ raise Exception("Unsupported device!")
@@ -0,0 +1,25 @@
1
+ """
2
+ QApp Platform Project braket_handler_factory.py Copyright © CITYNOW Co. Ltd. All rights reserved.
3
+ """
4
+
5
+ from qapp_common.config.logging_config import logger
6
+ from qapp_common.factory.handler_factory import HandlerFactory
7
+ from qapp_common.handler.handler import Handler
8
+
9
+ from ..handler.invocation_handler import InvocationHandler
10
+
11
+
12
+ class BraketHandlerFactory(HandlerFactory):
13
+
14
+ @staticmethod
15
+ def create_handler(event, circuit_preparation_fn, post_processing_fn) -> Handler:
16
+ logger.info("[BraketHandlerFactory] create_handler()")
17
+
18
+ request_data = event.json()
19
+
20
+ logger.debug("[BraketHandlerFactory] Create InvocationHandler")
21
+ return InvocationHandler(
22
+ request_data=request_data,
23
+ circuit_preparation_fn=circuit_preparation_fn,
24
+ post_processing_fn=post_processing_fn,
25
+ )
@@ -0,0 +1,40 @@
1
+ """
2
+ QApp Platform Project braket_provider_factory.py Copyright © CITYNOW Co. Ltd. All rights reserved.
3
+ """
4
+ from qapp_common.enum.provider_tag import ProviderTag
5
+ from qapp_common.enum.sdk import Sdk
6
+ from qapp_common.factory.provider_factory import ProviderFactory
7
+ from qapp_common.config.logging_config import logger
8
+
9
+ from ..model.provider.aws_braket_provider import AwsBraketProvider
10
+ from ..model.provider.oqc_cloud_provider import OqcCloudProvider
11
+ from ..model.provider.qapp_braket_provider import QappBraketProvider
12
+
13
+
14
+ class BraketProviderFactory(ProviderFactory):
15
+
16
+ @staticmethod
17
+ def create_provider(provider_type: ProviderTag, sdk: Sdk, authentication: dict):
18
+ logger.info("[BraketProviderFactory] create_provider()")
19
+
20
+ if ProviderTag.QUAO_QUANTUM_SIMULATOR.__eq__(provider_type) and Sdk.BRAKET.__eq__(sdk):
21
+ logger.debug("[BraketProviderFactory] Create QappBraketProvider")
22
+
23
+ return QappBraketProvider()
24
+
25
+ if ProviderTag.AWS_BRAKET.__eq__(provider_type):
26
+ logger.debug("[BraketProviderFactory] Create AwsBraketProvider")
27
+
28
+ return AwsBraketProvider(
29
+ authentication.get("accessKey"),
30
+ authentication.get("secretKey"),
31
+ authentication.get("regionName"),
32
+ )
33
+
34
+ if ProviderTag.OQC_CLOUD.__eq__(provider_type):
35
+ return OqcCloudProvider(
36
+ authentication.get("url"),
37
+ authentication.get("accessToken")
38
+ )
39
+
40
+ raise Exception("Unsupported provider!")
@@ -0,0 +1,27 @@
1
+ """
2
+ QApp platform Project invocation_handler.py Copyright © CITYNOW Co. Ltd. All rights reserved.
3
+ """
4
+ from qapp_common.data.request.invocation_request import InvocationRequest
5
+ from qapp_common.handler.handler import Handler
6
+ from qapp_common.config.logging_config import logger
7
+
8
+ from ..component.backend.braket_invocation import BraketInvocation
9
+
10
+
11
+ class InvocationHandler(Handler):
12
+
13
+ def __init__(self, request_data: dict,
14
+ circuit_preparation_fn,
15
+ post_processing_fn):
16
+ super().__init__(request_data, post_processing_fn)
17
+ self.circuit_preparation_fn = circuit_preparation_fn
18
+
19
+ def handle(self):
20
+ logger.info("[InvocationHandler] handle()")
21
+
22
+ invocation_request = InvocationRequest(self.request_data)
23
+
24
+ backend = BraketInvocation(invocation_request)
25
+
26
+ backend.submit_job(circuit_preparation_fn=self.circuit_preparation_fn,
27
+ post_processing_fn=self.post_processing_fn)
File without changes
@@ -0,0 +1,109 @@
1
+ """
2
+ QuaO Project aws_braket_device.py Copyright © CITYNOW Co. Ltd. All rights reserved.
3
+ """
4
+ from dateutil.parser import parse
5
+
6
+ from qapp_common.config.logging_config import logger
7
+ from qapp_common.data.device.circuit_running_option import CircuitRunningOption
8
+ from qapp_common.enum.status.job_status import JobStatus
9
+ from qapp_common.model.device.custom_device import CustomDevice
10
+ from qapp_common.model.provider.provider import Provider
11
+
12
+
13
+ class AwsBraketDevice(CustomDevice):
14
+
15
+ def __init__(self, provider: Provider,
16
+ device_specification: str,
17
+ s3_bucket_name: str,
18
+ s3_prefix: str):
19
+ super().__init__(provider, device_specification)
20
+ self.s3_folder = (s3_bucket_name, s3_prefix)
21
+
22
+ def _produce_histogram_data(self, job_result) -> dict | None:
23
+ logger.debug("[AwsBraketDevice] _produce_histogram_data()")
24
+
25
+ return dict(job_result.measurement_counts)
26
+
27
+ def _get_provider_job_id(self, job) -> str:
28
+ logger.debug("[AwsBraketDevice] _get_provider_job_id()")
29
+
30
+ return job.id
31
+
32
+ def _get_job_status(self, job) -> str:
33
+ logger.debug("[AwsBraketDevice] _get_job_status()")
34
+
35
+ job_state = job.state()
36
+ logger.debug("[AwsBraketDevice] job status: {0} ".format(job_state))
37
+
38
+ if JobStatus.COMPLETED.value.__eq__(job_state):
39
+ job_state = JobStatus.DONE.value
40
+ return job_state
41
+
42
+ def _calculate_execution_time(self, job_result):
43
+ logger.debug("[AwsBraketDevice] _calculate_execution_time()")
44
+
45
+ if "task_metadata" not in job_result:
46
+ return
47
+
48
+ task_metadata = job_result["task_metadata"]
49
+
50
+ if task_metadata is None \
51
+ or not bool(task_metadata) \
52
+ or "createdAt" not in task_metadata \
53
+ or "endedAt" not in task_metadata:
54
+ return
55
+
56
+ created_at = task_metadata["createdAt"]
57
+ ended_at = task_metadata["endedAt"]
58
+
59
+ if created_at is None or ended_at is None:
60
+ return
61
+
62
+ created_at = parse(created_at.replace("T", " ").replace("Z", ""))
63
+ ended_at = parse(ended_at.replace("T", " ").replace("Z", ""))
64
+
65
+ offset = ended_at - created_at
66
+
67
+ self.execution_time = offset.total_seconds()
68
+
69
+ logger.debug("[AwsBraketDevice] Execution time calculation was: {0} seconds"
70
+ .format(self.execution_time))
71
+
72
+ def _get_job_result(self, job):
73
+ logger.debug("[AwsBraketDevice] _get_job_result()")
74
+
75
+ return job.result()
76
+
77
+ def _create_job(self, circuit, options: CircuitRunningOption):
78
+ logger.debug("[AwsBraketDevice] _create_job()")
79
+
80
+ job = self.device.run(task_specification=circuit,
81
+ s3_destination_folder=self.s3_folder,
82
+ shots=options.shots)
83
+ return job
84
+
85
+ def _is_simulator(self) -> bool:
86
+ logger.debug("[AwsBraketDevice] _is_simulator()")
87
+
88
+ return True
89
+
90
+ def _get_shots(self, job_result) -> int | None:
91
+ """
92
+ Retrieve the number of shots from the job result's task metadata.
93
+
94
+ This method checks if the job result contains task metadata and
95
+ retrieves the number of shots if available. If task metadata
96
+ does not exist or does not contain the shots attribute,
97
+ the method returns None.
98
+
99
+ Args:
100
+ job_result: An object representing the result of a job, which
101
+ may contain task metadata with the number of shots.
102
+
103
+ Returns:
104
+ int | None: The number of shots if available; otherwise, None.
105
+ """
106
+ logger.debug("[AwsBraketDevice] _get_shots()")
107
+
108
+ return job_result.task_metadata.shots if hasattr(job_result, 'task_metadata') and hasattr(
109
+ job_result.task_metadata, 'shots') else None
@@ -0,0 +1,102 @@
1
+ """
2
+ QApp Platform Project ibm_cloud_device.py Copyright © CITYNOW Co. Ltd. All rights reserved.
3
+ """
4
+ from time import time
5
+
6
+ from qapp_common.config.logging_config import logger
7
+ from qapp_common.data.device.circuit_running_option import CircuitRunningOption
8
+ from qapp_common.enum.status.job_status import JobStatus
9
+ from qapp_common.model.device.custom_device import CustomDevice
10
+ from qapp_common.model.provider.provider import Provider
11
+ from qcaas_client.client import QPUTask, CompilerConfig
12
+ from qiskit.qasm2 import dumps
13
+
14
+ from qapp_braket.util.circuit_convert_utils import CircuitConvertUtils
15
+
16
+
17
+ class OqcCloudDevice(CustomDevice):
18
+
19
+ def __init__(self, provider: Provider, device_specification: str):
20
+ super().__init__(provider, device_specification)
21
+
22
+ self.device_specification = device_specification
23
+
24
+ def _create_job(self, circuit, options: CircuitRunningOption):
25
+ logger.debug("[OqcCloudDevice] _create_job() with {0} shots".format(options.shots))
26
+
27
+ start_time = time()
28
+
29
+ qiskit_circuit = CircuitConvertUtils.braket_to_qiskit(circuit)
30
+ qiskit_circuit.measure_all()
31
+ qasm_str = dumps(qiskit_circuit)
32
+ circuit_submit_options = CompilerConfig(repeats=options.shots)
33
+
34
+ task = QPUTask(program=qasm_str, config=circuit_submit_options)
35
+ job = self.device.execute_tasks(task, qpu_id=self.device_specification)
36
+
37
+ self.execution_time = time() - start_time
38
+
39
+ return job
40
+
41
+ def _is_simulator(self) -> bool:
42
+ logger.debug("[OqcCloudDevice] _is_simulator()")
43
+
44
+ return True
45
+
46
+ def _produce_histogram_data(self, job_result) -> dict | None:
47
+ logger.debug("[OqcCloudDevice] _produce_histogram_data()")
48
+
49
+ return next(iter(job_result.result.values()))
50
+
51
+ def _get_provider_job_id(self, job) -> str:
52
+ logger.debug("[OqcCloudDevice] _get_provider_job_id()")
53
+
54
+ return job[0].id
55
+
56
+ def _get_job_status(self, job) -> str:
57
+ logger.debug("[OqcCloudDevice] _get_job_status()")
58
+
59
+ oqc_status = self.device.get_task_status(task_id=job[0].id,
60
+ qpu_id=self.device_specification)
61
+ logger.debug("[OqcCloudDevice] job status: {0} ".format(oqc_status))
62
+
63
+ if "FAILED".__eq__(oqc_status):
64
+ return JobStatus.ERROR.value
65
+ elif "COMPLETED".__eq__(oqc_status):
66
+ return JobStatus.DONE.value
67
+
68
+ return oqc_status
69
+
70
+ def _calculate_execution_time(self, job_result):
71
+ logger.debug("[OqcCloudDevice] _calculate_execution_time()")
72
+
73
+ logger.debug("[OqcCloudDevice] Execution time calculation was: {0} seconds"
74
+ .format(self.execution_time))
75
+
76
+ def _get_job_result(self, job):
77
+ logger.debug("[OqcCloudDevice] _get_job_result()")
78
+
79
+ return job[0]
80
+
81
+ def _get_shots(self, job_result) -> int | None:
82
+ """
83
+ Retrieve the total number of measurement shots from the job result.
84
+
85
+ This method checks if the job result contains measurement data
86
+ and calculates the total number of shots based on the measurement
87
+ results. If the measurement data is not available, the method
88
+ returns None.
89
+
90
+ Args:
91
+ job_result: An object representing the result of a job, which
92
+ may contain measurement results under the 'result'
93
+ attribute.
94
+
95
+ Returns:
96
+ int | None: The total number of shots if measurement data is
97
+ available; otherwise, None.
98
+ """
99
+ logger.debug("[OqcCloudDevice] _get_shots()")
100
+
101
+ result_meas = getattr(job_result, 'result', {}).get('meas')
102
+ return sum(result_meas.values()) if result_meas else None
@@ -0,0 +1,85 @@
1
+ """
2
+ QuaO Project qapp_braket_device.py Copyright © CITYNOW Co. Ltd. All rights reserved.
3
+ """
4
+ import time
5
+
6
+ from qapp_common.config.logging_config import logger
7
+ from qapp_common.data.device.circuit_running_option import CircuitRunningOption
8
+ from qapp_common.enum.status.job_status import JobStatus
9
+ from qapp_common.model.device.custom_device import CustomDevice
10
+ from qapp_common.model.provider.provider import Provider
11
+
12
+
13
+ class QappBraketDevice(CustomDevice):
14
+
15
+ def __init__(self, provider: Provider, device_specification: str):
16
+ super().__init__(provider, device_specification)
17
+
18
+ def _create_job(self, circuit, options: CircuitRunningOption):
19
+ logger.debug("[QappBraketDevice] _create_job()")
20
+
21
+ start_time = time.time()
22
+
23
+ job = self.device.run(task_specification=circuit, shots=options.shots)
24
+
25
+ self.execution_time = time.time() - start_time
26
+
27
+ return job
28
+
29
+ def _produce_histogram_data(self, job_result) -> dict:
30
+ logger.debug("[QappBraketDevice] _produce_histogram_data()")
31
+
32
+ return dict(job_result.measurement_counts)
33
+
34
+ def _get_provider_job_id(self, job) -> str:
35
+ logger.debug("[QappBraketDevice] _get_provider_job_id()")
36
+
37
+ return job.id
38
+
39
+ def _get_job_status(self, job) -> str:
40
+ logger.debug("[QappBraketDevice] _get_job_status()")
41
+
42
+ job_state = job.state()
43
+ logger.debug("[AwsBraketDevice] job status: {0} ".format(job_state))
44
+
45
+ if JobStatus.COMPLETED.value.__eq__(job_state):
46
+ job_state = JobStatus.DONE.value
47
+
48
+ return job_state
49
+
50
+ def _is_simulator(self) -> bool:
51
+ logger.debug("[QappBraketDevice] _is_simulator()")
52
+
53
+ return True
54
+
55
+ def _calculate_execution_time(self, job_result):
56
+ logger.debug("[QappBraketDevice] _is_simulator()")
57
+
58
+ logger.debug("[QappBraketDevice] Execution time calculation was: {0} seconds"
59
+ .format(self.execution_time))
60
+
61
+ def _get_job_result(self, job):
62
+ logger.debug("[QappBraketDevice] _get_job_result()")
63
+
64
+ return job.result()
65
+
66
+ def _get_shots(self, job_result) -> int | None:
67
+ """
68
+ Retrieve the number of shots from the job result.
69
+
70
+ This method checks if the job result contains task metadata and
71
+ retrieves the number of shots if available. If task metadata
72
+ does not exist or does not contain the shots attribute,
73
+ the method returns None.
74
+
75
+ Args:
76
+ job_result: An object representing the result of a job, which
77
+ may contain task metadata.
78
+
79
+ Returns:
80
+ int | None: The number of shots if available; otherwise, None.
81
+ """
82
+ logger.debug("[QuappBraketDevice] _get_shots()")
83
+
84
+ return job_result.task_metadata.shots if hasattr(job_result, 'task_metadata') and hasattr(
85
+ job_result.task_metadata, 'shots') else None
@@ -0,0 +1,37 @@
1
+ """
2
+ QuaO Project aws_braket_provider.py Copyright © CITYNOW Co. Ltd. All rights reserved.
3
+ """
4
+ import boto3
5
+ from braket.aws import AwsSession, AwsDevice
6
+
7
+ from qapp_common.enum.provider_tag import ProviderTag
8
+ from qapp_common.model.provider.provider import Provider
9
+ from qapp_common.config.logging_config import logger
10
+
11
+
12
+ class AwsBraketProvider(Provider):
13
+
14
+ def __init__(self, aws_access_key, aws_secret_access_key, region_name):
15
+ super().__init__(ProviderTag.AWS_BRAKET)
16
+ self.aws_access_key = aws_access_key
17
+ self.aws_secret_access_key = aws_secret_access_key
18
+ self.region_name = region_name
19
+
20
+ def get_backend(self, device_specification: str):
21
+ logger.debug('[AwsBraketProvider] get_backend()')
22
+
23
+ session = self.collect_provider()
24
+
25
+ return AwsDevice(
26
+ arn=device_specification,
27
+ aws_session=session)
28
+
29
+ def collect_provider(self):
30
+ logger.debug('[AwsBraketProvider] collect_provider()')
31
+
32
+ session = boto3.Session(
33
+ aws_access_key_id=self.aws_access_key,
34
+ aws_secret_access_key=self.aws_secret_access_key,
35
+ region_name=self.region_name)
36
+
37
+ return AwsSession(boto_session=session)
@@ -0,0 +1,25 @@
1
+ """
2
+ QApp Platform Project oqc_cloud_provider.py Copyright © CITYNOW Co. Ltd. All rights reserved.
3
+ """
4
+ from qcaas_client.client import OQCClient
5
+
6
+ from qapp_common.enum.provider_tag import ProviderTag
7
+ from qapp_common.model.provider.provider import Provider
8
+ from qapp_common.config.logging_config import logger
9
+
10
+
11
+ class OqcCloudProvider(Provider):
12
+ def __init__(self, oqc_cloud_url: str, access_token: str):
13
+ super().__init__(ProviderTag.OQC_CLOUD)
14
+ self.oqc_cloud_url = oqc_cloud_url
15
+ self.access_token = access_token
16
+
17
+ def get_backend(self, device_specification):
18
+ logger.debug("[OqcCloudProvider] get_backend()")
19
+
20
+ return self.collect_provider()
21
+
22
+ def collect_provider(self):
23
+ logger.debug("[OqcCloudProvider] collect_provider()")
24
+
25
+ return OQCClient(url=self.oqc_cloud_url, authentication_token=self.access_token)
@@ -0,0 +1,31 @@
1
+ """
2
+ QuaO Project qapp_braket_provider.py Copyright © CITYNOW Co. Ltd. All rights reserved.
3
+ """
4
+ from braket.devices import LocalSimulator
5
+
6
+ from qapp_common.config.logging_config import logger
7
+ from qapp_common.enum.provider_tag import ProviderTag
8
+ from qapp_common.model.provider.provider import Provider
9
+
10
+
11
+ class QappBraketProvider(Provider):
12
+
13
+ def __init__(self, ):
14
+ super().__init__(ProviderTag.QUAO_QUANTUM_SIMULATOR)
15
+
16
+ def get_backend(self, device_specification):
17
+ logger.debug('[QappBraketProvider] get_backend()')
18
+
19
+ provider = self.collect_provider()
20
+
21
+ device_names = provider.registered_backends()
22
+
23
+ if device_names.__contains__(device_specification):
24
+ return LocalSimulator(device_specification)
25
+
26
+ raise Exception('Unsupported device')
27
+
28
+ def collect_provider(self):
29
+ logger.debug('[QappBraketProvider] collect_provider()')
30
+
31
+ return LocalSimulator()
File without changes
@@ -0,0 +1,32 @@
1
+ """
2
+ QApp Platform Project circuit_convert_utils.py Copyright © CITYNOW Co. Ltd. All rights reserved.
3
+ """
4
+ from braket.circuits import Circuit
5
+ from qiskit import QuantumCircuit
6
+ from qiskit.qasm2 import loads
7
+ from pytket.qasm import circuit_to_qasm_str
8
+ from pytket.extensions.braket import braket_to_tk
9
+
10
+ from qapp_common.config.logging_config import logger
11
+
12
+
13
+ class CircuitConvertUtils:
14
+
15
+ @staticmethod
16
+ def braket_to_qasm2_str(circuit: Circuit) -> str:
17
+ logger.debug("[CircuitConvertUtils] braket_to_qasm2_str()")
18
+
19
+ return circuit_to_qasm_str(braket_to_tk(circuit))
20
+
21
+ @staticmethod
22
+ def qasm2_str_to_qiskit(qasm_str: str) -> QuantumCircuit:
23
+ logger.debug("[CircuitConvertUtils] qasm2_str_to_qiskit()")
24
+
25
+ return loads(qasm_str)
26
+
27
+ @staticmethod
28
+ def braket_to_qiskit(circuit: Circuit) -> QuantumCircuit:
29
+ logger.debug("[CircuitConvertUtils] braket_to_qiskit()")
30
+
31
+ qasm_str = CircuitConvertUtils.braket_to_qasm2_str(circuit)
32
+ return CircuitConvertUtils.qasm2_str_to_qiskit(qasm_str)
@@ -0,0 +1,38 @@
1
+ Metadata-Version: 2.4
2
+ Name: quapp-braket
3
+ Version: 0.0.10.dev1
4
+ Summary: Quapp braket library supporting Quapp Platform for Quantum Computing
5
+ Author-email: "CITYNOW Co. Ltd. " <corp@citynow.vn>
6
+ License: The MIT License (MIT)
7
+ Copyright © CITYNOW Co. Ltd. All rights reserved.
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
14
+ Project-URL: Homepage, https://citynow.asia/
15
+ Keywords: quapp,quapp-braket,braket,quantum
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Programming Language :: Python
18
+ Classifier: Programming Language :: Python :: 3
19
+ Requires-Python: >=3.7
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: quapp-common==0.0.10.dev1
23
+ Requires-Dist: amazon-braket-sdk==1.83.0
24
+ Requires-Dist: oqc-qcaas-client==3.7.0
25
+ Requires-Dist: qiskit
26
+ Requires-Dist: pytket
27
+ Requires-Dist: pytket-braket
28
+ Provides-Extra: dev
29
+ Requires-Dist: black; extra == "dev"
30
+ Requires-Dist: bumpver; extra == "dev"
31
+ Requires-Dist: isort; extra == "dev"
32
+ Requires-Dist: pip-tools; extra == "dev"
33
+ Requires-Dist: pytest; extra == "dev"
34
+ Dynamic: license-file
35
+
36
+ # qapp-braket
37
+
38
+ qapp-braket
@@ -0,0 +1,31 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ qapp_braket/__init__.py
5
+ qapp_braket/async_tasks/__init__.py
6
+ qapp_braket/async_tasks/braket_circuit_export_task.py
7
+ qapp_braket/component/__init__.py
8
+ qapp_braket/component/backend/__init__.py
9
+ qapp_braket/component/backend/braket_invocation.py
10
+ qapp_braket/factory/__init__.py
11
+ qapp_braket/factory/braket_device_factory.py
12
+ qapp_braket/factory/braket_handler_factory.py
13
+ qapp_braket/factory/braket_provider_factory.py
14
+ qapp_braket/handler/__init__.py
15
+ qapp_braket/handler/invocation_handler.py
16
+ qapp_braket/model/__init__.py
17
+ qapp_braket/model/device/__init__.py
18
+ qapp_braket/model/device/aws_braket_device.py
19
+ qapp_braket/model/device/oqc_cloud_device.py
20
+ qapp_braket/model/device/qapp_braket_device.py
21
+ qapp_braket/model/provider/__init__.py
22
+ qapp_braket/model/provider/aws_braket_provider.py
23
+ qapp_braket/model/provider/oqc_cloud_provider.py
24
+ qapp_braket/model/provider/qapp_braket_provider.py
25
+ qapp_braket/util/__init__.py
26
+ qapp_braket/util/circuit_convert_utils.py
27
+ quapp_braket.egg-info/PKG-INFO
28
+ quapp_braket.egg-info/SOURCES.txt
29
+ quapp_braket.egg-info/dependency_links.txt
30
+ quapp_braket.egg-info/requires.txt
31
+ quapp_braket.egg-info/top_level.txt
@@ -0,0 +1,13 @@
1
+ quapp-common==0.0.10.dev1
2
+ amazon-braket-sdk==1.83.0
3
+ oqc-qcaas-client==3.7.0
4
+ qiskit
5
+ pytket
6
+ pytket-braket
7
+
8
+ [dev]
9
+ black
10
+ bumpver
11
+ isort
12
+ pip-tools
13
+ pytest
@@ -0,0 +1 @@
1
+ qapp_braket
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+