Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[unitaryHACK](#1) Cirq Support #20

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft

[unitaryHACK](#1) Cirq Support #20

wants to merge 2 commits into from

Conversation

harry-stark
Copy link

These are the implementation of CirqBackend , CirqPlatform , CirqJob, CirqCircuit.

Fixes #1


def cx(self, control_qubit: int, target_qubit: int) -> None:
raise NotImplementedError(self.ERROR_MSG)

Copy link
Author

@harry-stark harry-stark May 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Official Implementation of CX, CS are WIP. Also some three-qubit gates too. We can wait until the CIRQ ships them officially.

Comment on lines +71 to +77
"""
@property
def max_qubits(self) -> int:
raise NotImplementedError(self.ERROR_MSG)
return (

)
"""
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't figure out the maximum qubits part. Should we define this explicitly...??

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think that would be a good approach. We have to run the programs on physical backends/simulators, and they will have different capabilities.

Also, have you tested your code? It should not have let you instantiate this class without defining this property.

Copy link
Owner

@pedrorrivero pedrorrivero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you have a first review @harry-stark.

I have a lot of doubts about the code. Do not know the motivation behind many design choices, and do not understand a number of other things. We will need to work hard on this to get it ready.

Importantly: you need to follow the contributing guidelines. You did not. You will need to reset your commit history, since your commit messages do not adhere to Conventinal commits. Before doing so, though, make sure to save a copy of this review outside of GitHub in case it gets deleted.

@@ -19,23 +19,71 @@
## 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.

from cirq_google.engine import Engine
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I the dependency cirq, cirq_google, both, or are they the same? I am saying this to add list it appropriately. Also, did you include any extra depencies?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are different packages and no other extra dependency was used.

Comment on lines +29 to +31



Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally speaking, adhere to the code style in other files. Here, remove unnecessary empty lines.

Comment on lines +33 to +44
"""

Encapsulating Google Engine API with Quantum Backend

Since API and Cirq is still in Alpha,Changes are expected

methods from Engine class:

create_program()->Wraps a Circuit for use with the Quantum Engine. i.e return engineprogram

run()->Runs the supplied Circuit via Quantum Engine. i.e return study.result
"""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not adhere to NumPy's docstring style. See the contributing guidelines.

Comment on lines +48 to +49
shots:int =1,
max_experiments:int=1
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Cirq differentiate between shots and experiments? I thought they only used measurements. In any case, max_shots and max_experiments must be determined by the hardware you are connecting to, while the num_shots, num_experiments, or num_measurements has to be defined in CirqJob.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They use repetitions mainly.

"""
def __init__(
self,
engine: Engine,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you inheriting from Engine and also passing in and storing an Engine object as an attribute? Not necessarily wrong, but definitely not ideal, so just wondering the motivation behind it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought maybe an Engine object had to be instantiated before gcloud authentication.But I think it's not necessary, will fix it in the fresh PR.

from ..circuit import QuantumCircuit

from ...helpers import validate_natural_number, validate_type
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that you are not using validate_type in this module.

Comment on lines +37 to +44
def _validate_qubit_index(self, qubit_index: int) -> None:
if qubit_index >= self.num_qubits:
raise ValueError(
f"Qubit index out of range {qubit_index} >= {self.num_qubits}."
)



Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been added as a QuantumCircuit method. You can get rid of its declaration here. Keep using it though!

Comment on lines +134 to +135
def createcircuit(self):
return CirqQuantumCircuit(self.moment_list)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to inherit from CirqQuantumCircuit and apply the gates to itself: just as it is done in QiskitCircuit. This other technique should be avoided. Therefore you do not need the moment_list attribute.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do it.

Comment on lines -1 to +21
## _____ _____
## | __ \| __ \ AUTHOR: Pedro Rivero
## | |__) | |__) | ---------------------------------
## | ___/| _ / DATE: May 20, 2021
## | | | | \ \ ---------------------------------
## |_| |_| \_\ https://github.com/pedrorrivero
# _____ _____
# | __ \| __ \ AUTHOR: Pedro Rivero
# | |__) | |__) | ---------------------------------
# | ___/| _ / DATE: May 20, 2021
# | | | | \ \ ---------------------------------
# |_| |_| \_\ https://github.com/pedrorrivero
##

## Copyright 2021 Pedro Rivero
# Copyright 2021 Pedro Rivero
##
## 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
# 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
# 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.
# 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.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do this. You are making the style inconsistent across files.

def retrieve_backend(self) -> CirqBackend:
raise NotImplementedError(self.ERROR_MSG)
return CirqBackend(self._backend)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did you define self._backend?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will fix it.

@harry-stark harry-stark marked this pull request as draft May 31, 2021 15:13
@harry-stark
Copy link
Author

@pedrorrivero Well made a lot of rookie mistakes in this one. I will keep this a draft and open a parallel PR with less commit mess and better-tested code, adhering to the contributing guidelines. So we can refer to this review again until it is ready.

@crazy4pi314
Copy link

Hey @harry-stark and @pedrorrivero! I wanted to let folks know I am extending the unitaryHACK deadline till the end of this week for PRs that were already in progress to give some time to iterate with maintainers. Let me know if you have questions, or if I can be of help in getting this issue closed!

@harry-stark
Copy link
Author

@crazy4pi314 Thank you and that's some news. Will try my best to complete this before the weekend but only pain is that Google Qcs API is still private so very less info and working examples to look at. Will push some change soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants