quapp-qulacs 0.0.1.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 (32) hide show
  1. quapp_qulacs-0.0.1.dev1/LICENSE +8 -0
  2. quapp_qulacs-0.0.1.dev1/PKG-INFO +33 -0
  3. quapp_qulacs-0.0.1.dev1/README.md +2 -0
  4. quapp_qulacs-0.0.1.dev1/pyproject.toml +28 -0
  5. quapp_qulacs-0.0.1.dev1/quapp_qulacs/__init__.py +1 -0
  6. quapp_qulacs-0.0.1.dev1/quapp_qulacs/async_tasks/__init__.py +1 -0
  7. quapp_qulacs-0.0.1.dev1/quapp_qulacs/async_tasks/qulacs_circuit_export_task.py +45 -0
  8. quapp_qulacs-0.0.1.dev1/quapp_qulacs/component/__init__.py +1 -0
  9. quapp_qulacs-0.0.1.dev1/quapp_qulacs/component/backend/__init__.py +1 -0
  10. quapp_qulacs-0.0.1.dev1/quapp_qulacs/component/backend/qulacs_invocation.py +66 -0
  11. quapp_qulacs-0.0.1.dev1/quapp_qulacs/component/backend/qulacs_job_fetching.py +55 -0
  12. quapp_qulacs-0.0.1.dev1/quapp_qulacs/factory/__init__.py +1 -0
  13. quapp_qulacs-0.0.1.dev1/quapp_qulacs/factory/qulacs_device_factory.py +37 -0
  14. quapp_qulacs-0.0.1.dev1/quapp_qulacs/factory/qulacs_handler_factory.py +32 -0
  15. quapp_qulacs-0.0.1.dev1/quapp_qulacs/factory/qulacs_provider_factory.py +25 -0
  16. quapp_qulacs-0.0.1.dev1/quapp_qulacs/handler/__init__.py +1 -0
  17. quapp_qulacs-0.0.1.dev1/quapp_qulacs/handler/invocation_handler.py +35 -0
  18. quapp_qulacs-0.0.1.dev1/quapp_qulacs/handler/job_fetching_handler.py +30 -0
  19. quapp_qulacs-0.0.1.dev1/quapp_qulacs/model/__init__.py +1 -0
  20. quapp_qulacs-0.0.1.dev1/quapp_qulacs/model/device/__init__.py +1 -0
  21. quapp_qulacs-0.0.1.dev1/quapp_qulacs/model/device/qapp_qulacs_device.py +59 -0
  22. quapp_qulacs-0.0.1.dev1/quapp_qulacs/model/device/qulacs_density_matrix_device.py +61 -0
  23. quapp_qulacs-0.0.1.dev1/quapp_qulacs/model/device/qulacs_device.py +83 -0
  24. quapp_qulacs-0.0.1.dev1/quapp_qulacs/model/device/qulacs_gpu_device.py +59 -0
  25. quapp_qulacs-0.0.1.dev1/quapp_qulacs/model/provider/__init__.py +1 -0
  26. quapp_qulacs-0.0.1.dev1/quapp_qulacs/model/provider/qapp_qulacs_provider.py +36 -0
  27. quapp_qulacs-0.0.1.dev1/quapp_qulacs.egg-info/PKG-INFO +33 -0
  28. quapp_qulacs-0.0.1.dev1/quapp_qulacs.egg-info/SOURCES.txt +30 -0
  29. quapp_qulacs-0.0.1.dev1/quapp_qulacs.egg-info/dependency_links.txt +1 -0
  30. quapp_qulacs-0.0.1.dev1/quapp_qulacs.egg-info/requires.txt +9 -0
  31. quapp_qulacs-0.0.1.dev1/quapp_qulacs.egg-info/top_level.txt +1 -0
  32. quapp_qulacs-0.0.1.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,33 @@
1
+ Metadata-Version: 2.4
2
+ Name: quapp-qulacs
3
+ Version: 0.0.1.dev1
4
+ Summary: Quapp common 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://quapp.cloud/
15
+ Keywords: quapp,quapp-qulacs,quantum
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Programming Language :: Python
18
+ Classifier: Programming Language :: Python :: 3
19
+ Requires-Python: <3.11,>=3.9
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: quapp-common==0.0.11.dev10
23
+ Requires-Dist: qulacs==0.6.13
24
+ Provides-Extra: dev
25
+ Requires-Dist: black; extra == "dev"
26
+ Requires-Dist: bumpver; extra == "dev"
27
+ Requires-Dist: isort; extra == "dev"
28
+ Requires-Dist: pip-tools; extra == "dev"
29
+ Requires-Dist: pytest; extra == "dev"
30
+ Dynamic: license-file
31
+
32
+ # quapp-qulacs
33
+
@@ -0,0 +1,2 @@
1
+ # quapp-qulacs
2
+
@@ -0,0 +1,28 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0.0", "wheel==0.45.1"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "quapp-qulacs"
7
+ version = "0.0.1.dev1"
8
+ description = "Quapp common 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-qulacs", "quantum"]
18
+ dependencies = [
19
+ "quapp-common==0.0.11.dev10",
20
+ "qulacs ==0.6.13"
21
+ ]
22
+ requires-python = ">=3.9,<3.11"
23
+
24
+ [project.optional-dependencies]
25
+ dev = ["black", "bumpver", "isort", "pip-tools", "pytest"]
26
+
27
+ [project.urls]
28
+ Homepage = "https://quapp.cloud/"
@@ -0,0 +1 @@
1
+ from .factory.qulacs_handler_factory import QulacsHandlerFactory
@@ -0,0 +1,45 @@
1
+ # Quapp Platform Project
2
+ # qulacs_circuit_export_task.py
3
+ # Copyright © CITYNOW Co. Ltd. All rights reserved.
4
+
5
+ from quapp_common.async_tasks.export_circuit_task import CircuitExportTask
6
+
7
+
8
+ class QulacsCircuitExportTask(CircuitExportTask):
9
+
10
+ def do(self):
11
+ self.logger.debug('[Circuit export] Qulacs circuit export - start')
12
+
13
+ circuit_export_url = self.circuit_data_holder.export_url
14
+
15
+ if circuit_export_url is None or len(circuit_export_url) < 1:
16
+ return
17
+
18
+ self.logger.info(
19
+ '[Circuit export] Qulacs circuits do not support image export. '
20
+ 'Skipping circuit export.')
21
+
22
+ def _transpile_circuit(self):
23
+ self.logger.debug('Transpiling circuit (Qulacs)')
24
+ try:
25
+ try:
26
+ num_qubits = (self.circuit_data_holder.circuit.get_qubit_count()
27
+ if hasattr(self.circuit_data_holder.circuit,
28
+ "get_qubit_count") else None)
29
+ depth = (self.circuit_data_holder.circuit.calculate_depth()
30
+ if hasattr(self.circuit_data_holder.circuit,
31
+ "calculate_depth") else None)
32
+ self.logger.debug(
33
+ f'Circuit stats: qubits={num_qubits}, depth={depth}')
34
+ except Exception as exception:
35
+ self.logger.warning(f'Failed to get circuit stats: {exception}')
36
+
37
+ circuit = self.circuit_data_holder.circuit
38
+
39
+ self.logger.info(
40
+ 'Qulacs does not require transpilation. Returning circuit as-is.')
41
+ return circuit
42
+
43
+ except Exception as exception:
44
+ self.logger.exception(f'Circuit export failed: {exception}')
45
+ raise
@@ -0,0 +1,66 @@
1
+ # Quapp Platform Project
2
+ # qulacs_invocation.py
3
+ # Copyright © CITYNOW Co. Ltd. All rights reserved.
4
+
5
+ from qulacs import QuantumCircuit
6
+ from quapp_common.component.backend.invocation import Invocation
7
+ from quapp_common.data.request.invocation_request import InvocationRequest
8
+ from quapp_common.model.provider.provider import Provider
9
+
10
+ from ...factory.qulacs_device_factory import QulacsDeviceFactory
11
+ from ...factory.qulacs_provider_factory import QulacsProviderFactory
12
+
13
+
14
+ class QulacsInvocation(Invocation):
15
+
16
+ def __init__(self, request_data: InvocationRequest):
17
+ super().__init__(request_data)
18
+
19
+ def _export_circuit(self, circuit):
20
+ self.logger.debug('Circuit export skipped')
21
+ return
22
+
23
+ def _create_provider(self):
24
+ try:
25
+ self.logger.debug(
26
+ f'Creating provider: provider_tag={getattr(self.backend_information, "provider_tag", None)}, sdk={getattr(self, "sdk", None)}')
27
+ provider = QulacsProviderFactory.create_provider(
28
+ provider_type=self.backend_information.provider_tag,
29
+ sdk=self.sdk,
30
+ authentication=self.backend_information.authentication)
31
+ self.logger.info(
32
+ f'Provider created successfully: {type(provider).__name__}')
33
+ return provider
34
+ except Exception as exception:
35
+ self.logger.exception(f'Provider creation failed: {exception}')
36
+ raise
37
+
38
+ def _create_device(self, provider: Provider):
39
+ self.logger.debug('Creating device')
40
+ try:
41
+ device_spec = getattr(self.backend_information, "device_name", None)
42
+ self.logger.debug(
43
+ f'Creating device from provider={type(provider).__name__}, '
44
+ f'device_specification={device_spec}, sdk={getattr(self, "sdk", None)}')
45
+ device = QulacsDeviceFactory.create_device(provider=provider,
46
+ device_specification=device_spec,
47
+ authentication=self.backend_information.authentication,
48
+ sdk=self.sdk)
49
+ self.logger.info(
50
+ f'Device created successfully: {type(device).__name__}')
51
+ return device
52
+ except Exception as exception:
53
+ self.logger.exception(f"Device creation failed: {exception}")
54
+ raise
55
+
56
+ def _get_qubit_amount(self, circuit):
57
+ self.logger.debug(
58
+ f'Getting qubit amount for circuit type: {type(circuit).__name__}')
59
+ if isinstance(circuit, QuantumCircuit):
60
+ qubits = int(circuit.get_qubit_count())
61
+ self.logger.debug(f'Qubit amount determined: {qubits}')
62
+ return qubits
63
+
64
+ self.logger.exception(
65
+ f'Invalid circuit type for qubit amount: {type(circuit).__name__}')
66
+ raise Exception("Invalid circuit type!")
@@ -0,0 +1,55 @@
1
+ # Quapp Platform Project
2
+ # qulacs_job_fetching.py
3
+ # Copyright © CITYNOW Co. Ltd. All rights reserved.
4
+
5
+ from quapp_common.component.backend.job_fetching import JobFetching
6
+ from quapp_common.data.request.job_fetching_request import JobFetchingRequest
7
+ from quapp_common.enum.provider_tag import ProviderTag
8
+ from quapp_common.enum.sdk import Sdk
9
+
10
+ from ...factory.qulacs_provider_factory import QulacsProviderFactory
11
+
12
+
13
+ class QulacsJobFetching(JobFetching):
14
+
15
+ def __init__(self, request_data: JobFetchingRequest):
16
+ super().__init__(request_data)
17
+
18
+ def _collect_provider(self):
19
+ try:
20
+ self.logger.debug(
21
+ f'Collecting provider with provider_type={ProviderTag.QUAO_QUANTUM_SIMULATOR}, '
22
+ f'sdk={Sdk.QULACS}')
23
+ provider = QulacsProviderFactory.create_provider(
24
+ provider_type=ProviderTag.QUAO_QUANTUM_SIMULATOR,
25
+ sdk=Sdk.QULACS,
26
+ authentication=self.provider_authentication).collect_provider()
27
+ self.logger.info('Provider collected successfully')
28
+ return provider
29
+ except Exception as exception:
30
+ self.logger.exception(f'Failed to collect provider: {exception}')
31
+ raise
32
+
33
+ def _retrieve_job(self, provider):
34
+ self.logger.debug(
35
+ f'Retrieving job with job_id={self.provider_job_id}')
36
+ self.logger.warning(
37
+ 'Qulacs is a local simulator. Job retrieval is not supported.')
38
+ raise NotImplementedError(
39
+ "Qulacs is a local simulator and does not support job retrieval. "
40
+ "Results are returned synchronously after execution.")
41
+
42
+ def _get_job_status(self, job):
43
+ self.logger.debug('Getting job status')
44
+ return "DONE"
45
+
46
+ def _get_job_result(self, job):
47
+ self.logger.info("_get_job_result()")
48
+ try:
49
+ self.logger.debug("Returning raw job object for job_id=%s",
50
+ self.provider_job_id)
51
+ return job
52
+ except Exception as exception:
53
+ self.logger.exception("Failed to get job result for job_id=%s: %s",
54
+ self.provider_job_id, exception)
55
+ raise
@@ -0,0 +1,37 @@
1
+ # Quapp Platform Project
2
+ # qulacs_device_factory.py
3
+ # Copyright © CITYNOW Co. Ltd. All rights reserved.
4
+
5
+ from quapp_common.config.logging_config import logger
6
+ from quapp_common.enum.provider_tag import ProviderTag
7
+ from quapp_common.enum.sdk import Sdk
8
+ from quapp_common.factory.device_factory import DeviceFactory
9
+ from quapp_common.model.provider.provider import Provider
10
+
11
+ from ..model.device.qapp_qulacs_device import QappQulacsDevice
12
+ from ..model.device.qulacs_density_matrix_device import QulacsDensityMatrixDevice
13
+
14
+
15
+ class QulacsDeviceFactory(DeviceFactory):
16
+
17
+ @staticmethod
18
+ def create_device(provider: Provider, device_specification: str,
19
+ authentication: dict, sdk: Sdk):
20
+ logger.info("[QulacsDeviceFactory] create_device()")
21
+
22
+ provider_type = ProviderTag.resolve(provider.get_provider_type().value)
23
+
24
+ if not (ProviderTag.QUAO_QUANTUM_SIMULATOR.__eq__(provider_type)
25
+ and Sdk.QULACS.__eq__(sdk)):
26
+ raise Exception("Unsupported provider/sdk combination!")
27
+
28
+ if device_specification == "gpu_simulator":
29
+ logger.info("Created GPU_SIMULATOR device (Qulacs)")
30
+ # return QulacsGpuDevice(provider, device_specification)
31
+
32
+ if device_specification == "density_matrix_simulator":
33
+ logger.info("Created DENSITY_MATRIX_SIMULATOR device (Qulacs)")
34
+ return QulacsDensityMatrixDevice(provider, device_specification)
35
+
36
+ logger.info("Created STATEVECTOR_SIMULATOR device (Qulacs)")
37
+ return QappQulacsDevice(provider, device_specification)
@@ -0,0 +1,32 @@
1
+ # Quapp Platform Project
2
+ # qulacs_handler_factory.py
3
+ # Copyright © CITYNOW Co. Ltd. All rights reserved.
4
+
5
+ from quapp_common.config.logging_config import job_logger
6
+ from quapp_common.factory.handler_factory import HandlerFactory
7
+ from quapp_common.handler.handler import Handler
8
+
9
+ from ..handler.invocation_handler import InvocationHandler
10
+ from ..handler.job_fetching_handler import JobFetchingHandler
11
+
12
+
13
+ class QulacsHandlerFactory(HandlerFactory):
14
+
15
+ @staticmethod
16
+ def create_handler(event, circuit_preparation_fn,
17
+ post_processing_fn) -> Handler:
18
+ logger = job_logger(getattr(event.json(), 'jobId', None))
19
+ logger.debug("Create Qulacs Handler")
20
+
21
+ request_data = event.json()
22
+ provider_job_id = request_data.get("providerJobId")
23
+
24
+ if provider_job_id is None:
25
+ logger.debug('providerJobId is None. Create InvocationHandler')
26
+ return InvocationHandler(request_data=request_data,
27
+ circuit_preparation_fn=circuit_preparation_fn,
28
+ post_processing_fn=post_processing_fn)
29
+
30
+ logger.debug('Create JobFetchingHandler')
31
+ return JobFetchingHandler(request_data=request_data,
32
+ post_processing_fn=post_processing_fn)
@@ -0,0 +1,25 @@
1
+ # Quapp Platform Project
2
+ # qulacs_provider_factory.py
3
+ # Copyright © CITYNOW Co. Ltd. All rights reserved.
4
+
5
+ from quapp_common.config.logging_config import logger
6
+ from quapp_common.enum.provider_tag import ProviderTag
7
+ from quapp_common.enum.sdk import Sdk
8
+ from quapp_common.factory.provider_factory import ProviderFactory
9
+
10
+ from ..model.provider.qapp_qulacs_provider import QappQulacsProvider
11
+
12
+
13
+ class QulacsProviderFactory(ProviderFactory):
14
+
15
+ @staticmethod
16
+ def create_provider(provider_type: ProviderTag, sdk: Sdk,
17
+ authentication: dict):
18
+ logger.debug("Create Qulacs Provider")
19
+
20
+ if ProviderTag.QUAO_QUANTUM_SIMULATOR.__eq__(
21
+ provider_type) and Sdk.QULACS.__eq__(sdk):
22
+ logger.debug("Create Qapp Qulacs Provider")
23
+ return QappQulacsProvider()
24
+
25
+ raise Exception("Unsupported provider!")
@@ -0,0 +1,35 @@
1
+ # Quapp Platform Project
2
+ # invocation_handler.py
3
+ # Copyright © CITYNOW Co. Ltd. All rights reserved.
4
+
5
+ from quapp_common.data.request.invocation_request import InvocationRequest
6
+ from quapp_common.handler.handler import Handler
7
+
8
+ from ..component.backend.qulacs_invocation import QulacsInvocation
9
+
10
+
11
+ class InvocationHandler(Handler):
12
+ def __init__(self, request_data: dict, circuit_preparation_fn,
13
+ post_processing_fn):
14
+ super().__init__(request_data, post_processing_fn)
15
+ self.circuit_preparation_fn = circuit_preparation_fn
16
+
17
+ def handle(self):
18
+ self.logger.debug('Handle Invocation: start')
19
+ try:
20
+
21
+ invocation_request = InvocationRequest(self.request_data)
22
+ self.logger.debug(f'Invocation request created successfully: '
23
+ f'{invocation_request.__dict__.keys()}')
24
+
25
+ backend = QulacsInvocation(invocation_request)
26
+ self.logger.info('Submitting job via QulacsInvocation')
27
+
28
+ backend.submit_job(
29
+ circuit_preparation_fn=self.circuit_preparation_fn,
30
+ post_processing_fn=self.post_processing_fn)
31
+
32
+ self.logger.debug('Job submission triggered successfully')
33
+ except Exception as exception:
34
+ self.logger.exception(f'Invocation handling failed: {exception}')
35
+ raise
@@ -0,0 +1,30 @@
1
+ # Quapp Platform Project
2
+ # job_fetching_handler.py
3
+ # Copyright © CITYNOW Co. Ltd. All rights reserved.
4
+
5
+ from quapp_common.data.request.job_fetching_request import JobFetchingRequest
6
+ from quapp_common.handler.handler import Handler
7
+
8
+ from ..component.backend.qulacs_job_fetching import QulacsJobFetching
9
+
10
+
11
+ class JobFetchingHandler(Handler):
12
+ def __init__(self, request_data: dict, post_processing_fn):
13
+ super().__init__(request_data, post_processing_fn)
14
+
15
+ def handle(self):
16
+ self.logger.debug('Handle JobFetching: start')
17
+
18
+ request = JobFetchingRequest(self.request_data)
19
+ self.logger.debug(
20
+ f'JobFetching request created successfully: {request.__dict__.keys()}')
21
+
22
+ job_fetching = QulacsJobFetching(request)
23
+ self.logger.info('Job fetching initiated')
24
+
25
+ self.logger.debug('Job fetching started')
26
+ fetching_result = job_fetching.fetch(
27
+ post_processing_fn=self.post_processing_fn)
28
+ self.logger.debug('Job fetching finished')
29
+
30
+ return fetching_result
@@ -0,0 +1,59 @@
1
+ # Quapp Platform Project
2
+ # qapp_qulacs_device.py
3
+ # Copyright © CITYNOW Co. Ltd. All rights reserved.
4
+
5
+ import uuid
6
+ from time import time
7
+
8
+ from qulacs import QuantumCircuit, QuantumState
9
+ from quapp_common.data.device.circuit_running_option import CircuitRunningOption
10
+ from quapp_common.model.provider.provider import Provider
11
+
12
+ from .qulacs_device import QulacsDevice
13
+
14
+
15
+ class QappQulacsDevice(QulacsDevice):
16
+ def __init__(self, provider: Provider, device_specification: str):
17
+ super().__init__(provider, device_specification)
18
+
19
+ def _create_job(self, circuit, options: CircuitRunningOption):
20
+ self.logger.debug(f'Creating job with {options.shots} shots')
21
+
22
+ n_qubits = circuit.get_qubit_count()
23
+ self.logger.debug(f'Circuit qubit count: {n_qubits}')
24
+
25
+ state = QuantumState(n_qubits)
26
+ state.set_zero_state()
27
+ self.logger.debug('Quantum state initialized to |0...0>')
28
+
29
+ start_time = time()
30
+
31
+ circuit.update_quantum_state(state)
32
+ self.logger.debug('Circuit applied to quantum state')
33
+
34
+ samples = state.sampling(options.shots)
35
+ self.logger.debug(f'Sampling completed: {len(samples)} samples')
36
+
37
+ execution_time = time() - start_time
38
+ self.logger.debug(f'Execution time: {execution_time} seconds')
39
+
40
+ job_id = str(uuid.uuid4())
41
+
42
+ job = {
43
+ "job_id": job_id,
44
+ "status": "DONE",
45
+ "result": {
46
+ "samples": samples,
47
+ "n_qubits": n_qubits,
48
+ "shots": options.shots,
49
+ "execution_time": execution_time,
50
+ },
51
+ }
52
+
53
+ self.logger.info(f'Job created successfully: job_id={job_id}')
54
+ return job
55
+
56
+ def _is_simulator(self) -> bool:
57
+ self.logger.debug('Checking if simulator')
58
+ self.logger.debug(f'Simulator: {True}')
59
+ return True
@@ -0,0 +1,61 @@
1
+ # Quapp Platform Project
2
+ # qulacs_density_matrix_device.py
3
+ # Copyright © CITYNOW Co. Ltd. All rights reserved.
4
+
5
+ import uuid
6
+ from time import time
7
+
8
+ from qulacs import QuantumCircuit, DensityMatrix
9
+ from quapp_common.data.device.circuit_running_option import CircuitRunningOption
10
+ from quapp_common.model.provider.provider import Provider
11
+
12
+ from .qulacs_device import QulacsDevice
13
+
14
+
15
+ class QulacsDensityMatrixDevice(QulacsDevice):
16
+ def __init__(self, provider: Provider, device_specification: str):
17
+ super().__init__(provider, device_specification)
18
+
19
+ def _create_job(self, circuit, options: CircuitRunningOption):
20
+ self.logger.debug(
21
+ f'Creating density matrix job with {options.shots} shots')
22
+
23
+ n_qubits = circuit.get_qubit_count()
24
+ self.logger.debug(f'Circuit qubit count: {n_qubits}')
25
+
26
+ state = DensityMatrix(n_qubits)
27
+ state.set_zero_state()
28
+ self.logger.debug('Density matrix initialized to |0...0><0...0|')
29
+
30
+ start_time = time()
31
+
32
+ circuit.update_quantum_state(state)
33
+ self.logger.debug('Circuit applied to density matrix')
34
+
35
+ samples = state.sampling(options.shots)
36
+ self.logger.debug(f'Sampling completed: {len(samples)} samples')
37
+
38
+ execution_time = time() - start_time
39
+ self.logger.debug(f'Execution time: {execution_time} seconds')
40
+
41
+ job_id = str(uuid.uuid4())
42
+
43
+ job = {
44
+ "job_id": job_id,
45
+ "status": "DONE",
46
+ "result": {
47
+ "samples": samples,
48
+ "n_qubits": n_qubits,
49
+ "shots": options.shots,
50
+ "execution_time": execution_time,
51
+ },
52
+ }
53
+
54
+ self.logger.info(
55
+ f'Density matrix job created successfully: job_id={job_id}')
56
+ return job
57
+
58
+ def _is_simulator(self) -> bool:
59
+ self.logger.debug('Checking if simulator')
60
+ self.logger.debug(f'Simulator: {True}')
61
+ return True
@@ -0,0 +1,83 @@
1
+ # Quapp Platform Project
2
+ # qulacs_device.py
3
+ # Copyright © CITYNOW Co. Ltd. All rights reserved.
4
+
5
+ from abc import ABC
6
+ from collections import Counter
7
+
8
+ from quapp_common.model.device.custom_device import CustomDevice
9
+
10
+
11
+ class QulacsDevice(CustomDevice, ABC):
12
+
13
+ def _produce_histogram_data(self, job_result) -> dict | None:
14
+ self.logger.debug('Producing histogram data')
15
+
16
+ try:
17
+ samples = job_result.get("samples")
18
+ if samples is None:
19
+ self.logger.debug('No samples found in job_result')
20
+ return None
21
+
22
+ n_qubits = job_result.get("n_qubits", 0)
23
+ counts = Counter(samples)
24
+ histogram_data = {
25
+ format(k, 'b').zfill(n_qubits): v
26
+ for k, v in counts.items()
27
+ }
28
+ self.logger.debug(
29
+ f'Histogram data produced successfully: {histogram_data}')
30
+ return histogram_data
31
+ except Exception as exception:
32
+ self.logger.exception(
33
+ f'Unexpected error while producing histogram data: {exception}')
34
+ return None
35
+
36
+ def _get_provider_job_id(self, job) -> str:
37
+ self.logger.debug('Get provider job id')
38
+ try:
39
+ job_id = job.get("job_id", "")
40
+ self.logger.debug(f'Provider job id: {job_id}')
41
+ return job_id
42
+ except Exception as exception:
43
+ self.logger.exception(f'Failed to get provider job id: {exception}')
44
+ raise
45
+
46
+ def _get_job_status(self, job) -> str:
47
+ self.logger.debug('Get job status')
48
+ return "DONE"
49
+
50
+ def _calculate_execution_time(self, job_result):
51
+ self.logger.debug('Calculate execution time')
52
+
53
+ try:
54
+ execution_time = job_result.get("execution_time")
55
+ if execution_time is not None:
56
+ self.execution_time = execution_time
57
+ self.logger.debug(
58
+ f'Execution time: {self.execution_time} seconds')
59
+ return None
60
+ except Exception as exception:
61
+ self.logger.exception(
62
+ f'Failed to calculate execution time: {exception}')
63
+ return None
64
+
65
+ def _get_job_result(self, job):
66
+ self.logger.debug('Getting job result')
67
+ try:
68
+ result = job.get("result")
69
+ self.logger.debug('Result fetched successfully')
70
+ return result
71
+ except Exception as exception:
72
+ self.logger.exception(f'Failed to fetch job result: {exception}')
73
+ raise
74
+
75
+ def _get_shots(self, job_result) -> int | None:
76
+ try:
77
+ shots = job_result.get("shots")
78
+ self.logger.debug(f'Number of shots: {shots}')
79
+ return shots
80
+ except Exception as exception:
81
+ self.logger.exception(
82
+ f'Failed to get shots from job_result: {exception}')
83
+ return None
@@ -0,0 +1,59 @@
1
+ # # Quapp Platform Project
2
+ # # qulacs_gpu_device.py
3
+ # # Copyright © CITYNOW Co. Ltd. All rights reserved.
4
+ #
5
+ # import uuid
6
+ # from time import time
7
+ #
8
+ # from qulacs import QuantumCircuit, QuantumStateGpu
9
+ # from quapp_common.data.device.circuit_running_option import CircuitRunningOption
10
+ # from quapp_common.model.provider.provider import Provider
11
+ #
12
+ # from .qulacs_device import QulacsDevice
13
+ #
14
+ #
15
+ # class QulacsGpuDevice(QulacsDevice):
16
+ # def __init__(self, provider: Provider, device_specification: str):
17
+ # super().__init__(provider, device_specification)
18
+ #
19
+ # def _create_job(self, circuit, options: CircuitRunningOption):
20
+ # self.logger.debug(f'Creating GPU job with {options.shots} shots')
21
+ #
22
+ # n_qubits = circuit.get_qubit_count()
23
+ # self.logger.debug(f'Circuit qubit count: {n_qubits}')
24
+ #
25
+ # state = QuantumStateGpu(n_qubits)
26
+ # state.set_zero_state()
27
+ # self.logger.debug('GPU quantum state initialized to |0...0>')
28
+ #
29
+ # start_time = time()
30
+ #
31
+ # circuit.update_quantum_state(state)
32
+ # self.logger.debug('Circuit applied to GPU quantum state')
33
+ #
34
+ # samples = state.sampling(options.shots)
35
+ # self.logger.debug(f'Sampling completed: {len(samples)} samples')
36
+ #
37
+ # execution_time = time() - start_time
38
+ # self.logger.debug(f'Execution time: {execution_time} seconds')
39
+ #
40
+ # job_id = str(uuid.uuid4())
41
+ #
42
+ # job = {
43
+ # "job_id": job_id,
44
+ # "status": "DONE",
45
+ # "result": {
46
+ # "samples": samples,
47
+ # "n_qubits": n_qubits,
48
+ # "shots": options.shots,
49
+ # "execution_time": execution_time,
50
+ # },
51
+ # }
52
+ #
53
+ # self.logger.info(f'GPU job created successfully: job_id={job_id}')
54
+ # return job
55
+ #
56
+ # def _is_simulator(self) -> bool:
57
+ # self.logger.debug('Checking if simulator')
58
+ # self.logger.debug(f'Simulator: {True}')
59
+ # return True
@@ -0,0 +1,36 @@
1
+ # Quapp Platform Project
2
+ # qapp_qulacs_provider.py
3
+ # Copyright © CITYNOW Co. Ltd. All rights reserved.
4
+
5
+ from quapp_common.config.logging_config import job_logger
6
+ from quapp_common.enum.provider_tag import ProviderTag
7
+ from quapp_common.model.provider.provider import Provider
8
+
9
+ logger = job_logger('QappQulacsProvider')
10
+
11
+ SUPPORTED_DEVICES = {
12
+ "statevector_simulator",
13
+ "gpu_simulator",
14
+ "density_matrix_simulator",
15
+ }
16
+
17
+
18
+ class QappQulacsProvider(Provider):
19
+
20
+ def __init__(self):
21
+ super().__init__(ProviderTag.QUAO_QUANTUM_SIMULATOR)
22
+
23
+ def get_backend(self, device_specification):
24
+ logger.debug('Get backend from Qapp Qulacs')
25
+ logger.debug(f'Device specification: {device_specification}')
26
+
27
+ if device_specification not in SUPPORTED_DEVICES:
28
+ logger.exception(f'Unsupported device: {device_specification}. '
29
+ f'Supported: {SUPPORTED_DEVICES}')
30
+ raise Exception(f'Unsupported device: {device_specification}')
31
+
32
+ return device_specification
33
+
34
+ def collect_provider(self):
35
+ logger.debug('Collecting provider for Qapp Qulacs')
36
+ return None
@@ -0,0 +1,33 @@
1
+ Metadata-Version: 2.4
2
+ Name: quapp-qulacs
3
+ Version: 0.0.1.dev1
4
+ Summary: Quapp common 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://quapp.cloud/
15
+ Keywords: quapp,quapp-qulacs,quantum
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Programming Language :: Python
18
+ Classifier: Programming Language :: Python :: 3
19
+ Requires-Python: <3.11,>=3.9
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: quapp-common==0.0.11.dev10
23
+ Requires-Dist: qulacs==0.6.13
24
+ Provides-Extra: dev
25
+ Requires-Dist: black; extra == "dev"
26
+ Requires-Dist: bumpver; extra == "dev"
27
+ Requires-Dist: isort; extra == "dev"
28
+ Requires-Dist: pip-tools; extra == "dev"
29
+ Requires-Dist: pytest; extra == "dev"
30
+ Dynamic: license-file
31
+
32
+ # quapp-qulacs
33
+
@@ -0,0 +1,30 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ quapp_qulacs/__init__.py
5
+ quapp_qulacs.egg-info/PKG-INFO
6
+ quapp_qulacs.egg-info/SOURCES.txt
7
+ quapp_qulacs.egg-info/dependency_links.txt
8
+ quapp_qulacs.egg-info/requires.txt
9
+ quapp_qulacs.egg-info/top_level.txt
10
+ quapp_qulacs/async_tasks/__init__.py
11
+ quapp_qulacs/async_tasks/qulacs_circuit_export_task.py
12
+ quapp_qulacs/component/__init__.py
13
+ quapp_qulacs/component/backend/__init__.py
14
+ quapp_qulacs/component/backend/qulacs_invocation.py
15
+ quapp_qulacs/component/backend/qulacs_job_fetching.py
16
+ quapp_qulacs/factory/__init__.py
17
+ quapp_qulacs/factory/qulacs_device_factory.py
18
+ quapp_qulacs/factory/qulacs_handler_factory.py
19
+ quapp_qulacs/factory/qulacs_provider_factory.py
20
+ quapp_qulacs/handler/__init__.py
21
+ quapp_qulacs/handler/invocation_handler.py
22
+ quapp_qulacs/handler/job_fetching_handler.py
23
+ quapp_qulacs/model/__init__.py
24
+ quapp_qulacs/model/device/__init__.py
25
+ quapp_qulacs/model/device/qapp_qulacs_device.py
26
+ quapp_qulacs/model/device/qulacs_density_matrix_device.py
27
+ quapp_qulacs/model/device/qulacs_device.py
28
+ quapp_qulacs/model/device/qulacs_gpu_device.py
29
+ quapp_qulacs/model/provider/__init__.py
30
+ quapp_qulacs/model/provider/qapp_qulacs_provider.py
@@ -0,0 +1,9 @@
1
+ quapp-common==0.0.11.dev10
2
+ qulacs==0.6.13
3
+
4
+ [dev]
5
+ black
6
+ bumpver
7
+ isort
8
+ pip-tools
9
+ pytest
@@ -0,0 +1 @@
1
+ quapp_qulacs
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+