Skip to content

[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

Closed
wants to merge 8 commits into from
Closed

[WIP] NoCompile Tag for optimizers #4298

wants to merge 8 commits into from

Conversation

pgoiporia
Copy link

Fixes #4253

@google-cla
Copy link

google-cla bot commented Jul 7, 2021

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 @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added the cla: no label Jul 7, 2021
@google-cla
Copy link

google-cla bot commented Jul 8, 2021

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 @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@google-cla
Copy link

google-cla bot commented Jul 8, 2021

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 @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@pgoiporia
Copy link
Author

@googlebot I signed it!

@google-cla
Copy link

google-cla bot commented Jul 8, 2021

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 @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@google-cla
Copy link

google-cla bot commented Jul 8, 2021

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 @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@google-cla
Copy link

google-cla bot commented Jul 9, 2021

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 @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@pgoiporia
Copy link
Author

Keeping log of changes
NoCompileTag applied to:

drop_negligible with testing
eject_phased_paulis without testing
drop_empty_moments doesn't require the tag

@dstrain115 dstrain115 self-requested a review July 14, 2021 18:09
Copy link
Collaborator

@dstrain115 dstrain115 left a 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.
Copy link
Collaborator

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()
Copy link
Collaborator

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
Copy link
Collaborator

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:
Copy link
Collaborator

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.

Copy link
Collaborator

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:
Copy link
Collaborator

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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this correct?

@tanujkhattar tanujkhattar self-assigned this Jul 15, 2021
@CirqBot CirqBot added size: XL lines changed >1000 size: M 50< lines changed <250 and removed size: XL lines changed >1000 labels Aug 12, 2021
@tanujkhattar
Copy link
Collaborator

Support for NoCompileTags has been added to transformers as part of designing and implementing the new transformer framework.

See #4253 and #4722 for progress on migrating individual optimizers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: no size: M 50< lines changed <250
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NoCompile Tag for optimizers
4 participants