quapp-pyquil 0.0.3.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.
- quapp_pyquil-0.0.3.dev1/LICENSE +8 -0
- quapp_pyquil-0.0.3.dev1/PKG-INFO +33 -0
- quapp_pyquil-0.0.3.dev1/README.md +2 -0
- quapp_pyquil-0.0.3.dev1/pyproject.toml +30 -0
- quapp_pyquil-0.0.3.dev1/qapp_pyquil/__init__.py +0 -0
- quapp_pyquil-0.0.3.dev1/qapp_pyquil/async_tasks/__init__.py +0 -0
- quapp_pyquil-0.0.3.dev1/qapp_pyquil/async_tasks/pyquil_circuit_export_task.py +62 -0
- quapp_pyquil-0.0.3.dev1/qapp_pyquil/component/__init__.py +0 -0
- quapp_pyquil-0.0.3.dev1/qapp_pyquil/component/backend/__init__.py +0 -0
- quapp_pyquil-0.0.3.dev1/qapp_pyquil/component/backend/pyquil_invocation.py +50 -0
- quapp_pyquil-0.0.3.dev1/qapp_pyquil/component/backend/pyquil_job_fetching.py +64 -0
- quapp_pyquil-0.0.3.dev1/qapp_pyquil/factory/__init__.py +0 -0
- quapp_pyquil-0.0.3.dev1/qapp_pyquil/factory/pyquil_device_factory.py +36 -0
- quapp_pyquil-0.0.3.dev1/qapp_pyquil/factory/pyquil_handler_factory.py +32 -0
- quapp_pyquil-0.0.3.dev1/qapp_pyquil/factory/pyquil_provider_factory.py +32 -0
- quapp_pyquil-0.0.3.dev1/qapp_pyquil/handler/__init__.py +0 -0
- quapp_pyquil-0.0.3.dev1/qapp_pyquil/handler/invocation_handler.py +27 -0
- quapp_pyquil-0.0.3.dev1/qapp_pyquil/handler/job_fetching_handler.py +27 -0
- quapp_pyquil-0.0.3.dev1/qapp_pyquil/model/__init__.py +0 -0
- quapp_pyquil-0.0.3.dev1/qapp_pyquil/model/device/__init__.py +0 -0
- quapp_pyquil-0.0.3.dev1/qapp_pyquil/model/device/qapp_pyquil_device.py +118 -0
- quapp_pyquil-0.0.3.dev1/qapp_pyquil/model/device/rigetti_pyquil_device.py +70 -0
- quapp_pyquil-0.0.3.dev1/qapp_pyquil/model/provider/__init__.py +0 -0
- quapp_pyquil-0.0.3.dev1/qapp_pyquil/model/provider/qapp_pyquil_provider.py +30 -0
- quapp_pyquil-0.0.3.dev1/qapp_pyquil/model/provider/rigetti_pyquil_provider.py +31 -0
- quapp_pyquil-0.0.3.dev1/quapp_pyquil.egg-info/PKG-INFO +33 -0
- quapp_pyquil-0.0.3.dev1/quapp_pyquil.egg-info/SOURCES.txt +29 -0
- quapp_pyquil-0.0.3.dev1/quapp_pyquil.egg-info/dependency_links.txt +1 -0
- quapp_pyquil-0.0.3.dev1/quapp_pyquil.egg-info/requires.txt +9 -0
- quapp_pyquil-0.0.3.dev1/quapp_pyquil.egg-info/top_level.txt +1 -0
- quapp_pyquil-0.0.3.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-pyquil
|
|
3
|
+
Version: 0.0.3.dev1
|
|
4
|
+
Summary: QApp pyquil library supporting QApp 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,qapp-pyquil,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.dev3
|
|
23
|
+
Requires-Dist: pyquil==4.15.0
|
|
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
|
+
# qapp-pyqil
|
|
33
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
|
|
2
|
+
[build-system]
|
|
3
|
+
requires = ["setuptools>=61.0.0", "wheel"]
|
|
4
|
+
build-backend = "setuptools.build_meta"
|
|
5
|
+
|
|
6
|
+
[project]
|
|
7
|
+
name = "quapp-pyquil"
|
|
8
|
+
version = "0.0.3.dev1"
|
|
9
|
+
description = "QApp pyquil library supporting QApp Platform for Quantum Computing"
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
authors = [{ name = "CITYNOW Co. Ltd. ", email = "corp@citynow.vn" }]
|
|
12
|
+
license = { file = "LICENSE" }
|
|
13
|
+
classifiers = [
|
|
14
|
+
"License :: OSI Approved :: MIT License",
|
|
15
|
+
"Programming Language :: Python",
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
]
|
|
18
|
+
keywords = ["quapp", "qapp-pyquil", "quantum"]
|
|
19
|
+
dependencies = [
|
|
20
|
+
"quapp-common==0.0.11.dev3",
|
|
21
|
+
"pyquil==4.15.0"
|
|
22
|
+
|
|
23
|
+
]
|
|
24
|
+
requires-python = ">=3.9,<3.11"
|
|
25
|
+
|
|
26
|
+
[project.optional-dependencies]
|
|
27
|
+
dev = ["black", "bumpver", "isort", "pip-tools", "pytest"]
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Homepage = "https://citynow.asia/"
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""
|
|
2
|
+
QApp Platform Project pennylane_circuit_export_task.py Copyright © CITYNOW Co. Ltd. All rights reserved.
|
|
3
|
+
"""
|
|
4
|
+
from quapp_common.async_tasks.export_circuit_task import CircuitExportTask
|
|
5
|
+
# from ..quapp_common.config.logging_config import logger
|
|
6
|
+
# from pyquil.latex import to_latex
|
|
7
|
+
# import os
|
|
8
|
+
# import subprocess
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class PyquilCircuitExportTask(CircuitExportTask):
|
|
12
|
+
|
|
13
|
+
def _convert(self):
|
|
14
|
+
|
|
15
|
+
# circuit = self.circuit_data_holder.circuit
|
|
16
|
+
|
|
17
|
+
# latex_code = to_latex(circuit)
|
|
18
|
+
|
|
19
|
+
# latex_filename = "quantikz.tex"
|
|
20
|
+
# pdf_filename = "quantikz.pdf"
|
|
21
|
+
# svg_filename = "quantikz.svg"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# try:
|
|
25
|
+
|
|
26
|
+
# with open(latex_filename, "w") as latex_file:
|
|
27
|
+
# latex_file.write(latex_code)
|
|
28
|
+
|
|
29
|
+
# subprocess.run(["pdflatex", latex_filename], check=True)
|
|
30
|
+
# subprocess.run(["pdf2svg", pdf_filename, svg_filename], check=True)
|
|
31
|
+
|
|
32
|
+
# with open(svg_filename, "rb") as svg_file:
|
|
33
|
+
# svg_bytes = svg_file.read()
|
|
34
|
+
|
|
35
|
+
# except subprocess.CalledProcessError:
|
|
36
|
+
# logger.error('[PyquilCircuitExportTask] Fail to convert to svg')
|
|
37
|
+
# return None
|
|
38
|
+
|
|
39
|
+
# finally:
|
|
40
|
+
|
|
41
|
+
# logger.info('[PyquilCircuitExportTask] Cleaning up temporary files')
|
|
42
|
+
|
|
43
|
+
# files_to_cleanup = [
|
|
44
|
+
# "quantikz.tex", # LaTeX source file
|
|
45
|
+
# "quantikz.pdf", # Generated PDF file
|
|
46
|
+
# "quantikz.svg", # Generated SVG file
|
|
47
|
+
# "quantikz.aux", # Auxiliary file created during LaTeX compilation
|
|
48
|
+
# "quantikz.log", # Log file created during LaTeX compilation
|
|
49
|
+
# ]
|
|
50
|
+
# # Clean up each file if it exists
|
|
51
|
+
# for file in files_to_cleanup:
|
|
52
|
+
# try:
|
|
53
|
+
# os.remove(file)
|
|
54
|
+
# logger.info(f'[PyquilCircuitExportTask] Successfully removed: {file}')
|
|
55
|
+
# except FileNotFoundError:
|
|
56
|
+
# logger.error(f'[PyquilCircuitExportTask] File not found: {file}')
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# return svg_bytes
|
|
61
|
+
|
|
62
|
+
return None
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""
|
|
2
|
+
QApp Platform Project pennylane_invocation.py Copyright © CITYNOW Co. Ltd. All rights reserved.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from quapp_common.component.backend.invocation import Invocation
|
|
6
|
+
from quapp_common.config.logging_config import logger
|
|
7
|
+
from quapp_common.config.thread_config import circuit_exporting_pool
|
|
8
|
+
from quapp_common.data.async_task.circuit_export.backend_holder import BackendDataHolder
|
|
9
|
+
from quapp_common.data.async_task.circuit_export.circuit_holder import CircuitDataHolder
|
|
10
|
+
from quapp_common.data.request.invocation_request import InvocationRequest
|
|
11
|
+
from quapp_common.model.provider.provider import Provider
|
|
12
|
+
|
|
13
|
+
from ...async_tasks.pyquil_circuit_export_task import PyquilCircuitExportTask
|
|
14
|
+
from ...factory.pyquil_device_factory import PyquilDeviceFactory
|
|
15
|
+
from ...factory.pyquil_provider_factory import PyquilProviderFactory
|
|
16
|
+
|
|
17
|
+
class PyquilInvocation(Invocation):
|
|
18
|
+
|
|
19
|
+
def __init__(self, request_data: InvocationRequest, **kwargs):
|
|
20
|
+
super().__init__(request_data)
|
|
21
|
+
self.num_qubits = kwargs.get('num_qubits')
|
|
22
|
+
|
|
23
|
+
def _export_circuit(self, circuit):
|
|
24
|
+
logger.info("[PyquilInvocation] _export_circuit()")
|
|
25
|
+
|
|
26
|
+
circuit_export_task = PyquilCircuitExportTask(
|
|
27
|
+
circuit_data_holder=CircuitDataHolder(circuit, self.circuit_export_url),
|
|
28
|
+
backend_data_holder=BackendDataHolder(
|
|
29
|
+
self.backend_information, self.authentication.user_token
|
|
30
|
+
),
|
|
31
|
+
)
|
|
32
|
+
circuit_exporting_pool.submit(circuit_export_task.do)
|
|
33
|
+
|
|
34
|
+
def _create_provider(self):
|
|
35
|
+
logger.info('[PennylaneInvocation] _create_provider()')
|
|
36
|
+
|
|
37
|
+
return PyquilProviderFactory.create_provider(
|
|
38
|
+
provider_type=self.backend_information.provider_tag, sdk=self.sdk,
|
|
39
|
+
authentication=self.backend_information.authentication)
|
|
40
|
+
|
|
41
|
+
def _create_device(self, provider: Provider):
|
|
42
|
+
logger.info('[PennylaneInvocation] Creating device')
|
|
43
|
+
return PyquilDeviceFactory.create_device(provider=provider,
|
|
44
|
+
device_specification=self.backend_information.device_name,
|
|
45
|
+
authentication=self.backend_information.authentication,
|
|
46
|
+
sdk=self.sdk, num_qubits=self.num_qubits,
|
|
47
|
+
input=self.input)
|
|
48
|
+
|
|
49
|
+
def _get_qubit_amount(self, circuit):
|
|
50
|
+
return len(circuit.get_qubit_indices())
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""
|
|
2
|
+
QApp Platform Project qiskit_job_fetching.py Copyright © CITYNOW Co. Ltd. All rights reserved.
|
|
3
|
+
"""
|
|
4
|
+
from quapp_common.component.backend.job_fetcher import JobFetcher
|
|
5
|
+
from quapp_common.data.request.job_fetching_request import JobFetchingRequest
|
|
6
|
+
from quapp_common.config.logging_config import logger
|
|
7
|
+
from quapp_common.enum.provider_tag import ProviderTag
|
|
8
|
+
from quapp_common.enum.sdk import Sdk
|
|
9
|
+
from quapp_common.enum.status.job_status import JobStatus
|
|
10
|
+
from quapp_common.enum.status.status_code import StatusCode
|
|
11
|
+
from pyquil import get_qc
|
|
12
|
+
import pickle
|
|
13
|
+
import os
|
|
14
|
+
|
|
15
|
+
from ...factory.pyquil_provider_factory import PyquilProviderFactory
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class PyquilJobFetching(JobFetcher):
|
|
19
|
+
|
|
20
|
+
def __init__(self, request_data: JobFetchingRequest, device_name: str):
|
|
21
|
+
super().__init__(request_data)
|
|
22
|
+
self.request_data = request_data
|
|
23
|
+
self.device_name = device_name
|
|
24
|
+
|
|
25
|
+
def _collect_provider(self):
|
|
26
|
+
|
|
27
|
+
print(f"Device name in fetching: {self.device_name}")
|
|
28
|
+
return get_qc(self.device_name)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _retrieve_job(self, job):
|
|
32
|
+
|
|
33
|
+
job_id = self.provider_job_id
|
|
34
|
+
device = self._collect_provider()
|
|
35
|
+
|
|
36
|
+
with open(job_id+".pkl", 'rb') as file:
|
|
37
|
+
data = pickle.load(file)
|
|
38
|
+
|
|
39
|
+
res = device.qam.get_result(data)
|
|
40
|
+
print(f"Result: {res}")
|
|
41
|
+
|
|
42
|
+
return res
|
|
43
|
+
|
|
44
|
+
def _get_job_status(self, job):
|
|
45
|
+
|
|
46
|
+
if (job.execution_duration_microseconds is not None):
|
|
47
|
+
|
|
48
|
+
if os.path.exists(self.provider_job_id+".pkl"):
|
|
49
|
+
os.remove(self.provider_job_id+".pkl")
|
|
50
|
+
return JobStatus.DONE.value
|
|
51
|
+
|
|
52
|
+
return "POLLING"
|
|
53
|
+
|
|
54
|
+
def _get_job_result(self, job):
|
|
55
|
+
return job
|
|
56
|
+
|
|
57
|
+
def _produce_histogram_data(self, job_result) -> dict | None:
|
|
58
|
+
return None
|
|
59
|
+
|
|
60
|
+
def _get_execution_time(self, job_result):
|
|
61
|
+
return job_result.execution_duration_microseconds
|
|
62
|
+
|
|
63
|
+
def _get_shots(self, job_result):
|
|
64
|
+
return None
|
|
File without changes
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""
|
|
2
|
+
QApp Platform Project
|
|
3
|
+
pennylane_device_factory.py
|
|
4
|
+
Copyright © CITYNOW Co. Ltd. All rights reserved.
|
|
5
|
+
"""
|
|
6
|
+
from quapp_common.config.logging_config import logger
|
|
7
|
+
from quapp_common.enum.provider_tag import ProviderTag
|
|
8
|
+
from quapp_common.enum.sdk import Sdk
|
|
9
|
+
from quapp_common.factory.device_factory import DeviceFactory
|
|
10
|
+
from quapp_common.model.provider.provider import Provider
|
|
11
|
+
from ..model.device.qapp_pyquil_device import QAppPyquilDevice
|
|
12
|
+
from ..model.device.rigetti_pyquil_device import RigettiPyquilDevice
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class PyquilDeviceFactory(DeviceFactory):
|
|
16
|
+
|
|
17
|
+
@staticmethod
|
|
18
|
+
def create_device(provider: Provider, device_specification: str, authentication: dict, sdk: Sdk,
|
|
19
|
+
**kwargs):
|
|
20
|
+
logger.info("[PyquilDeviceFactory] create_device()")
|
|
21
|
+
|
|
22
|
+
provider_type = ProviderTag.resolve(provider.get_provider_type().value)
|
|
23
|
+
|
|
24
|
+
logger.info("[PyquilDeviceFactory] provider type:" + str(provider_type))
|
|
25
|
+
|
|
26
|
+
match provider_type:
|
|
27
|
+
case ProviderTag.QUAO_QUANTUM_SIMULATOR:
|
|
28
|
+
if Sdk.PYQUIL == sdk:
|
|
29
|
+
logger.debug('[PyquilDeviceFactory] Creating QAppPyquilDevice')
|
|
30
|
+
return QAppPyquilDevice(provider, device_specification)
|
|
31
|
+
case ProviderTag.RIGETTI:
|
|
32
|
+
if Sdk.PYQUIL == sdk:
|
|
33
|
+
logger.debug('[PyquilDeviceFactory] Creating RigettiPyquilDevice')
|
|
34
|
+
return RigettiPyquilDevice(provider, device_specification)
|
|
35
|
+
case _:
|
|
36
|
+
raise ValueError(f"Unsupported provider type: {provider_type}")
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""
|
|
2
|
+
QApp Platform Project pyquil_handler_factory.py Copyright © CITYNOW Co. Ltd. All rights reserved.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from quapp_common.config.logging_config import 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
|
+
class PyquilHandlerFactory(HandlerFactory):
|
|
13
|
+
|
|
14
|
+
@staticmethod
|
|
15
|
+
def create_handler(event, circuit_preparation_fn, post_processing_fn) -> Handler:
|
|
16
|
+
logger.info("[PyquilHandlerFactory] create_handler()")
|
|
17
|
+
|
|
18
|
+
request_data = event.json()
|
|
19
|
+
provider_job_id = request_data.get("providerJobId")
|
|
20
|
+
|
|
21
|
+
if provider_job_id is None:
|
|
22
|
+
logger.debug("[PyquilHandlerFactory] Create InvocationHandler")
|
|
23
|
+
return InvocationHandler(
|
|
24
|
+
request_data=request_data,
|
|
25
|
+
circuit_preparation_fn=circuit_preparation_fn,
|
|
26
|
+
post_processing_fn=post_processing_fn,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
logger.debug("Create JobFetchingHandler")
|
|
30
|
+
return JobFetchingHandler(
|
|
31
|
+
request_data=request_data, post_processing_fn=post_processing_fn
|
|
32
|
+
)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""
|
|
2
|
+
QApp Platform Project
|
|
3
|
+
pennylane_provider_factory.py
|
|
4
|
+
Copyright © CITYNOW Co. Ltd. All rights reserved.
|
|
5
|
+
"""
|
|
6
|
+
from quapp_common.config.logging_config import logger
|
|
7
|
+
from quapp_common.enum.provider_tag import ProviderTag
|
|
8
|
+
from quapp_common.enum.sdk import Sdk
|
|
9
|
+
from quapp_common.factory.provider_factory import ProviderFactory
|
|
10
|
+
|
|
11
|
+
from ..model.provider.rigetti_pyquil_provider import RigettiPyquilProvider
|
|
12
|
+
from ..model.provider.qapp_pyquil_provider import QAppPyquilProvider
|
|
13
|
+
|
|
14
|
+
class PyquilProviderFactory(ProviderFactory):
|
|
15
|
+
|
|
16
|
+
@staticmethod
|
|
17
|
+
def create_provider(provider_type: ProviderTag, sdk: Sdk, authentication: dict):
|
|
18
|
+
logger.info("[PyquilProviderFactory] create_provider()")
|
|
19
|
+
logger.debug(f"provider_type: {provider_type}, sdk: {sdk}, authentication: {authentication}")
|
|
20
|
+
|
|
21
|
+
match provider_type:
|
|
22
|
+
case ProviderTag.QUAO_QUANTUM_SIMULATOR:
|
|
23
|
+
if Sdk.PYQUIL.__eq__(sdk):
|
|
24
|
+
return QAppPyquilProvider()
|
|
25
|
+
raise ValueError(f'Unsupported SDK for provider type: {provider_type}')
|
|
26
|
+
case ProviderTag.RIGETTI:
|
|
27
|
+
if Sdk.PYQUIL.__eq__(sdk):
|
|
28
|
+
return RigettiPyquilProvider()
|
|
29
|
+
raise ValueError(f'Unsupported SDK for provider type: {provider_type}')
|
|
30
|
+
|
|
31
|
+
case _:
|
|
32
|
+
raise ValueError(f'Unsupported provider type: {provider_type}')
|
|
File without changes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""
|
|
2
|
+
QApp platform Project invocation_handler.py Copyright © CITYNOW Co. Ltd. All rights reserved.
|
|
3
|
+
"""
|
|
4
|
+
from quapp_common.data.request.invocation_request import InvocationRequest
|
|
5
|
+
from quapp_common.handler.handler import Handler
|
|
6
|
+
from quapp_common.config.logging_config import logger
|
|
7
|
+
|
|
8
|
+
from ..component.backend.pyquil_invocation import PyquilInvocation
|
|
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 = PyquilInvocation(invocation_request)
|
|
25
|
+
|
|
26
|
+
backend.submit_job(circuit_preparation_fn=self.circuit_preparation_fn,
|
|
27
|
+
post_processing_fn=self.post_processing_fn)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""
|
|
2
|
+
QApp Platform Project job_fetching_handler.py Copyright © CITYNOW Co. Ltd. All rights reserved.
|
|
3
|
+
"""
|
|
4
|
+
from quapp_common.data.request.job_fetching_request import JobFetchingRequest
|
|
5
|
+
from quapp_common.handler.handler import Handler
|
|
6
|
+
from quapp_common.config.logging_config import logger
|
|
7
|
+
|
|
8
|
+
from ..component.backend.pyquil_job_fetching import PyquilJobFetching
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class JobFetchingHandler(Handler):
|
|
12
|
+
def __init__(self,
|
|
13
|
+
request_data: dict,
|
|
14
|
+
post_processing_fn):
|
|
15
|
+
super().__init__(request_data, post_processing_fn)
|
|
16
|
+
|
|
17
|
+
def handle(self):
|
|
18
|
+
logger.info("[JobFetchingHandler] handle()")
|
|
19
|
+
|
|
20
|
+
request = JobFetchingRequest(self.request_data)
|
|
21
|
+
device_name = self.request_data.get("authentication").get("deviceName")
|
|
22
|
+
|
|
23
|
+
job_fetching = PyquilJobFetching(request,device_name = device_name)
|
|
24
|
+
|
|
25
|
+
fetching_result = job_fetching.fetch(post_processing_fn=self.post_processing_fn)
|
|
26
|
+
|
|
27
|
+
return fetching_result
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"""
|
|
2
|
+
QApp Platform Project
|
|
3
|
+
qapp_pyquil_device.py
|
|
4
|
+
Copyright © CITYNOW Co. Ltd. All rights reserved.
|
|
5
|
+
"""
|
|
6
|
+
import time
|
|
7
|
+
import math
|
|
8
|
+
|
|
9
|
+
from quapp_common.data.response.authentication import Authentication
|
|
10
|
+
from quapp_common.data.response.project_header import ProjectHeader
|
|
11
|
+
from quapp_common.model.device.device import Device
|
|
12
|
+
from quapp_common.config.logging_config import logger
|
|
13
|
+
from quapp_common.data.device.circuit_running_option import CircuitRunningOption
|
|
14
|
+
from quapp_common.model.provider.provider import Provider
|
|
15
|
+
from quapp_common.enum.invocation_step import InvocationStep
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class QAppPyquilDevice(Device):
|
|
19
|
+
def __init__(self, provider: Provider, device_specification: str):
|
|
20
|
+
super().__init__(provider, device_specification)
|
|
21
|
+
logger.debug('[QAppPyquilDevice] Initializing device specification')
|
|
22
|
+
self.device_specification = device_specification
|
|
23
|
+
|
|
24
|
+
def _create_job(self, circuit, options: CircuitRunningOption):
|
|
25
|
+
logger.debug(
|
|
26
|
+
'[QAppPyquilDevice] Creating job with {0} shots'.format(
|
|
27
|
+
options.shots))
|
|
28
|
+
|
|
29
|
+
circuit.wrap_in_numshots_loop(options.shots)
|
|
30
|
+
|
|
31
|
+
start_time = time.time()
|
|
32
|
+
executable = self.device.compile(circuit)
|
|
33
|
+
result = self.device.run(executable)
|
|
34
|
+
end_time = time.time()
|
|
35
|
+
|
|
36
|
+
data = {"result": result, "time_taken_execute": end_time - start_time}
|
|
37
|
+
|
|
38
|
+
# logger.info(data)
|
|
39
|
+
return data
|
|
40
|
+
|
|
41
|
+
def _is_simulator(self) -> bool:
|
|
42
|
+
logger.debug('[QAppPyquilDevice] Is simulator')
|
|
43
|
+
return True
|
|
44
|
+
|
|
45
|
+
def _produce_histogram_data(self, job_result) -> dict | None:
|
|
46
|
+
logger.info('[PyquilDevice] Producing histogram data')
|
|
47
|
+
|
|
48
|
+
histogram = job_result.get('histogram')
|
|
49
|
+
|
|
50
|
+
if histogram is None:
|
|
51
|
+
logger.debug("[PyquilDevice] Can't produce histogram")
|
|
52
|
+
|
|
53
|
+
return job_result.get('histogram')
|
|
54
|
+
|
|
55
|
+
def _get_provider_job_id(self, job) -> str:
|
|
56
|
+
logger.debug('[PyquilDevice] Getting job id')
|
|
57
|
+
|
|
58
|
+
# no job id in local simulator
|
|
59
|
+
return ""
|
|
60
|
+
|
|
61
|
+
def _get_job_status(self, job) -> str:
|
|
62
|
+
logger.debug('[PyquilDevice] Getting job status')
|
|
63
|
+
|
|
64
|
+
return "DONE"
|
|
65
|
+
|
|
66
|
+
def _get_job_result(self, job) -> dict:
|
|
67
|
+
logger.debug('[PyquilDevice] Getting job result')
|
|
68
|
+
|
|
69
|
+
return job
|
|
70
|
+
|
|
71
|
+
def _calculate_execution_time(self, job_result):
|
|
72
|
+
logger.debug('[PyquilDevice] Calculating execution time')
|
|
73
|
+
|
|
74
|
+
self.execution_time = job_result.get('time_taken_execute')
|
|
75
|
+
|
|
76
|
+
logger.debug(
|
|
77
|
+
'[PyquilDevice] Execution time calculation was: {0} seconds'.format(
|
|
78
|
+
self.execution_time))
|
|
79
|
+
|
|
80
|
+
def run_circuit(self,
|
|
81
|
+
circuit,
|
|
82
|
+
post_processing_fn,
|
|
83
|
+
options: CircuitRunningOption,
|
|
84
|
+
callback_dict: dict,
|
|
85
|
+
authentication: Authentication,
|
|
86
|
+
project_header: ProjectHeader):
|
|
87
|
+
"""
|
|
88
|
+
@param project_header: project header
|
|
89
|
+
@param callback_dict: callback url dictionary
|
|
90
|
+
@param options: Options for run circuit
|
|
91
|
+
@param authentication: Authentication for calling quao server
|
|
92
|
+
@param post_processing_fn: Post-processing function
|
|
93
|
+
@param circuit: Circuit was run
|
|
94
|
+
"""
|
|
95
|
+
original_job_result, job_response = self._on_execution(
|
|
96
|
+
authentication=authentication,
|
|
97
|
+
project_header=project_header,
|
|
98
|
+
execution_callback=callback_dict.get(InvocationStep.EXECUTION),
|
|
99
|
+
circuit=circuit,
|
|
100
|
+
options=options)
|
|
101
|
+
|
|
102
|
+
if original_job_result is None:
|
|
103
|
+
return
|
|
104
|
+
|
|
105
|
+
job_response = self._on_analysis(
|
|
106
|
+
job_response=job_response,
|
|
107
|
+
original_job_result=original_job_result,
|
|
108
|
+
analysis_callback=callback_dict.get(InvocationStep.ANALYSIS))
|
|
109
|
+
|
|
110
|
+
if job_response is None:
|
|
111
|
+
return
|
|
112
|
+
|
|
113
|
+
self._on_finalization(job_result=original_job_result.get('result'),
|
|
114
|
+
authentication=authentication,
|
|
115
|
+
post_processing_fn=post_processing_fn,
|
|
116
|
+
finalization_callback=callback_dict.get(
|
|
117
|
+
InvocationStep.FINALIZATION),
|
|
118
|
+
project_header=project_header)
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""
|
|
2
|
+
QApp Platform Project
|
|
3
|
+
qapp_pyquil_device.py
|
|
4
|
+
Copyright © CITYNOW Co. Ltd. All rights reserved.
|
|
5
|
+
"""
|
|
6
|
+
import time
|
|
7
|
+
import math
|
|
8
|
+
|
|
9
|
+
from quapp_common.data.response.authentication import Authentication
|
|
10
|
+
from quapp_common.data.response.project_header import ProjectHeader
|
|
11
|
+
from quapp_common.model.device.device import Device
|
|
12
|
+
from quapp_common.config.logging_config import logger
|
|
13
|
+
from quapp_common.data.device.circuit_running_option import CircuitRunningOption
|
|
14
|
+
from quapp_common.model.provider.provider import Provider
|
|
15
|
+
from quapp_common.enum.invocation_step import InvocationStep
|
|
16
|
+
|
|
17
|
+
import pickle
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class RigettiPyquilDevice(Device):
|
|
21
|
+
def __init__(self, provider: Provider, device_specification: str):
|
|
22
|
+
super().__init__(provider, device_specification)
|
|
23
|
+
logger.debug('[RigettiPyquilDevice] Initializing device specification')
|
|
24
|
+
self.device_specification = device_specification
|
|
25
|
+
|
|
26
|
+
def _create_job(self, circuit, options: CircuitRunningOption):
|
|
27
|
+
logger.debug(
|
|
28
|
+
'[RigettiPyquilDevice] Creating job with {0} shots'.format(
|
|
29
|
+
options.shots))
|
|
30
|
+
|
|
31
|
+
circuit.wrap_in_numshots_loop(options.shots)
|
|
32
|
+
executable = self.device.compile(circuit)
|
|
33
|
+
|
|
34
|
+
return self.device.qam.execute(executable)
|
|
35
|
+
|
|
36
|
+
def _is_simulator(self) -> bool:
|
|
37
|
+
logger.debug('[RigettiPyquilDevice] is quantum machine')
|
|
38
|
+
return False
|
|
39
|
+
|
|
40
|
+
def _get_provider_job_id(self, job) -> str:
|
|
41
|
+
logger.debug('[PyquilDevice] Getting job id')
|
|
42
|
+
|
|
43
|
+
job_id = job.job_id
|
|
44
|
+
|
|
45
|
+
with open(job_id + ".pkl", "wb") as f:
|
|
46
|
+
pickle.dump(job,f)
|
|
47
|
+
|
|
48
|
+
print("Job ID: ", job_id)
|
|
49
|
+
|
|
50
|
+
return job_id
|
|
51
|
+
|
|
52
|
+
def _get_job_status(self, job) -> str:
|
|
53
|
+
logger.debug('[PyquilDevice] Getting job status')
|
|
54
|
+
|
|
55
|
+
return "RUNNING"
|
|
56
|
+
|
|
57
|
+
def _calculate_execution_time(self, job_result):
|
|
58
|
+
|
|
59
|
+
logger.debug('[PyquilDevice] Getting execution time')
|
|
60
|
+
return None
|
|
61
|
+
|
|
62
|
+
def _get_job_result(self, job) -> dict:
|
|
63
|
+
|
|
64
|
+
return None
|
|
65
|
+
|
|
66
|
+
def _produce_histogram_data(self, job_result) -> dict | None:
|
|
67
|
+
logger.info('[PyquilDevice] Producing histogram data')
|
|
68
|
+
|
|
69
|
+
return None
|
|
70
|
+
|
|
File without changes
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""
|
|
2
|
+
QApp Platform Project
|
|
3
|
+
qapp_pennylane_provider.py
|
|
4
|
+
Copyright © CITYNOW Co. Ltd. All rights reserved.
|
|
5
|
+
"""
|
|
6
|
+
from quapp_common.config.logging_config import logger
|
|
7
|
+
from quapp_common.enum.provider_tag import ProviderTag
|
|
8
|
+
from quapp_common.model.provider.provider import Provider
|
|
9
|
+
|
|
10
|
+
from pyquil import get_qc
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class QAppPyquilProvider(Provider):
|
|
14
|
+
def __init__(self, ):
|
|
15
|
+
logger.debug('[QAppPyquilProvider] get_backend()')
|
|
16
|
+
super().__init__(ProviderTag.QUAO_QUANTUM_SIMULATOR)
|
|
17
|
+
|
|
18
|
+
def get_backend(self, device_specification):
|
|
19
|
+
logger.debug('[QAppPyquilProvider] get_backend()')
|
|
20
|
+
|
|
21
|
+
try:
|
|
22
|
+
print(device_specification)
|
|
23
|
+
return get_qc(device_specification,as_qvm=True)
|
|
24
|
+
except Exception as e:
|
|
25
|
+
print(e)
|
|
26
|
+
raise ValueError('[QAppPyquilProvider] Unsupported device')
|
|
27
|
+
|
|
28
|
+
def collect_provider(self):
|
|
29
|
+
logger.debug('[QAppPyquilProvider] collect_provider()')
|
|
30
|
+
return None
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""
|
|
2
|
+
QApp Platform Project
|
|
3
|
+
qapp_pennylane_provider.py
|
|
4
|
+
Copyright © CITYNOW Co. Ltd. All rights reserved.
|
|
5
|
+
"""
|
|
6
|
+
from quapp_common.config.logging_config import logger
|
|
7
|
+
from quapp_common.enum.provider_tag import ProviderTag
|
|
8
|
+
from quapp_common.model.provider.provider import Provider
|
|
9
|
+
|
|
10
|
+
from pyquil import get_qc
|
|
11
|
+
from pyquil.api import QuantumComputer
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class RigettiPyquilProvider(Provider):
|
|
15
|
+
def __init__(self, ):
|
|
16
|
+
logger.debug('[RigettiPyquilProvider] get_backend()')
|
|
17
|
+
super().__init__(ProviderTag.RIGETTI)
|
|
18
|
+
|
|
19
|
+
def get_backend(self, device_specification) -> QuantumComputer:
|
|
20
|
+
logger.debug('[RigettiPyquilProvider] get_backend()')
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
print(device_specification)
|
|
24
|
+
return get_qc(device_specification)
|
|
25
|
+
except Exception as e:
|
|
26
|
+
print(e)
|
|
27
|
+
raise ValueError('[RigettiPyquilProvider] Unsupported device')
|
|
28
|
+
|
|
29
|
+
def collect_provider(self):
|
|
30
|
+
logger.debug('[RigettiPyquilProvider] collect_provider()')
|
|
31
|
+
return None
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: quapp-pyquil
|
|
3
|
+
Version: 0.0.3.dev1
|
|
4
|
+
Summary: QApp pyquil library supporting QApp 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,qapp-pyquil,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.dev3
|
|
23
|
+
Requires-Dist: pyquil==4.15.0
|
|
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
|
+
# qapp-pyqil
|
|
33
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
qapp_pyquil/__init__.py
|
|
5
|
+
qapp_pyquil/async_tasks/__init__.py
|
|
6
|
+
qapp_pyquil/async_tasks/pyquil_circuit_export_task.py
|
|
7
|
+
qapp_pyquil/component/__init__.py
|
|
8
|
+
qapp_pyquil/component/backend/__init__.py
|
|
9
|
+
qapp_pyquil/component/backend/pyquil_invocation.py
|
|
10
|
+
qapp_pyquil/component/backend/pyquil_job_fetching.py
|
|
11
|
+
qapp_pyquil/factory/__init__.py
|
|
12
|
+
qapp_pyquil/factory/pyquil_device_factory.py
|
|
13
|
+
qapp_pyquil/factory/pyquil_handler_factory.py
|
|
14
|
+
qapp_pyquil/factory/pyquil_provider_factory.py
|
|
15
|
+
qapp_pyquil/handler/__init__.py
|
|
16
|
+
qapp_pyquil/handler/invocation_handler.py
|
|
17
|
+
qapp_pyquil/handler/job_fetching_handler.py
|
|
18
|
+
qapp_pyquil/model/__init__.py
|
|
19
|
+
qapp_pyquil/model/device/__init__.py
|
|
20
|
+
qapp_pyquil/model/device/qapp_pyquil_device.py
|
|
21
|
+
qapp_pyquil/model/device/rigetti_pyquil_device.py
|
|
22
|
+
qapp_pyquil/model/provider/__init__.py
|
|
23
|
+
qapp_pyquil/model/provider/qapp_pyquil_provider.py
|
|
24
|
+
qapp_pyquil/model/provider/rigetti_pyquil_provider.py
|
|
25
|
+
quapp_pyquil.egg-info/PKG-INFO
|
|
26
|
+
quapp_pyquil.egg-info/SOURCES.txt
|
|
27
|
+
quapp_pyquil.egg-info/dependency_links.txt
|
|
28
|
+
quapp_pyquil.egg-info/requires.txt
|
|
29
|
+
quapp_pyquil.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
qapp_pyquil
|