diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index e3a27170eb9..3c3ed0ddab1 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -14,7 +14,7 @@ cirq-ionq/**/*.* @dabacon @ColemanCollins @nakardo @gmauricio @quantumlib/cirq-m cirq-aqt/**/*.* @ma5x @pschindler @alfrisch @quantumlib/cirq-maintainers @vtomole @cduck -cirq-core/cirq/pasqal/**/*.* @HGSilveri @quantumlib/cirq-maintainers @vtomole @cduck +cirq-pasqal/**/*.* @HGSilveri @quantumlib/cirq-maintainers @vtomole @cduck ################################################ # qcvv maintainers @mrwojtek + cirq maintainers diff --git a/check/mypy b/check/mypy index a02c4d873a3..b0e1f141beb 100755 --- a/check/mypy +++ b/check/mypy @@ -19,8 +19,10 @@ for arg in $@; do fi done +CIRQ_PACKAGES=$(env PYTHONPATH=. python dev_tools/modules.py list --mode package-path) + echo -e -n "\033[31m" -mypy --config-file=dev_tools/conf/mypy.ini $@ cirq-google/cirq_google cirq-core/cirq dev_tools +mypy --config-file=dev_tools/conf/mypy.ini $@ $CIRQ_PACKAGES dev_tools examples result=$? echo -e -n "\033[0m" diff --git a/cirq-core/cirq/__init__.py b/cirq-core/cirq/__init__.py index 79c8549fce6..7f24d5808d0 100644 --- a/cirq-core/cirq/__init__.py +++ b/cirq-core/cirq/__init__.py @@ -580,7 +580,6 @@ # Unflattened sub-modules. from cirq import ( - pasqal, testing, ) @@ -622,6 +621,19 @@ warning("Can't import cirq_ionq: ", exc_info=ex) +try: + _compat.deprecated_submodule( + new_module_name='cirq_pasqal', + old_parent=__name__, + old_child='pasqal', + deadline="v0.14", + create_attribute=True, + ) +except ImportError as ex: + # coverage: ignore + warning("Can't import cirq_pasqal: ", exc_info=ex) + + def _register_resolver() -> None: """Registers the cirq module's public classes for JSON serialization.""" from cirq.protocols.json_serialization import _internal_register_resolver diff --git a/cirq-core/cirq/json_resolver_cache.py b/cirq-core/cirq/json_resolver_cache.py index 8a3b699d67e..33a6848ed65 100644 --- a/cirq-core/cirq/json_resolver_cache.py +++ b/cirq-core/cirq/json_resolver_cache.py @@ -108,8 +108,6 @@ def two_qubit_matrix_gate(matrix): '_PauliY': cirq.ops.pauli_gates._PauliY, '_PauliZ': cirq.ops.pauli_gates._PauliZ, 'ParamResolver': cirq.ParamResolver, - 'PasqalDevice': cirq.pasqal.PasqalDevice, - 'PasqalVirtualDevice': cirq.pasqal.PasqalVirtualDevice, 'ParallelGateOperation': cirq.ParallelGateOperation, 'PauliString': cirq.PauliString, 'PhaseDampingChannel': cirq.PhaseDampingChannel, @@ -130,12 +128,10 @@ def two_qubit_matrix_gate(matrix): 'SwapPowGate': cirq.SwapPowGate, 'SymmetricalQidPair': cirq.SymmetricalQidPair, 'TaggedOperation': cirq.TaggedOperation, - 'ThreeDQubit': cirq.pasqal.ThreeDQubit, 'Result': cirq.Result, 'Rx': cirq.Rx, 'Ry': cirq.Ry, 'Rz': cirq.Rz, - 'TwoDQubit': cirq.pasqal.TwoDQubit, 'TwoQubitMatrixGate': two_qubit_matrix_gate, '_UnconstrainedDevice': cirq.devices.unconstrained_device._UnconstrainedDevice, 'VarianceStoppingCriteria': cirq.work.VarianceStoppingCriteria, diff --git a/cirq-core/cirq/protocols/json_serialization_test.py b/cirq-core/cirq/protocols/json_serialization_test.py index 05db080ceb7..6dcedfaf2f1 100644 --- a/cirq-core/cirq/protocols/json_serialization_test.py +++ b/cirq-core/cirq/protocols/json_serialization_test.py @@ -62,6 +62,12 @@ class _ModuleDeprecation: "cirq.google", deadline="v0.14", count=None ), ), + 'cirq_pasqal': _ModuleDeprecation( + old_name="cirq.pasqal", + deprecation_assertion=cirq.testing.assert_deprecated( + "cirq.pasqal", deadline="v0.14", count=None + ), + ), 'cirq.protocols': None, 'non_existent_should_be_fine': None, } @@ -597,6 +603,13 @@ def _eval_repr_data_file(path: pathlib.Path, deprecation_deadline: Optional[str] except ImportError: pass + try: + import cirq_pasqal + + imports['cirq_pasqal'] = cirq_pasqal + except ImportError: + pass + with contextlib.ExitStack() as stack: for ctx_manager in ctx_managers: stack.enter_context(ctx_manager) diff --git a/cirq-pasqal/LICENSE b/cirq-pasqal/LICENSE new file mode 100644 index 00000000000..8dada3edaf5 --- /dev/null +++ b/cirq-pasqal/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/cirq-pasqal/README.rst b/cirq-pasqal/README.rst new file mode 100644 index 00000000000..fc32146a693 --- /dev/null +++ b/cirq-pasqal/README.rst @@ -0,0 +1,27 @@ +.. image:: https://upload.wikimedia.org/wikipedia/en/thumb/d/d4/pasqal_corp_logo.svg/2560px-pasqal_corp_logo.svg.png + :target: https://github.com/quantumlib/cirq/ + :alt: cirq-pasqal + :width: 500px + +`Cirq `__ is a Python library for writing, manipulating, and optimizing quantum +circuits and running them against quantum computers and simulators. + +This module is **cirq-pasqal**, which provides everything you'll need to run Cirq quantum algorithms on pasqal quantum computers. + +Documentation +------------- + +To get started with pasqal quantum computing services, checkout the following guide and tutorial: + +- `Access and authentication `__ +- `Getting started guide `__ + +Installation +------------ + +To install the stable version of only **cirq-pasqal**, use `pip install cirq-pasqal`. +To install the pre-release version of only **cirq-pasqal**, use `pip install cirq-pasqal --pre`. + +Note, that this will install both **cirq-pasqal** and **cirq-core**. + +To get all the optional modules installed, you'll have to use `pip install cirq` or `pip install cirq --pre` for the pre-release version. diff --git a/cirq-pasqal/cirq_pasqal/__init__.py b/cirq-pasqal/cirq_pasqal/__init__.py new file mode 100644 index 00000000000..40aad252053 --- /dev/null +++ b/cirq-pasqal/cirq_pasqal/__init__.py @@ -0,0 +1,44 @@ +# Copyright 2021 The Cirq Developers +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Devices, qubits, and sampler for Pasqal's neutral atom device.""" + +from cirq_pasqal.pasqal_qubits import ( + ThreeDQubit, + TwoDQubit, +) + +from cirq_pasqal.pasqal_device import ( + PasqalDevice, + PasqalVirtualDevice, +) + +from cirq_pasqal.pasqal_noise_model import ( + PasqalNoiseModel, +) + +from cirq_pasqal.pasqal_sampler import ( + PasqalSampler, +) + + +def _register_resolver() -> None: + """Registers the cirq_google's public classes for JSON serialization.""" + from cirq.protocols.json_serialization import _internal_register_resolver + from cirq_pasqal.json_resolver_cache import _class_resolver_dictionary + + _internal_register_resolver(_class_resolver_dictionary) + + +_register_resolver() diff --git a/cirq-pasqal/cirq_pasqal/_version.py b/cirq-pasqal/cirq_pasqal/_version.py new file mode 100644 index 00000000000..941bf941f5d --- /dev/null +++ b/cirq-pasqal/cirq_pasqal/_version.py @@ -0,0 +1,17 @@ +# Copyright 2021 The Cirq Developers +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Define version number here, read it from setup.py automatically""" + +__version__ = "0.12.0.dev" diff --git a/cirq-pasqal/cirq_pasqal/json_resolver_cache.py b/cirq-pasqal/cirq_pasqal/json_resolver_cache.py new file mode 100644 index 00000000000..6adb2678d7b --- /dev/null +++ b/cirq-pasqal/cirq_pasqal/json_resolver_cache.py @@ -0,0 +1,29 @@ +# Copyright 2021 The Cirq Developers +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import functools +from typing import Dict + +import cirq_pasqal +from cirq.protocols.json_serialization import ObjectFactory + + +@functools.lru_cache(maxsize=1) +def _class_resolver_dictionary() -> Dict[str, ObjectFactory]: + return { + 'PasqalDevice': cirq_pasqal.PasqalDevice, + 'PasqalVirtualDevice': cirq_pasqal.PasqalVirtualDevice, + 'ThreeDQubit': cirq_pasqal.ThreeDQubit, + 'TwoDQubit': cirq_pasqal.TwoDQubit, + } diff --git a/cirq-core/cirq/protocols/json_test_data/PasqalDevice.json b/cirq-pasqal/cirq_pasqal/json_test_data/PasqalDevice.json similarity index 100% rename from cirq-core/cirq/protocols/json_test_data/PasqalDevice.json rename to cirq-pasqal/cirq_pasqal/json_test_data/PasqalDevice.json diff --git a/cirq-pasqal/cirq_pasqal/json_test_data/PasqalDevice.json_inward b/cirq-pasqal/cirq_pasqal/json_test_data/PasqalDevice.json_inward new file mode 100644 index 00000000000..b348a2f68bc --- /dev/null +++ b/cirq-pasqal/cirq_pasqal/json_test_data/PasqalDevice.json_inward @@ -0,0 +1,9 @@ +{ + "cirq_type": "PasqalDevice", + "qubits": [ + { + "cirq_type": "NamedQubit", + "name": "q0" + } + ] +} diff --git a/cirq-pasqal/cirq_pasqal/json_test_data/PasqalDevice.repr b/cirq-pasqal/cirq_pasqal/json_test_data/PasqalDevice.repr new file mode 100644 index 00000000000..e795593dbe5 --- /dev/null +++ b/cirq-pasqal/cirq_pasqal/json_test_data/PasqalDevice.repr @@ -0,0 +1,3 @@ +cirq_pasqal.PasqalDevice( + qubits=[cirq.NamedQubit('q0')] +) diff --git a/cirq-core/cirq/protocols/json_test_data/PasqalDevice.repr b/cirq-pasqal/cirq_pasqal/json_test_data/PasqalDevice.repr_inward similarity index 100% rename from cirq-core/cirq/protocols/json_test_data/PasqalDevice.repr rename to cirq-pasqal/cirq_pasqal/json_test_data/PasqalDevice.repr_inward diff --git a/cirq-core/cirq/protocols/json_test_data/PasqalVirtualDevice.json b/cirq-pasqal/cirq_pasqal/json_test_data/PasqalVirtualDevice.json similarity index 100% rename from cirq-core/cirq/protocols/json_test_data/PasqalVirtualDevice.json rename to cirq-pasqal/cirq_pasqal/json_test_data/PasqalVirtualDevice.json diff --git a/cirq-pasqal/cirq_pasqal/json_test_data/PasqalVirtualDevice.json_inward b/cirq-pasqal/cirq_pasqal/json_test_data/PasqalVirtualDevice.json_inward new file mode 100644 index 00000000000..1dd6a50b940 --- /dev/null +++ b/cirq-pasqal/cirq_pasqal/json_test_data/PasqalVirtualDevice.json_inward @@ -0,0 +1,12 @@ +{ + "cirq_type": "PasqalVirtualDevice", + "control_radius": 3, + "qubits": [ + { + "cirq_type": "ThreeDQubit", + "x": 1, + "y": 1, + "z": 1 + } + ] +} diff --git a/cirq-pasqal/cirq_pasqal/json_test_data/PasqalVirtualDevice.repr b/cirq-pasqal/cirq_pasqal/json_test_data/PasqalVirtualDevice.repr new file mode 100644 index 00000000000..6d8cf729790 --- /dev/null +++ b/cirq-pasqal/cirq_pasqal/json_test_data/PasqalVirtualDevice.repr @@ -0,0 +1,4 @@ +cirq_pasqal.PasqalVirtualDevice( + control_radius=3, + qubits=[cirq_pasqal.ThreeDQubit(1, 1, 1)] +) diff --git a/cirq-core/cirq/protocols/json_test_data/PasqalVirtualDevice.repr b/cirq-pasqal/cirq_pasqal/json_test_data/PasqalVirtualDevice.repr_inward similarity index 100% rename from cirq-core/cirq/protocols/json_test_data/PasqalVirtualDevice.repr rename to cirq-pasqal/cirq_pasqal/json_test_data/PasqalVirtualDevice.repr_inward diff --git a/cirq-core/cirq/protocols/json_test_data/ThreeDQubit.json b/cirq-pasqal/cirq_pasqal/json_test_data/ThreeDQubit.json similarity index 100% rename from cirq-core/cirq/protocols/json_test_data/ThreeDQubit.json rename to cirq-pasqal/cirq_pasqal/json_test_data/ThreeDQubit.json diff --git a/cirq-pasqal/cirq_pasqal/json_test_data/ThreeDQubit.json_inward b/cirq-pasqal/cirq_pasqal/json_test_data/ThreeDQubit.json_inward new file mode 100644 index 00000000000..4aad6ef521a --- /dev/null +++ b/cirq-pasqal/cirq_pasqal/json_test_data/ThreeDQubit.json_inward @@ -0,0 +1,6 @@ +{ + "cirq_type": "ThreeDQubit", + "x": 10, + "y": 11, + "z": 12 +} diff --git a/cirq-pasqal/cirq_pasqal/json_test_data/ThreeDQubit.repr b/cirq-pasqal/cirq_pasqal/json_test_data/ThreeDQubit.repr new file mode 100644 index 00000000000..ae355ad98a4 --- /dev/null +++ b/cirq-pasqal/cirq_pasqal/json_test_data/ThreeDQubit.repr @@ -0,0 +1 @@ +cirq_pasqal.ThreeDQubit(10, 11, 12) diff --git a/cirq-core/cirq/protocols/json_test_data/ThreeDQubit.repr b/cirq-pasqal/cirq_pasqal/json_test_data/ThreeDQubit.repr_inward similarity index 100% rename from cirq-core/cirq/protocols/json_test_data/ThreeDQubit.repr rename to cirq-pasqal/cirq_pasqal/json_test_data/ThreeDQubit.repr_inward diff --git a/cirq-core/cirq/protocols/json_test_data/TwoDQubit.json b/cirq-pasqal/cirq_pasqal/json_test_data/TwoDQubit.json similarity index 100% rename from cirq-core/cirq/protocols/json_test_data/TwoDQubit.json rename to cirq-pasqal/cirq_pasqal/json_test_data/TwoDQubit.json diff --git a/cirq-pasqal/cirq_pasqal/json_test_data/TwoDQubit.json_inward b/cirq-pasqal/cirq_pasqal/json_test_data/TwoDQubit.json_inward new file mode 100644 index 00000000000..9e6b06f3f3e --- /dev/null +++ b/cirq-pasqal/cirq_pasqal/json_test_data/TwoDQubit.json_inward @@ -0,0 +1,5 @@ +{ + "cirq_type": "TwoDQubit", + "x": 10, + "y": 11 +} diff --git a/cirq-pasqal/cirq_pasqal/json_test_data/TwoDQubit.repr b/cirq-pasqal/cirq_pasqal/json_test_data/TwoDQubit.repr new file mode 100644 index 00000000000..04837d811b7 --- /dev/null +++ b/cirq-pasqal/cirq_pasqal/json_test_data/TwoDQubit.repr @@ -0,0 +1 @@ +cirq_pasqal.TwoDQubit(10, 11) diff --git a/cirq-core/cirq/protocols/json_test_data/TwoDQubit.repr b/cirq-pasqal/cirq_pasqal/json_test_data/TwoDQubit.repr_inward similarity index 100% rename from cirq-core/cirq/protocols/json_test_data/TwoDQubit.repr rename to cirq-pasqal/cirq_pasqal/json_test_data/TwoDQubit.repr_inward diff --git a/cirq-core/cirq/pasqal/__init__.py b/cirq-pasqal/cirq_pasqal/json_test_data/__init__.py similarity index 57% rename from cirq-core/cirq/pasqal/__init__.py rename to cirq-pasqal/cirq_pasqal/json_test_data/__init__.py index c353c3fd183..1377c9b5bbf 100644 --- a/cirq-core/cirq/pasqal/__init__.py +++ b/cirq-pasqal/cirq_pasqal/json_test_data/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2020 The Cirq Developers +# Copyright 2021 The Cirq Developers # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,21 +11,10 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -"""Devices, qubits, and sampler for Pasqal's neutrali atom device.""" -from cirq.pasqal.pasqal_qubits import ( - ThreeDQubit, - TwoDQubit, -) -from cirq.pasqal.pasqal_device import ( - PasqalDevice, - PasqalVirtualDevice, -) +# For the cirq_pasqal module, this file specifies test data for JSON +# serialization of public objects. It is used by +# cirq/protocols/json_serialization_test.py which checks for coverage of +# public classes and tests the correctness of repr and json results -from cirq.pasqal.pasqal_noise_model import ( - PasqalNoiseModel, -) - -from cirq.pasqal.pasqal_sampler import ( - PasqalSampler, -) +from cirq_pasqal.json_test_data.spec import TestSpec diff --git a/cirq-pasqal/cirq_pasqal/json_test_data/spec.py b/cirq-pasqal/cirq_pasqal/json_test_data/spec.py new file mode 100644 index 00000000000..2e8c7e48581 --- /dev/null +++ b/cirq-pasqal/cirq_pasqal/json_test_data/spec.py @@ -0,0 +1,39 @@ +# Copyright 2021 The Cirq Developers +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""The cirq-pasqal test specification for JSON serialization tests. + +The actual tests live in cirq.protocols.json_serialization_test.py. +See cirq-core/cirq/testing/json.py for a description of the framework. +""" + +import pathlib + +import cirq_pasqal +from cirq_pasqal.json_resolver_cache import _class_resolver_dictionary + +from cirq.testing.json import ModuleJsonTestSpec + +TestSpec = ModuleJsonTestSpec( + name="cirq_pasqal", + packages=[cirq_pasqal], + test_data_path=pathlib.Path(__file__).parent, + not_yet_serializable=[], + should_not_be_serialized=[ + "PasqalNoiseModel", + "PasqalSampler", + ], + resolver_cache=_class_resolver_dictionary(), + deprecated={}, +) diff --git a/cirq-core/cirq/pasqal/pasqal_device.py b/cirq-pasqal/cirq_pasqal/pasqal_device.py similarity index 99% rename from cirq-core/cirq/pasqal/pasqal_device.py rename to cirq-pasqal/cirq_pasqal/pasqal_device.py index ff6de05f1b8..417e616cf4e 100644 --- a/cirq-core/cirq/pasqal/pasqal_device.py +++ b/cirq-pasqal/cirq_pasqal/pasqal_device.py @@ -18,7 +18,7 @@ import cirq from cirq import GridQubit, LineQubit from cirq.ops import NamedQubit -from cirq.pasqal import ThreeDQubit, TwoDQubit +from cirq_pasqal import ThreeDQubit, TwoDQubit @cirq.value.value_equality diff --git a/cirq-core/cirq/pasqal/pasqal_device_test.py b/cirq-pasqal/cirq_pasqal/pasqal_device_test.py similarity index 98% rename from cirq-core/cirq/pasqal/pasqal_device_test.py rename to cirq-pasqal/cirq_pasqal/pasqal_device_test.py index 8c3c6e4ad36..9bcc13f031e 100644 --- a/cirq-core/cirq/pasqal/pasqal_device_test.py +++ b/cirq-pasqal/cirq_pasqal/pasqal_device_test.py @@ -16,9 +16,10 @@ import numpy as np import cirq +import cirq_pasqal -from cirq.pasqal import PasqalDevice, PasqalVirtualDevice -from cirq.pasqal import TwoDQubit, ThreeDQubit +from cirq_pasqal import PasqalDevice, PasqalVirtualDevice +from cirq_pasqal import TwoDQubit, ThreeDQubit def generic_device(num_qubits) -> PasqalDevice: @@ -276,7 +277,7 @@ def test_to_json(): assert d == { "cirq_type": "PasqalVirtualDevice", "control_radius": 2, - "qubits": [cirq.pasqal.TwoDQubit(0, 0)], + "qubits": [cirq_pasqal.TwoDQubit(0, 0)], } diff --git a/cirq-core/cirq/pasqal/pasqal_noise_model.py b/cirq-pasqal/cirq_pasqal/pasqal_noise_model.py similarity index 97% rename from cirq-core/cirq/pasqal/pasqal_noise_model.py rename to cirq-pasqal/cirq_pasqal/pasqal_noise_model.py index 15a2b4ccafb..719a95656f8 100644 --- a/cirq-core/cirq/pasqal/pasqal_noise_model.py +++ b/cirq-pasqal/cirq_pasqal/pasqal_noise_model.py @@ -14,6 +14,7 @@ from typing import List, Dict, Sequence, Any import cirq +import cirq_pasqal class PasqalNoiseModel(cirq.devices.NoiseModel): @@ -21,7 +22,7 @@ class PasqalNoiseModel(cirq.devices.NoiseModel): def __init__(self, device: cirq.devices.Device): self.noise_op_dict = self.get_default_noise_dict() - if not isinstance(device, cirq.pasqal.PasqalDevice): + if not isinstance(device, cirq_pasqal.PasqalDevice): raise TypeError( "The noise model varies between Pasqal's devices. " "Please specify the one you intend to execute the " diff --git a/cirq-core/cirq/pasqal/pasqal_noise_model_test.py b/cirq-pasqal/cirq_pasqal/pasqal_noise_model_test.py similarity index 97% rename from cirq-core/cirq/pasqal/pasqal_noise_model_test.py rename to cirq-pasqal/cirq_pasqal/pasqal_noise_model_test.py index 6dec946f5a9..d6668ab134c 100644 --- a/cirq-core/cirq/pasqal/pasqal_noise_model_test.py +++ b/cirq-pasqal/cirq_pasqal/pasqal_noise_model_test.py @@ -14,11 +14,11 @@ import pytest import cirq -from cirq.pasqal import PasqalNoiseModel, PasqalDevice +from cirq_pasqal import PasqalNoiseModel, PasqalDevice from cirq.ops import NamedQubit -def test_NoiseModel_init(): +def test_noise_model_init(): noise_model = PasqalNoiseModel(PasqalDevice([])) assert noise_model.noise_op_dict == { str(cirq.ops.YPowGate()): cirq.ops.depolarize(1e-2), diff --git a/cirq-core/cirq/pasqal/pasqal_qubits.py b/cirq-pasqal/cirq_pasqal/pasqal_qubits.py similarity index 100% rename from cirq-core/cirq/pasqal/pasqal_qubits.py rename to cirq-pasqal/cirq_pasqal/pasqal_qubits.py diff --git a/cirq-core/cirq/pasqal/pasqal_qubits_test.py b/cirq-pasqal/cirq_pasqal/pasqal_qubits_test.py similarity index 92% rename from cirq-core/cirq/pasqal/pasqal_qubits_test.py rename to cirq-pasqal/cirq_pasqal/pasqal_qubits_test.py index bd0ad11b305..7d506cc4f30 100644 --- a/cirq-core/cirq/pasqal/pasqal_qubits_test.py +++ b/cirq-pasqal/cirq_pasqal/pasqal_qubits_test.py @@ -15,23 +15,23 @@ import numpy as np import cirq -from cirq.pasqal import ThreeDQubit, TwoDQubit +from cirq_pasqal import ThreeDQubit, TwoDQubit -def test_pasqal_qubit_init_3D(): +def test_pasqal_qubit_init_3d(): q = ThreeDQubit(3, 4, 5) assert q.x == 3 assert q.y == 4 assert q.z == 5 -def test_comparison_key_3D(): +def test_comparison_key_3d(): assert ThreeDQubit(3, 4, 5)._comparison_key() == (5, 4, 3) coords = (np.cos(np.pi / 2), np.sin(np.pi / 2), 0) assert ThreeDQubit(*coords) == ThreeDQubit(0, 1, 0) -def test_pasqal_qubit_ordering_3D(): +def test_pasqal_qubit_ordering_3d(): assert ThreeDQubit(0, 0, 1) >= ThreeDQubit(1, 0, 0) assert ThreeDQubit(0, 0, 1) >= ThreeDQubit(0, 1, 0) assert ThreeDQubit(0, 1, 0) >= ThreeDQubit(1, 0, 0) @@ -47,7 +47,7 @@ def test_pasqal_qubit_ordering_3D(): assert ThreeDQubit(1, 1, 1) > ThreeDQubit(v[0], v[1], v[2]) -def test_distance_3D(): +def test_distance_3d(): with pytest.raises(TypeError): _ = ThreeDQubit(0, 0, 0).distance(cirq.GridQubit(0, 0)) @@ -59,7 +59,7 @@ def test_distance_3D(): ) -def test_grid_qubit_eq_3D(): +def test_grid_qubit_eq_3d(): eq = cirq.testing.EqualsTester() eq.make_equality_group(lambda: ThreeDQubit(0, 0, 0)) eq.make_equality_group(lambda: ThreeDQubit(1, 0, 0)) @@ -67,7 +67,7 @@ def test_grid_qubit_eq_3D(): eq.make_equality_group(lambda: ThreeDQubit(50, 25, 25)) -def test_cube_3D(): +def test_cube_3d(): assert ThreeDQubit.cube(2, x0=1, y0=1, z0=1) == [ ThreeDQubit(1, 1, 1), ThreeDQubit(2, 1, 1), @@ -90,7 +90,7 @@ def test_cube_3D(): ] -def test_parrallelep_3D(): +def test_parallelep_3d(): assert ThreeDQubit.parallelep(1, 2, 2, x0=5, y0=6, z0=7) == [ ThreeDQubit(5, 6, 7), ThreeDQubit(5, 7, 7), @@ -110,7 +110,7 @@ def test_parrallelep_3D(): ] -def test_square_2D(): +def test_square_2d(): assert TwoDQubit.square(2, x0=1, y0=1) == [ TwoDQubit(1, 1), TwoDQubit(2, 1), @@ -125,7 +125,7 @@ def test_square_2D(): ] -def test_rec_2D(): +def test_rec_2d(): assert TwoDQubit.rect(1, 2, x0=5, y0=6) == [TwoDQubit(5, 6), TwoDQubit(5, 7)] assert TwoDQubit.rect(2, 2) == [ TwoDQubit(0, 0), @@ -135,7 +135,7 @@ def test_rec_2D(): ] -def test_triangular_2D(): +def test_triangular_2d(): assert TwoDQubit.triangular_lattice(1) == [ TwoDQubit(0.0, 0.0), TwoDQubit(0.5, 0.8660254037844386), @@ -151,17 +151,17 @@ def test_triangular_2D(): ] -def test_repr_(): +def test_repr(): assert repr(ThreeDQubit(4, -25, 109)) == 'pasqal.ThreeDQubit(4, -25, 109)' assert repr(TwoDQubit(4, -25)) == 'pasqal.TwoDQubit(4, -25)' -def test_str_(): +def test_str(): assert str(ThreeDQubit(4, -25, 109)) == '(4, -25, 109)' assert str(TwoDQubit(4, -25)) == '(4, -25)' -def test_to_json_(): +def test_to_json(): q = ThreeDQubit(1.3, 1, 1) d = q._json_dict_() assert d == { diff --git a/cirq-core/cirq/pasqal/pasqal_sampler.py b/cirq-pasqal/cirq_pasqal/pasqal_sampler.py similarity index 98% rename from cirq-core/cirq/pasqal/pasqal_sampler.py rename to cirq-pasqal/cirq_pasqal/pasqal_sampler.py index 1bb56bc94ec..375430dd648 100644 --- a/cirq-core/cirq/pasqal/pasqal_sampler.py +++ b/cirq-pasqal/cirq_pasqal/pasqal_sampler.py @@ -17,6 +17,7 @@ import requests import cirq +import cirq_pasqal class PasqalSampler(cirq.work.Sampler): @@ -110,7 +111,7 @@ def run_sweep( Result list for this run; one for each possible parameter resolver. """ - assert isinstance(program.device, cirq.pasqal.PasqalDevice) + assert isinstance(program.device, cirq_pasqal.PasqalDevice) program.device.validate_circuit(program) trial_results = [] diff --git a/cirq-core/cirq/pasqal/pasqal_sampler_test.py b/cirq-pasqal/cirq_pasqal/pasqal_sampler_test.py similarity index 87% rename from cirq-core/cirq/pasqal/pasqal_sampler_test.py rename to cirq-pasqal/cirq_pasqal/pasqal_sampler_test.py index f0b927de1b8..82af90c8213 100644 --- a/cirq-core/cirq/pasqal/pasqal_sampler_test.py +++ b/cirq-pasqal/cirq_pasqal/pasqal_sampler_test.py @@ -18,6 +18,7 @@ import pytest import cirq +import cirq_pasqal class MockGet: @@ -35,9 +36,9 @@ def text(self): return self.json -def _make_sampler() -> cirq.pasqal.PasqalSampler: +def _make_sampler() -> cirq_pasqal.PasqalSampler: - sampler = cirq.pasqal.PasqalSampler(remote_host='http://00.00.00/', access_token='N/A') + sampler = cirq_pasqal.PasqalSampler(remote_host='http://00.00.00/', access_token='N/A') return sampler @@ -45,7 +46,7 @@ def test_pasqal_circuit_init(): qs = cirq.NamedQubit.range(3, prefix='q') ex_circuit = cirq.Circuit() ex_circuit.append([[cirq.CZ(qs[i], qs[i + 1]), cirq.X(qs[i + 1])] for i in range(len(qs) - 1)]) - device = cirq.pasqal.PasqalDevice(qubits=qs) + device = cirq_pasqal.PasqalDevice(qubits=qs) test_circuit = cirq.Circuit(device=device) test_circuit.append( [[cirq.CZ(qs[i], qs[i + 1]), cirq.X(qs[i + 1])] for i in range(len(qs) - 1)] @@ -55,15 +56,15 @@ def test_pasqal_circuit_init(): assert moment1 == moment2 -@patch('cirq.pasqal.pasqal_sampler.requests.get') -@patch('cirq.pasqal.pasqal_sampler.requests.post') +@patch('cirq_pasqal.pasqal_sampler.requests.get') +@patch('cirq_pasqal.pasqal_sampler.requests.post') def test_run_sweep(mock_post, mock_get): """ Encodes a random binary number in the qubits, sweeps between odd and even without noise and checks if the results match. """ - qs = [cirq.pasqal.ThreeDQubit(i, j, 0) for i in range(3) for j in range(3)] + qs = [cirq_pasqal.ThreeDQubit(i, j, 0) for i in range(3) for j in range(3)] par = sympy.Symbol('par') sweep = cirq.Linspace(key='par', start=0.0, stop=1.0, length=2) @@ -71,7 +72,7 @@ def test_run_sweep(mock_post, mock_get): num = np.random.randint(0, 2 ** 9) binary = bin(num)[2:].zfill(9) - device = cirq.pasqal.PasqalVirtualDevice(control_radius=1, qubits=qs) + device = cirq_pasqal.PasqalVirtualDevice(control_radius=1, qubits=qs) ex_circuit = cirq.Circuit(device=device) for i, b in enumerate(binary[:-1]): diff --git a/cirq-pasqal/requirements.txt b/cirq-pasqal/requirements.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/cirq-pasqal/setup.cfg b/cirq-pasqal/setup.cfg new file mode 100644 index 00000000000..0c9e0fc1447 --- /dev/null +++ b/cirq-pasqal/setup.cfg @@ -0,0 +1,2 @@ +[metadata] +license_file = LICENSE diff --git a/cirq-pasqal/setup.py b/cirq-pasqal/setup.py new file mode 100644 index 00000000000..56b11c628ca --- /dev/null +++ b/cirq-pasqal/setup.py @@ -0,0 +1,70 @@ +# Copyright 2021 The Cirq Developers +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import io +import os +from setuptools import find_packages, setup + +# This reads the __version__ variable from cirq/_version.py +__version__ = '' +exec(open('cirq_pasqal/_version.py').read()) + +name = 'cirq-pasqal' + +description = 'A Cirq package to simulate and connect to Pasqal quantum computers' + +# README file as long_description. +long_description = io.open('README.rst', encoding='utf-8').read() + +# If CIRQ_PRE_RELEASE_VERSION is set then we update the version to this value. +# It is assumed that it ends with one of `.devN`, `.aN`, `.bN`, `.rcN` and hence +# it will be a pre-release version on PyPi. See +# https://packaging.python.org/guides/distributing-packages-using-setuptools/#pre-release-versioning +# for more details. +if 'CIRQ_PRE_RELEASE_VERSION' in os.environ: + __version__ = os.environ['CIRQ_PRE_RELEASE_VERSION'] + long_description = ( + "**This is a development version of Cirq-pasqal and may be " + "unstable.**\n\n**For the latest stable release of Cirq-pasqal " + "see**\n`here `__.\n\n" + long_description + ) + +# Read in requirements +requirements = open('requirements.txt').readlines() +requirements = [r.strip() for r in requirements] + +cirq_packages = ['cirq_pasqal'] + [ + 'cirq_pasqal.' + package for package in find_packages(where='cirq_pasqal') +] + +# Sanity check +assert __version__, 'Version string cannot be empty' + +setup( + name=name, + version=__version__, + url='http://github.com/quantumlib/cirq', + author='The Cirq Developers', + author_email='cirq-dev@googlegroups.com', + python_requires='>=3.6.0', + install_requires=requirements, + license='Apache 2', + description=description, + long_description=long_description, + packages=cirq_packages, + package_data={ + 'cirq_pasqal': ['py.typed'], + 'cirq_pasqal.json_test_data': ['*'], + }, +) diff --git a/dev_tools/codeowners_test.py b/dev_tools/codeowners_test.py index 69d373ac176..bd535179ecb 100644 --- a/dev_tools/codeowners_test.py +++ b/dev_tools/codeowners_test.py @@ -49,20 +49,27 @@ ("cirq-core/setup.py", BASE_MAINTAINERS), ("cirq-core/cirq/contrib/__init__.py", BASE_MAINTAINERS), ("docs/_book.yaml", DOCS_MAINTAINERS), + # qcvv ("cirq-core/cirq/experiments/__init__.py", QCVV_MAINTAINERS), ("docs/qcvv/isolated_xeb.ipynb", QCVV_MAINTAINERS.union(DOCS_MAINTAINERS)), + # aqt ("cirq-aqt/cirq_aqt/__init__.py", AQT_MAINTAINERS), ("cirq-aqt/setup.py", AQT_MAINTAINERS), ("docs/aqt/access.md", AQT_MAINTAINERS.union(DOCS_MAINTAINERS)), ("docs/tutorials/aqt/getting_started.ipynb", AQT_MAINTAINERS.union(DOCS_MAINTAINERS)), - ("cirq-core/cirq/pasqal/__init__.py", PASQAL_MAINTAINERS), + # pasqal + ("cirq-pasqal/cirq_pasqal/__init__.py", PASQAL_MAINTAINERS), + ("cirq-pasqal/setup.py", PASQAL_MAINTAINERS), ("docs/pasqal/access.md", PASQAL_MAINTAINERS.union(DOCS_MAINTAINERS)), ("docs/tutorials/pasqal/getting_started.ipynb", PASQAL_MAINTAINERS.union(DOCS_MAINTAINERS)), + # ionq ("cirq-ionq/cirq_ionq/__init__.py", IONQ_MAINTAINERS), ("cirq-ionq/setup.py", IONQ_MAINTAINERS), ("docs/ionq/access.md", IONQ_MAINTAINERS.union(DOCS_MAINTAINERS)), ("docs/tutorials/ionq/getting_started.ipynb", IONQ_MAINTAINERS.union(DOCS_MAINTAINERS)), + # google ("cirq-google/cirq_google/__init__.py", GOOGLE_MAINTAINERS), + ("cirq-google/setup.py", GOOGLE_MAINTAINERS), ("docs/google/access.md", GOOGLE_MAINTAINERS.union(DOCS_MAINTAINERS)), ("docs/tutorials/google/start.ipynb", GOOGLE_MAINTAINERS.union(DOCS_MAINTAINERS)), ],