-
Notifications
You must be signed in to change notification settings - Fork 14
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
base: dev
Are you sure you want to change the base?
Conversation
|
||
def cx(self, control_qubit: int, target_qubit: int) -> None: | ||
raise NotImplementedError(self.ERROR_MSG) | ||
|
There was a problem hiding this comment.
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.
""" | ||
@property | ||
def max_qubits(self) -> int: | ||
raise NotImplementedError(self.ERROR_MSG) | ||
return ( | ||
|
||
) | ||
""" |
There was a problem hiding this comment.
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...??
There was a problem hiding this comment.
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.
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
|
||
|
||
|
There was a problem hiding this comment.
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.
""" | ||
|
||
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 | ||
""" |
There was a problem hiding this comment.
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.
shots:int =1, | ||
max_experiments:int=1 |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
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}." | ||
) | ||
|
||
|
||
|
There was a problem hiding this comment.
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!
def createcircuit(self): | ||
return CirqQuantumCircuit(self.moment_list) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do it.
## _____ _____ | ||
## | __ \| __ \ 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. |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will fix it.
@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. |
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! |
@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. |
These are the implementation of
CirqBackend
,CirqPlatform
,CirqJob
,CirqCircuit
.Fixes #1