Skip to content

Bump the proto requirements to match the generated data. #4473

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

Merged
merged 16 commits into from
Sep 10, 2021

Conversation

tonybruguier
Copy link
Contributor

@tonybruguier tonybruguier commented Aug 26, 2021

It seems PR #4333 used a newer version of the proto syntax, but the requirements have not been updated, so this PR bumps them,

As a check, I decided to execute the follow commands:

python3 -m pip install protobuf~=3.17.3
python3 -m pip install grpcio-tools~=1.34.1
python3 -m pip install grpcio~=1.34.1
python3 -m pip install mypy-protobuf==1.10

./dev_tools/build-protos.sh

And the generated protos are unchanged, so maybe it's correct?

@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label Aug 26, 2021
@CirqBot CirqBot added the Size: XS <10 lines changed label Aug 26, 2021
@tonybruguier tonybruguier marked this pull request as ready for review August 26, 2021 03:57
@tonybruguier tonybruguier requested review from cduck, vtomole, wcourtney and a team as code owners August 26, 2021 03:57
Copy link
Collaborator

@MichaelBroughton MichaelBroughton left a comment

Choose a reason for hiding this comment

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

This is actually a pain point for compatibility between TFQ and CIrq. We manually compile our .proto files using grpcio-tools (which comes with a recommended protoc inside) and keep them in the repo. Right now, the release version of TensorFlow Quantum depends on TensorFlow 2.4.1 which requires proto 3.9.2, but will work up to cirq having proto 3.13.0 or lower. Is this proto bump happening because you found something breaking or because there were warnings ?

@MichaelBroughton MichaelBroughton self-assigned this Aug 26, 2021
@tonybruguier
Copy link
Contributor Author

tonybruguier commented Aug 26, 2021

@MichaelBroughton
Thanks for the quick turn-around! So while working on bumping up the Cirq version in TFQ:
tensorflow/quantum#621

I encountered an error:

    import cirq
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/cirq/__init__.py", line 596, in <module>
    _compat.deprecated_submodule(
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/cirq/_compat.py", line 594, in deprecated_submodule
    new_module = importlib.import_module(new_module_name)
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/cirq_google/__init__.py", line 17, in <module>
    from cirq_google import api
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/cirq_google/api/__init__.py", line 16, in <module>
    from cirq_google.api import v2
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/cirq_google/api/v2/__init__.py", line 16, in <module>
    from cirq_google.api.v2 import (
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/cirq_google/api/v2/batch_pb2.py", line 14, in <module>
    from . import program_pb2 as cirq__google_dot_api_dot_v2_dot_program__pb2
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/cirq_google/api/v2/program_pb2.py", line 21, in <module>
    create_key=_descriptor._internal_create_key,
AttributeError: module 'google.protobuf.descriptor' has no attribute '_internal_create_key'

https://github.com/tensorflow/quantum/pull/621/checks?check_run_id=3425375706

I was able to repro locally, and I was able to fix by bumping the version of protobuf. But, from what I now understand, this is a naive approach and bumping the version won't work.

Is there another way? Maybe PR #4333 was compiled with the wrong version of grpcio-tool. Is so, maybe a way out is to compile with the right version? If so, I can try it but pointers would be welcome.

@CirqBot CirqBot added the size: XL lines changed >1000 label Aug 28, 2021
@tonybruguier tonybruguier changed the title Bump proto version Regenerate the proto API with the correct version Aug 28, 2021
@tonybruguier
Copy link
Contributor Author

I think I was able to resolve the issue, @MichaelBroughton . Instead of bumping the requirements, I had to regenerate the files.

I also added a discussion item for next week's Cirq sync.

@maffoo
Copy link
Contributor

maffoo commented Aug 30, 2021

We used to have a CI check that would generate protos with the expected version of the proto compiler and fail if there were any diffs compared to what was in the PR. Is that no longer running? If there's a diff like this I would have expected either a previous PR to be rejected, or this one.

@MichaelBroughton
Copy link
Collaborator

From Cirq Cync: Could you regenerate and test with the following:

grpcio-tools and grpc==1.34.1
protobuf==3.17.3

And then bump: https://github.com/quantumlib/Cirq/blob/master/cirq-google/requirements.txt
to 3.17.3 ? and see if things still work ? This might also solve #4161

@tonybruguier tonybruguier changed the title Regenerate the proto API with the correct version Bump the proto requirements to match the generated data. Sep 2, 2021
@tonybruguier
Copy link
Contributor Author

Thanks. PTAL.

@MichaelBroughton
Copy link
Collaborator

So you regnerated all the pb2.py files using these versions and nothing changed ?

@tonybruguier
Copy link
Contributor Author

So you regnerated all the pb2.py files using these versions and nothing changed ?

Yes, precisely. I used the commands in the description.

@MichaelBroughton
Copy link
Collaborator

Awesome. @dstrain115 @maffoo does this work for you guys to merge ?

@maffoo
Copy link
Contributor

maffoo commented Sep 3, 2021

I think the build-changed-protos ci step is not doing what we want. It's not clear to me that the script has been updated to reflect the latest packaging changes, and I think we are being too clever by trying to detect protos that have changed and only compile those. I think ci should instead compile all the protos (e.g. run dev_tools/build-protos.sh as recommended in the dev docs) and then look for any diffs. There aren't that many protos so this is plenty fast, and it will greatly simplify the logic.

For this PR, I think updating the protobuf library is probably ok, but I'd prefer to update the grpcio-tools version in the dev_tools proto deps to reflect the version that we actually want to use to generate protos and then update the protobuf library to match whatever is used by the grpcio-tools version we settle on (grpcio-tools bundles some version of protoc). We should also fix the ci proto step.

@tonybruguier
Copy link
Contributor Author

tonybruguier commented Sep 3, 2021

@maffoo

Thanks for answering. I am a little bit confused though. I did run dev_tools/build-protos.sh. In fact, these are the commands that I ran:

python3 -m pip install protobuf~=3.17.3
python3 -m pip install grpcio-tools~=1.34.1
python3 -m pip install grpcio~=1.34.1
python3 -m pip install mypy-protobuf==1.10

./dev_tools/build-protos.sh

After running the commands, the proto files reverted themselves to their version at head. In other words, I did not manually revert the changes. Instead, I kept the intermediate (and incorrect) changes that I had, and by running the script, they naturally got reverted.

Sorry if I am still confused and thanks for having taken the time to review the changes.

@tonybruguier
Copy link
Contributor Author

@maffoo
Copy link
Contributor

maffoo commented Sep 3, 2021

@tonybruguier, I think the problem is that the .proto files we have committed at HEAD are not correct because our CI check is broken. The CI should be compiling with grpcio-tools==1.26.0 which is what is listed in the the proto deps: https://github.com/quantumlib/Cirq/blob/master/dev_tools/requirements/deps/protos.txt#L6. If you do that you'll see a big diff compared to what is committed at HEAD. But our CI check didn't detect the problem whenever the latest proto changes were committed.

@tonybruguier
Copy link
Contributor Author

@maffoo Thanks. I looked into the test code and I think I might have found an issue: It seems that it was only checking changed files, which is not correct I think. When we bump the requirements, we don't modify the proto definitions, yet their compiled version might be different.

I tried the fix the unit test, and also updated the requirements. Here's the log:
https://pipelines.actions.githubusercontent.com/j17N1UnkAeIifjAO1q0K1FVeXWuBVqg7pbz7SuXJuOPU7i2PHx/_apis/pipelines/1/runs/7241/signedlogcontent/23?urlExpires=2021-09-04T02%3A32%3A03.9197508Z&urlSigningMethod=HMACV1&urlSignature=TgNiRgwl%2BTvw15oO3CCoqHLXBegyfkkw2o89hUt19wc%3D

It now seems to be finding the protos and to re-generate them.

@tonybruguier
Copy link
Contributor Author

Thanks, @maffoo PTAL when you have the time. I appreciate the quick turn-around and the opportunity to learn.

Copy link
Contributor

@maffoo maffoo left a comment

Choose a reason for hiding this comment

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

This is looking much better, thanks for working through these protobuf issues! I think we should run some tests to ensure that the ci task to check generated protobuf code is working. For example, make a change to a .proto file and push this branch without regenerating proto code and verify that the CI check fails. Similarly, could make an edit directly to one of the generated _pb2.py files and again verify that the CI check fails. This will ensure that we can keep our proto code properly synced going forward.

I'll let @MichaelBroughton weigh in on what protobuf version we actually want to upgrade to, but I do think we should keep that in sync here with our grpcio-tools version.

@tonybruguier
Copy link
Contributor Author

Thanks, @maffoo
I left some comments unresolved for Michael to give some advice. I addressed the others. As for testing the code, I purposely mangled the protos with this commit:
60123dd
And I saw this error:
https://github.com/quantumlib/Cirq/pull/4473/checks?check_run_id=3539007607

@tonybruguier
Copy link
Contributor Author

Closed remaining comments and sync'ed to head.

Copy link
Contributor

@maffoo maffoo left a comment

Choose a reason for hiding this comment

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

Tooling looks good, thanks for fixing/simplifying the CI check. I'd suggest changing the protobuf dependency per Michael's suggestion and a few minor doc fixes, then we should be good to go.

@tonybruguier
Copy link
Contributor Author

Thanks. PTAL.

Copy link
Contributor

@maffoo maffoo left a comment

Choose a reason for hiding this comment

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

LGTM

@MichaelBroughton MichaelBroughton added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Sep 10, 2021
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Sep 10, 2021
@CirqBot CirqBot merged commit 578c956 into quantumlib:master Sep 10, 2021
@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Sep 10, 2021
@tonybruguier tonybruguier deleted the cirq_bump_proto_version branch September 10, 2021 23:21
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
…4473)

It seems PR quantumlib#4333 used a newer version of the proto syntax, but the requirements have not been updated, so this PR bumps them,

As a check, I decided to execute the follow commands:
```
python3 -m pip install protobuf~=3.17.3
python3 -m pip install grpcio-tools~=1.34.1
python3 -m pip install grpcio~=1.34.1
python3 -m pip install mypy-protobuf==1.10

./dev_tools/build-protos.sh
```

And the generated protos are unchanged, so maybe it's correct?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Makes googlebot stop complaining. size: XL lines changed >1000 Size: XS <10 lines changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants