-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[WIP] NoCompile Tag for optimizers #4298
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
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@googlebot I signed it! |
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
Keeping log of changes drop_negligible with testing |
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 would be really cool if we could have a more general testing util that makes sure that every compiler doesn't get affected by NoCompileTag.
|
||
|
||
class NoCompileTag: | ||
"""A TaggedOperation tag indicating that the operation is virtual. |
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.
Fix description. This docstring is taken from VirtualTag
|
||
def test_nocompile_tag(): | ||
tag1 = cirq.ops.VirtualTag() | ||
tag2 = cirq.ops.VirtualTag() |
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.
Fix from virtual.
# circuit.append(op, strategy=InsertStrategy.EARLIEST) | ||
# else: | ||
# circuit.append(op) | ||
# circuit=circuit_new |
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.
Delete commented code.
@@ -38,6 +39,7 @@ def optimize_circuit(self, circuit: _circuit.Circuit) -> None: | |||
for op in moment.operations: | |||
if protocols.is_measurement(op): | |||
continue | |||
if protocols.trace_distance_bound(op) <= self.tolerance: | |||
deletions.append((moment_index, op)) | |||
if NoCompileTag not in op.tags: |
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.
Can combine these two conditions:
if protocols.is_measurement(op) or NoCompileTag in op.tags:
continue
# 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 delete copyright please.
@@ -63,52 +64,53 @@ def optimize_circuit(self, circuit: circuits.Circuit): | |||
|
|||
for moment_index, moment in enumerate(circuit): | |||
for op in moment.operations: | |||
affected = [q for q in op.qubits if q in state.held_w_phases] | |||
if NoCompileTag not in op.tags: |
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 would probably be consistent with above and say
if NoCompileTag in op.tags:
continue
This avoids the negative condition and makes the change cleaner since all indentation doesn't change.
|
||
circuit.batch_remove(state.deletions) | ||
circuit.batch_insert_into(state.inline_intos) | ||
circuit.batch_insert(state.insertions) |
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.
Is this correct?
Fixes #4253