We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Docs builds for GridInteractionLayer and XebResultDict are broken
**Description of the issue**
Currently we cannot run the `build_api_docs.py` and build the API docs for `GridInteractionLayer` or `XebResultDict`.

**How to reproduce the issue**

```
diff --git a/dev_tools/docs/build_api_docs.py b/dev_tools/docs/build_api_docs.py
index e3f0c79a..076a4acc 100644
--- a/dev_tools/docs/build_api_docs.py
+++ b/dev_tools/docs/build_api_docs.py
@@ -95,6 +95,11 @@ def generate_cirq():
         site_path=FLAGS.site_path,
         callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],
         extra_docs=_doc.RECORDED_CONST_DOCS,
+        private_map={
+            # Opt to not build docs for these paths for now since they error.
+            "cirq.experiments": ["CrossEntropyResultDict", "GridInteractionLayer"],
+            "cirq.experiments.random_quantum_circuit_generation": ["GridInteractionLayer"],
+        },
     )
```
Removing the `private_map` entry in `build_api_docs.py` above and then running the build script gives:


```
Traceback (most recent call last):
  File "/home/mbbrough/Desktop/cirq_env/lib/python3.9/site-packages/tensorflow_docs/api_generator/generate_lib.py", line 546, in write_docs
    page_info = docs_for_object.docs_for_object(
  File "/home/mbbrough/Desktop/cirq_env/lib/python3.9/site-packages/tensorflow_docs/api_generator/pretty_docs/docs_for_object.py", line 89, in docs_for_object
    page_info.docs_for_object(parser_config)
  File "/home/mbbrough/Desktop/cirq_env/lib/python3.9/site-packages/tensorflow_docs/api_generator/pretty_docs/base_page.py", line 164, in docs_for_object
    self.collect_docs(parser_config)
  File "/home/mbbrough/Desktop/cirq_env/lib/python3.9/site-packages/tensorflow_docs/api_generator/pretty_docs/class_page.py", line 384, in collect_docs
    self._add_member(member_info, defining_class, parser_config)
  File "/home/mbbrough/Desktop/cirq_env/lib/python3.9/site-packages/tensorflow_docs/api_generator/pretty_docs/class_page.py", line 337, in _add_member
    self._add_method(member_info, defining_class, parser_config)
  File "/home/mbbrough/Desktop/cirq_env/lib/python3.9/site-packages/tensorflow_docs/api_generator/pretty_docs/class_page.py", line 277, in _add_method
    signature = signature_lib.generate_signature(
  File "/home/mbbrough/Desktop/cirq_env/lib/python3.9/site-packages/tensorflow_docs/api_generator/signature.py", line 589, in generate_signature
    return_annotation_source) = extract_fn(func)
  File "/home/mbbrough/Desktop/cirq_env/lib/python3.9/site-packages/tensorflow_docs/api_generator/signature.py", line 624, in _extract_class_defaults_and_annotations
    ast_visitor.extract(cls)
  File "/home/mbbrough/Desktop/cirq_env/lib/python3.9/site-packages/tensorflow_docs/api_generator/signature.py", line 140, in extract
    super().extract(cls)
  File "/home/mbbrough/Desktop/cirq_env/lib/python3.9/site-packages/tensorflow_docs/api_generator/signature.py", line 58, in extract
    obj_source = textwrap.dedent(inspect.getsource(obj))
  File "/usr/lib/python3.9/inspect.py", line 1024, in getsource
    lines, lnum = getsourcelines(object)
  File "/usr/lib/python3.9/inspect.py", line 1006, in getsourcelines
    lines, lnum = findsource(object)
  File "/usr/lib/python3.9/inspect.py", line 851, in findsource
    raise OSError('could not find class definition')
OSError: could not find class definition

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/mbbrough/Desktop/Cirq/dev_tools/docs/build_api_docs.py", line 220, in <module>
    app.run(main)
  File "/home/mbbrough/Desktop/cirq_env/lib/python3.9/site-packages/absl/app.py", line 312, in run
    _run_main(main, args)
  File "/home/mbbrough/Desktop/cirq_env/lib/python3.9/site-packages/absl/app.py", line 258, in _run_main
    sys.exit(main(argv))
  File "/home/mbbrough/Desktop/Cirq/dev_tools/docs/build_api_docs.py", line 79, in main
    generate_cirq()
  File "/home/mbbrough/Desktop/Cirq/dev_tools/docs/build_api_docs.py", line 106, in generate_cirq
    doc_generator.build(output_dir=FLAGS.output_dir)
  File "/home/mbbrough/Desktop/cirq_env/lib/python3.9/site-packages/tensorflow_docs/api_generator/generate_lib.py", line 847, in build
    write_docs(
  File "/home/mbbrough/Desktop/cirq_env/lib/python3.9/site-packages/tensorflow_docs/api_generator/generate_lib.py", line 559, in write_docs
    raise ValueError(
ValueError: Failed to generate docs for symbol: `cirq.experiments.GridInteractionLayer`
```

**Cirq version**
```
0.15.0dev
```



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `dev_tools/docs/build_api_docs.py`
Content:
```
1 # Copyright 2021 The Cirq Developers
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     https://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 # ==============================================================================
15 """Tool to generate external api_docs for Cirq.
16 
17 In order to publish to our site, devsite runs two jobs for us: stable and nightly.
18 The stable one downloads the latest cirq release from pypi and uses that to generate the reference
19 API docs.
20 The nightly one downloads the latest cirq pre-release (pip install cirq --pre) and uses that to
21 generate the "nightly diff".
22 
23 This script needs to cater for both of these cases.
24 """
25 
26 import os
27 import types
28 
29 import networkx
30 from absl import app
31 from absl import flags
32 from tensorflow_docs.api_generator import doc_controls
33 from tensorflow_docs.api_generator import generate_lib
34 from tensorflow_docs.api_generator import public_api
35 
36 import cirq
37 import cirq_aqt
38 import cirq_google
39 import cirq_ionq
40 import cirq_pasqal
41 import cirq_rigetti
42 import cirq_web
43 
44 from cirq import _doc
45 
46 flags.DEFINE_string("output_dir", "docs/api_docs", "Where to output the docs")
47 
48 flags.DEFINE_string(
49     "code_url_prefix",
50     "https://github.com/quantumlib/Cirq/blob/master",
51     "The url prefix for links to code.",
52 )
53 
54 flags.DEFINE_bool("search_hints", True, "Include metadata search hints in the generated files")
55 
56 flags.DEFINE_string("site_path", "reference/python", "Path prefix in the _toc.yaml")
57 
58 FLAGS = flags.FLAGS
59 
60 
61 def filter_unwanted_inherited_methods(path, parent, children):
62     """Filter the unwanted inherited methods.
63 
64     CircuitDag inherits a lot of methods from `networkx.DiGraph` and `Graph`.
65     This filter removes these, as it creates a lot of noise in the API docs.
66     """
67     if parent.__name__ != "CircuitDag":
68         return children
69 
70     filtered_children = []
71     for name, obj in children:
72         if isinstance(obj, types.FunctionType):
73             if obj.__module__.startswith('cirq'):
74                 filtered_children.append((name, obj))
75     return filtered_children
76 
77 
78 def main(unused_argv):
79     generate_cirq()
80     generate_cirq_google()
81     generate_cirq_aqt()
82     generate_cirq_ionq()
83     generate_cirq_pasqal()
84     generate_cirq_rigetti()
85     generate_cirq_web()
86 
87 
88 def generate_cirq():
89     doc_generator = generate_lib.DocGenerator(
90         root_title="Cirq",
91         py_modules=[("cirq", cirq)],
92         base_dir=os.path.dirname(cirq.__file__),
93         code_url_prefix=FLAGS.code_url_prefix + "/cirq-core/cirq",
94         search_hints=FLAGS.search_hints,
95         site_path=FLAGS.site_path,
96         callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],
97         extra_docs=_doc.RECORDED_CONST_DOCS,
98         private_map={
99             # Opt to not build docs for these paths for now since they error.
100             "cirq.experiments": ["CrossEntropyResultDict", "GridInteractionLayer"],
101             "cirq.experiments.random_quantum_circuit_generation": ["GridInteractionLayer"],
102         },
103     )
104     doc_controls.decorate_all_class_attributes(
105         doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]
106     )
107     doc_generator.build(output_dir=FLAGS.output_dir)
108 
109 
110 def generate_cirq_aqt():
111     doc_generator = generate_lib.DocGenerator(
112         root_title="Cirq-aqt",
113         py_modules=[("cirq_aqt", cirq_aqt)],
114         base_dir=os.path.dirname(cirq_aqt.__file__),
115         code_url_prefix=FLAGS.code_url_prefix + "/cirq-aqt/cirq_aqt",
116         search_hints=FLAGS.search_hints,
117         site_path=FLAGS.site_path,
118         callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],
119         extra_docs=_doc.RECORDED_CONST_DOCS,
120     )
121     doc_controls.decorate_all_class_attributes(
122         doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]
123     )
124 
125     doc_generator.build(output_dir=FLAGS.output_dir)
126 
127 
128 def generate_cirq_ionq():
129     doc_generator = generate_lib.DocGenerator(
130         root_title="Cirq_ionq",
131         py_modules=[("cirq_ionq", cirq_ionq)],
132         base_dir=os.path.dirname(cirq_ionq.__file__),
133         code_url_prefix=FLAGS.code_url_prefix + "/cirq-ionq/cirq_ionq",
134         search_hints=FLAGS.search_hints,
135         site_path=FLAGS.site_path,
136         callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],
137         extra_docs=_doc.RECORDED_CONST_DOCS,
138     )
139     doc_controls.decorate_all_class_attributes(
140         doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]
141     )
142 
143     doc_generator.build(output_dir=FLAGS.output_dir)
144 
145 
146 def generate_cirq_pasqal():
147     doc_generator = generate_lib.DocGenerator(
148         root_title="Cirq-pasqal",
149         py_modules=[("cirq_pasqal", cirq_pasqal)],
150         base_dir=os.path.dirname(cirq_pasqal.__file__),
151         code_url_prefix=FLAGS.code_url_prefix + "/cirq-pasqal/cirq_pasqal",
152         search_hints=FLAGS.search_hints,
153         site_path=FLAGS.site_path,
154         callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],
155         extra_docs=_doc.RECORDED_CONST_DOCS,
156     )
157     doc_controls.decorate_all_class_attributes(
158         doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]
159     )
160 
161     doc_generator.build(output_dir=FLAGS.output_dir)
162 
163 
164 def generate_cirq_rigetti():
165     doc_generator = generate_lib.DocGenerator(
166         root_title="Cirq_rigetti",
167         py_modules=[("cirq_rigetti", cirq_rigetti)],
168         base_dir=os.path.dirname(cirq_rigetti.__file__),
169         code_url_prefix=FLAGS.code_url_prefix + "/cirq-rigetti/cirq_rigetti",
170         search_hints=FLAGS.search_hints,
171         site_path=FLAGS.site_path,
172         callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],
173         extra_docs=_doc.RECORDED_CONST_DOCS,
174     )
175     doc_controls.decorate_all_class_attributes(
176         doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]
177     )
178 
179     doc_generator.build(output_dir=FLAGS.output_dir)
180 
181 
182 def generate_cirq_google():
183     doc_generator = generate_lib.DocGenerator(
184         root_title="Cirq-google",
185         py_modules=[("cirq_google", cirq_google)],
186         base_dir=os.path.dirname(cirq_google.__file__),
187         code_url_prefix=FLAGS.code_url_prefix + "/cirq-google/cirq_google",
188         search_hints=FLAGS.search_hints,
189         site_path=FLAGS.site_path,
190         callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],
191         private_map={
192             # Opt to not build docs for these paths for now since they error.
193             "cirq_google.cloud.quantum.QuantumEngineServiceClient": ["enums"],
194             "cirq_google.cloud.quantum_v1alpha1.QuantumEngineServiceClient": ["enums"],
195             "cirq_google.api": ["v1"],
196         },
197         extra_docs=_doc.RECORDED_CONST_DOCS,
198     )
199     doc_generator.build(output_dir=FLAGS.output_dir)
200 
201 
202 def generate_cirq_web():
203     doc_generator = generate_lib.DocGenerator(
204         root_title="Cirq_web",
205         py_modules=[("cirq_web", cirq_web)],
206         base_dir=os.path.dirname(cirq_web.__file__),
207         code_url_prefix=FLAGS.code_url_prefix + "/cirq-web/cirq_web",
208         search_hints=FLAGS.search_hints,
209         site_path=FLAGS.site_path,
210         callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],
211         extra_docs=_doc.RECORDED_CONST_DOCS,
212     )
213     doc_controls.decorate_all_class_attributes(
214         doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]
215     )
216 
217     doc_generator.build(output_dir=FLAGS.output_dir)
218 
219 
220 if __name__ == "__main__":
221     app.run(main)
222
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/dev_tools/docs/build_api_docs.py b/dev_tools/docs/build_api_docs.py
--- a/dev_tools/docs/build_api_docs.py
+++ b/dev_tools/docs/build_api_docs.py
@@ -95,11 +95,6 @@
         site_path=FLAGS.site_path,
         callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],
         extra_docs=_doc.RECORDED_CONST_DOCS,
-        private_map={
-            # Opt to not build docs for these paths for now since they error.
-            "cirq.experiments": ["CrossEntropyResultDict", "GridInteractionLayer"],
-            "cirq.experiments.random_quantum_circuit_generation": ["GridInteractionLayer"],
-        },
     )
     doc_controls.decorate_all_class_attributes(
         doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]

{"golden_diff": "diff --git a/dev_tools/docs/build_api_docs.py b/dev_tools/docs/build_api_docs.py\n--- a/dev_tools/docs/build_api_docs.py\n+++ b/dev_tools/docs/build_api_docs.py\n@@ -95,11 +95,6 @@\n         site_path=FLAGS.site_path,\n         callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n         extra_docs=_doc.RECORDED_CONST_DOCS,\n-        private_map={\n-            # Opt to not build docs for these paths for now since they error.\n-            \"cirq.experiments\": [\"CrossEntropyResultDict\", \"GridInteractionLayer\"],\n-            \"cirq.experiments.random_quantum_circuit_generation\": [\"GridInteractionLayer\"],\n-        },\n     )\n     doc_controls.decorate_all_class_attributes(\n         doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]\n", "issue": "Docs builds for GridInteractionLayer and XebResultDict are broken\n**Description of the issue**\r\nCurrently we cannot run the `build_api_docs.py` and build the API docs for `GridInteractionLayer` or `XebResultDict`.\r\n\r\n**How to reproduce the issue**\r\n\r\n```\r\ndiff --git a/dev_tools/docs/build_api_docs.py b/dev_tools/docs/build_api_docs.py\r\nindex e3f0c79a..076a4acc 100644\r\n--- a/dev_tools/docs/build_api_docs.py\r\n+++ b/dev_tools/docs/build_api_docs.py\r\n@@ -95,6 +95,11 @@ def generate_cirq():\r\n         site_path=FLAGS.site_path,\r\n         callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\r\n         extra_docs=_doc.RECORDED_CONST_DOCS,\r\n+        private_map={\r\n+            # Opt to not build docs for these paths for now since they error.\r\n+            \"cirq.experiments\": [\"CrossEntropyResultDict\", \"GridInteractionLayer\"],\r\n+            \"cirq.experiments.random_quantum_circuit_generation\": [\"GridInteractionLayer\"],\r\n+        },\r\n     )\r\n```\r\nRemoving the `private_map` entry in `build_api_docs.py` above and then running the build script gives:\r\n\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"/home/mbbrough/Desktop/cirq_env/lib/python3.9/site-packages/tensorflow_docs/api_generator/generate_lib.py\", line 546, in write_docs\r\n    page_info = docs_for_object.docs_for_object(\r\n  File \"/home/mbbrough/Desktop/cirq_env/lib/python3.9/site-packages/tensorflow_docs/api_generator/pretty_docs/docs_for_object.py\", line 89, in docs_for_object\r\n    page_info.docs_for_object(parser_config)\r\n  File \"/home/mbbrough/Desktop/cirq_env/lib/python3.9/site-packages/tensorflow_docs/api_generator/pretty_docs/base_page.py\", line 164, in docs_for_object\r\n    self.collect_docs(parser_config)\r\n  File \"/home/mbbrough/Desktop/cirq_env/lib/python3.9/site-packages/tensorflow_docs/api_generator/pretty_docs/class_page.py\", line 384, in collect_docs\r\n    self._add_member(member_info, defining_class, parser_config)\r\n  File \"/home/mbbrough/Desktop/cirq_env/lib/python3.9/site-packages/tensorflow_docs/api_generator/pretty_docs/class_page.py\", line 337, in _add_member\r\n    self._add_method(member_info, defining_class, parser_config)\r\n  File \"/home/mbbrough/Desktop/cirq_env/lib/python3.9/site-packages/tensorflow_docs/api_generator/pretty_docs/class_page.py\", line 277, in _add_method\r\n    signature = signature_lib.generate_signature(\r\n  File \"/home/mbbrough/Desktop/cirq_env/lib/python3.9/site-packages/tensorflow_docs/api_generator/signature.py\", line 589, in generate_signature\r\n    return_annotation_source) = extract_fn(func)\r\n  File \"/home/mbbrough/Desktop/cirq_env/lib/python3.9/site-packages/tensorflow_docs/api_generator/signature.py\", line 624, in _extract_class_defaults_and_annotations\r\n    ast_visitor.extract(cls)\r\n  File \"/home/mbbrough/Desktop/cirq_env/lib/python3.9/site-packages/tensorflow_docs/api_generator/signature.py\", line 140, in extract\r\n    super().extract(cls)\r\n  File \"/home/mbbrough/Desktop/cirq_env/lib/python3.9/site-packages/tensorflow_docs/api_generator/signature.py\", line 58, in extract\r\n    obj_source = textwrap.dedent(inspect.getsource(obj))\r\n  File \"/usr/lib/python3.9/inspect.py\", line 1024, in getsource\r\n    lines, lnum = getsourcelines(object)\r\n  File \"/usr/lib/python3.9/inspect.py\", line 1006, in getsourcelines\r\n    lines, lnum = findsource(object)\r\n  File \"/usr/lib/python3.9/inspect.py\", line 851, in findsource\r\n    raise OSError('could not find class definition')\r\nOSError: could not find class definition\r\n\r\nThe above exception was the direct cause of the following exception:\r\n\r\nTraceback (most recent call last):\r\n  File \"/home/mbbrough/Desktop/Cirq/dev_tools/docs/build_api_docs.py\", line 220, in <module>\r\n    app.run(main)\r\n  File \"/home/mbbrough/Desktop/cirq_env/lib/python3.9/site-packages/absl/app.py\", line 312, in run\r\n    _run_main(main, args)\r\n  File \"/home/mbbrough/Desktop/cirq_env/lib/python3.9/site-packages/absl/app.py\", line 258, in _run_main\r\n    sys.exit(main(argv))\r\n  File \"/home/mbbrough/Desktop/Cirq/dev_tools/docs/build_api_docs.py\", line 79, in main\r\n    generate_cirq()\r\n  File \"/home/mbbrough/Desktop/Cirq/dev_tools/docs/build_api_docs.py\", line 106, in generate_cirq\r\n    doc_generator.build(output_dir=FLAGS.output_dir)\r\n  File \"/home/mbbrough/Desktop/cirq_env/lib/python3.9/site-packages/tensorflow_docs/api_generator/generate_lib.py\", line 847, in build\r\n    write_docs(\r\n  File \"/home/mbbrough/Desktop/cirq_env/lib/python3.9/site-packages/tensorflow_docs/api_generator/generate_lib.py\", line 559, in write_docs\r\n    raise ValueError(\r\nValueError: Failed to generate docs for symbol: `cirq.experiments.GridInteractionLayer`\r\n```\r\n\r\n**Cirq version**\r\n```\r\n0.15.0dev\r\n```\r\n\r\n\n", "before_files": [{"content": "# Copyright 2021 The Cirq Developers\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     https://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n# ==============================================================================\n\"\"\"Tool to generate external api_docs for Cirq.\n\nIn order to publish to our site, devsite runs two jobs for us: stable and nightly.\nThe stable one downloads the latest cirq release from pypi and uses that to generate the reference\nAPI docs.\nThe nightly one downloads the latest cirq pre-release (pip install cirq --pre) and uses that to\ngenerate the \"nightly diff\".\n\nThis script needs to cater for both of these cases.\n\"\"\"\n\nimport os\nimport types\n\nimport networkx\nfrom absl import app\nfrom absl import flags\nfrom tensorflow_docs.api_generator import doc_controls\nfrom tensorflow_docs.api_generator import generate_lib\nfrom tensorflow_docs.api_generator import public_api\n\nimport cirq\nimport cirq_aqt\nimport cirq_google\nimport cirq_ionq\nimport cirq_pasqal\nimport cirq_rigetti\nimport cirq_web\n\nfrom cirq import _doc\n\nflags.DEFINE_string(\"output_dir\", \"docs/api_docs\", \"Where to output the docs\")\n\nflags.DEFINE_string(\n    \"code_url_prefix\",\n    \"https://github.com/quantumlib/Cirq/blob/master\",\n    \"The url prefix for links to code.\",\n)\n\nflags.DEFINE_bool(\"search_hints\", True, \"Include metadata search hints in the generated files\")\n\nflags.DEFINE_string(\"site_path\", \"reference/python\", \"Path prefix in the _toc.yaml\")\n\nFLAGS = flags.FLAGS\n\n\ndef filter_unwanted_inherited_methods(path, parent, children):\n    \"\"\"Filter the unwanted inherited methods.\n\n    CircuitDag inherits a lot of methods from `networkx.DiGraph` and `Graph`.\n    This filter removes these, as it creates a lot of noise in the API docs.\n    \"\"\"\n    if parent.__name__ != \"CircuitDag\":\n        return children\n\n    filtered_children = []\n    for name, obj in children:\n        if isinstance(obj, types.FunctionType):\n            if obj.__module__.startswith('cirq'):\n                filtered_children.append((name, obj))\n    return filtered_children\n\n\ndef main(unused_argv):\n    generate_cirq()\n    generate_cirq_google()\n    generate_cirq_aqt()\n    generate_cirq_ionq()\n    generate_cirq_pasqal()\n    generate_cirq_rigetti()\n    generate_cirq_web()\n\n\ndef generate_cirq():\n    doc_generator = generate_lib.DocGenerator(\n        root_title=\"Cirq\",\n        py_modules=[(\"cirq\", cirq)],\n        base_dir=os.path.dirname(cirq.__file__),\n        code_url_prefix=FLAGS.code_url_prefix + \"/cirq-core/cirq\",\n        search_hints=FLAGS.search_hints,\n        site_path=FLAGS.site_path,\n        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n        extra_docs=_doc.RECORDED_CONST_DOCS,\n        private_map={\n            # Opt to not build docs for these paths for now since they error.\n            \"cirq.experiments\": [\"CrossEntropyResultDict\", \"GridInteractionLayer\"],\n            \"cirq.experiments.random_quantum_circuit_generation\": [\"GridInteractionLayer\"],\n        },\n    )\n    doc_controls.decorate_all_class_attributes(\n        doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]\n    )\n    doc_generator.build(output_dir=FLAGS.output_dir)\n\n\ndef generate_cirq_aqt():\n    doc_generator = generate_lib.DocGenerator(\n        root_title=\"Cirq-aqt\",\n        py_modules=[(\"cirq_aqt\", cirq_aqt)],\n        base_dir=os.path.dirname(cirq_aqt.__file__),\n        code_url_prefix=FLAGS.code_url_prefix + \"/cirq-aqt/cirq_aqt\",\n        search_hints=FLAGS.search_hints,\n        site_path=FLAGS.site_path,\n        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n        extra_docs=_doc.RECORDED_CONST_DOCS,\n    )\n    doc_controls.decorate_all_class_attributes(\n        doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]\n    )\n\n    doc_generator.build(output_dir=FLAGS.output_dir)\n\n\ndef generate_cirq_ionq():\n    doc_generator = generate_lib.DocGenerator(\n        root_title=\"Cirq_ionq\",\n        py_modules=[(\"cirq_ionq\", cirq_ionq)],\n        base_dir=os.path.dirname(cirq_ionq.__file__),\n        code_url_prefix=FLAGS.code_url_prefix + \"/cirq-ionq/cirq_ionq\",\n        search_hints=FLAGS.search_hints,\n        site_path=FLAGS.site_path,\n        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n        extra_docs=_doc.RECORDED_CONST_DOCS,\n    )\n    doc_controls.decorate_all_class_attributes(\n        doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]\n    )\n\n    doc_generator.build(output_dir=FLAGS.output_dir)\n\n\ndef generate_cirq_pasqal():\n    doc_generator = generate_lib.DocGenerator(\n        root_title=\"Cirq-pasqal\",\n        py_modules=[(\"cirq_pasqal\", cirq_pasqal)],\n        base_dir=os.path.dirname(cirq_pasqal.__file__),\n        code_url_prefix=FLAGS.code_url_prefix + \"/cirq-pasqal/cirq_pasqal\",\n        search_hints=FLAGS.search_hints,\n        site_path=FLAGS.site_path,\n        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n        extra_docs=_doc.RECORDED_CONST_DOCS,\n    )\n    doc_controls.decorate_all_class_attributes(\n        doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]\n    )\n\n    doc_generator.build(output_dir=FLAGS.output_dir)\n\n\ndef generate_cirq_rigetti():\n    doc_generator = generate_lib.DocGenerator(\n        root_title=\"Cirq_rigetti\",\n        py_modules=[(\"cirq_rigetti\", cirq_rigetti)],\n        base_dir=os.path.dirname(cirq_rigetti.__file__),\n        code_url_prefix=FLAGS.code_url_prefix + \"/cirq-rigetti/cirq_rigetti\",\n        search_hints=FLAGS.search_hints,\n        site_path=FLAGS.site_path,\n        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n        extra_docs=_doc.RECORDED_CONST_DOCS,\n    )\n    doc_controls.decorate_all_class_attributes(\n        doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]\n    )\n\n    doc_generator.build(output_dir=FLAGS.output_dir)\n\n\ndef generate_cirq_google():\n    doc_generator = generate_lib.DocGenerator(\n        root_title=\"Cirq-google\",\n        py_modules=[(\"cirq_google\", cirq_google)],\n        base_dir=os.path.dirname(cirq_google.__file__),\n        code_url_prefix=FLAGS.code_url_prefix + \"/cirq-google/cirq_google\",\n        search_hints=FLAGS.search_hints,\n        site_path=FLAGS.site_path,\n        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n        private_map={\n            # Opt to not build docs for these paths for now since they error.\n            \"cirq_google.cloud.quantum.QuantumEngineServiceClient\": [\"enums\"],\n            \"cirq_google.cloud.quantum_v1alpha1.QuantumEngineServiceClient\": [\"enums\"],\n            \"cirq_google.api\": [\"v1\"],\n        },\n        extra_docs=_doc.RECORDED_CONST_DOCS,\n    )\n    doc_generator.build(output_dir=FLAGS.output_dir)\n\n\ndef generate_cirq_web():\n    doc_generator = generate_lib.DocGenerator(\n        root_title=\"Cirq_web\",\n        py_modules=[(\"cirq_web\", cirq_web)],\n        base_dir=os.path.dirname(cirq_web.__file__),\n        code_url_prefix=FLAGS.code_url_prefix + \"/cirq-web/cirq_web\",\n        search_hints=FLAGS.search_hints,\n        site_path=FLAGS.site_path,\n        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n        extra_docs=_doc.RECORDED_CONST_DOCS,\n    )\n    doc_controls.decorate_all_class_attributes(\n        doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]\n    )\n\n    doc_generator.build(output_dir=FLAGS.output_dir)\n\n\nif __name__ == \"__main__\":\n    app.run(main)\n", "path": "dev_tools/docs/build_api_docs.py"}], "after_files": [{"content": "# Copyright 2021 The Cirq Developers\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     https://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n# ==============================================================================\n\"\"\"Tool to generate external api_docs for Cirq.\n\nIn order to publish to our site, devsite runs two jobs for us: stable and nightly.\nThe stable one downloads the latest cirq release from pypi and uses that to generate the reference\nAPI docs.\nThe nightly one downloads the latest cirq pre-release (pip install cirq --pre) and uses that to\ngenerate the \"nightly diff\".\n\nThis script needs to cater for both of these cases.\n\"\"\"\n\nimport os\nimport types\n\nimport networkx\nfrom absl import app\nfrom absl import flags\nfrom tensorflow_docs.api_generator import doc_controls\nfrom tensorflow_docs.api_generator import generate_lib\nfrom tensorflow_docs.api_generator import public_api\n\nimport cirq\nimport cirq_aqt\nimport cirq_google\nimport cirq_ionq\nimport cirq_pasqal\nimport cirq_rigetti\nimport cirq_web\n\nfrom cirq import _doc\n\nflags.DEFINE_string(\"output_dir\", \"docs/api_docs\", \"Where to output the docs\")\n\nflags.DEFINE_string(\n    \"code_url_prefix\",\n    \"https://github.com/quantumlib/Cirq/blob/master\",\n    \"The url prefix for links to code.\",\n)\n\nflags.DEFINE_bool(\"search_hints\", True, \"Include metadata search hints in the generated files\")\n\nflags.DEFINE_string(\"site_path\", \"reference/python\", \"Path prefix in the _toc.yaml\")\n\nFLAGS = flags.FLAGS\n\n\ndef filter_unwanted_inherited_methods(path, parent, children):\n    \"\"\"Filter the unwanted inherited methods.\n\n    CircuitDag inherits a lot of methods from `networkx.DiGraph` and `Graph`.\n    This filter removes these, as it creates a lot of noise in the API docs.\n    \"\"\"\n    if parent.__name__ != \"CircuitDag\":\n        return children\n\n    filtered_children = []\n    for name, obj in children:\n        if isinstance(obj, types.FunctionType):\n            if obj.__module__.startswith('cirq'):\n                filtered_children.append((name, obj))\n    return filtered_children\n\n\ndef main(unused_argv):\n    generate_cirq()\n    generate_cirq_google()\n    generate_cirq_aqt()\n    generate_cirq_ionq()\n    generate_cirq_pasqal()\n    generate_cirq_rigetti()\n    generate_cirq_web()\n\n\ndef generate_cirq():\n    doc_generator = generate_lib.DocGenerator(\n        root_title=\"Cirq\",\n        py_modules=[(\"cirq\", cirq)],\n        base_dir=os.path.dirname(cirq.__file__),\n        code_url_prefix=FLAGS.code_url_prefix + \"/cirq-core/cirq\",\n        search_hints=FLAGS.search_hints,\n        site_path=FLAGS.site_path,\n        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n        extra_docs=_doc.RECORDED_CONST_DOCS,\n    )\n    doc_controls.decorate_all_class_attributes(\n        doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]\n    )\n    doc_generator.build(output_dir=FLAGS.output_dir)\n\n\ndef generate_cirq_aqt():\n    doc_generator = generate_lib.DocGenerator(\n        root_title=\"Cirq-aqt\",\n        py_modules=[(\"cirq_aqt\", cirq_aqt)],\n        base_dir=os.path.dirname(cirq_aqt.__file__),\n        code_url_prefix=FLAGS.code_url_prefix + \"/cirq-aqt/cirq_aqt\",\n        search_hints=FLAGS.search_hints,\n        site_path=FLAGS.site_path,\n        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n        extra_docs=_doc.RECORDED_CONST_DOCS,\n    )\n    doc_controls.decorate_all_class_attributes(\n        doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]\n    )\n\n    doc_generator.build(output_dir=FLAGS.output_dir)\n\n\ndef generate_cirq_ionq():\n    doc_generator = generate_lib.DocGenerator(\n        root_title=\"Cirq_ionq\",\n        py_modules=[(\"cirq_ionq\", cirq_ionq)],\n        base_dir=os.path.dirname(cirq_ionq.__file__),\n        code_url_prefix=FLAGS.code_url_prefix + \"/cirq-ionq/cirq_ionq\",\n        search_hints=FLAGS.search_hints,\n        site_path=FLAGS.site_path,\n        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n        extra_docs=_doc.RECORDED_CONST_DOCS,\n    )\n    doc_controls.decorate_all_class_attributes(\n        doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]\n    )\n\n    doc_generator.build(output_dir=FLAGS.output_dir)\n\n\ndef generate_cirq_pasqal():\n    doc_generator = generate_lib.DocGenerator(\n        root_title=\"Cirq-pasqal\",\n        py_modules=[(\"cirq_pasqal\", cirq_pasqal)],\n        base_dir=os.path.dirname(cirq_pasqal.__file__),\n        code_url_prefix=FLAGS.code_url_prefix + \"/cirq-pasqal/cirq_pasqal\",\n        search_hints=FLAGS.search_hints,\n        site_path=FLAGS.site_path,\n        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n        extra_docs=_doc.RECORDED_CONST_DOCS,\n    )\n    doc_controls.decorate_all_class_attributes(\n        doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]\n    )\n\n    doc_generator.build(output_dir=FLAGS.output_dir)\n\n\ndef generate_cirq_rigetti():\n    doc_generator = generate_lib.DocGenerator(\n        root_title=\"Cirq_rigetti\",\n        py_modules=[(\"cirq_rigetti\", cirq_rigetti)],\n        base_dir=os.path.dirname(cirq_rigetti.__file__),\n        code_url_prefix=FLAGS.code_url_prefix + \"/cirq-rigetti/cirq_rigetti\",\n        search_hints=FLAGS.search_hints,\n        site_path=FLAGS.site_path,\n        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n        extra_docs=_doc.RECORDED_CONST_DOCS,\n    )\n    doc_controls.decorate_all_class_attributes(\n        doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]\n    )\n\n    doc_generator.build(output_dir=FLAGS.output_dir)\n\n\ndef generate_cirq_google():\n    doc_generator = generate_lib.DocGenerator(\n        root_title=\"Cirq-google\",\n        py_modules=[(\"cirq_google\", cirq_google)],\n        base_dir=os.path.dirname(cirq_google.__file__),\n        code_url_prefix=FLAGS.code_url_prefix + \"/cirq-google/cirq_google\",\n        search_hints=FLAGS.search_hints,\n        site_path=FLAGS.site_path,\n        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n        private_map={\n            # Opt to not build docs for these paths for now since they error.\n            \"cirq_google.cloud.quantum.QuantumEngineServiceClient\": [\"enums\"],\n            \"cirq_google.cloud.quantum_v1alpha1.QuantumEngineServiceClient\": [\"enums\"],\n            \"cirq_google.api\": [\"v1\"],\n        },\n        extra_docs=_doc.RECORDED_CONST_DOCS,\n    )\n    doc_generator.build(output_dir=FLAGS.output_dir)\n\n\ndef generate_cirq_web():\n    doc_generator = generate_lib.DocGenerator(\n        root_title=\"Cirq_web\",\n        py_modules=[(\"cirq_web\", cirq_web)],\n        base_dir=os.path.dirname(cirq_web.__file__),\n        code_url_prefix=FLAGS.code_url_prefix + \"/cirq-web/cirq_web\",\n        search_hints=FLAGS.search_hints,\n        site_path=FLAGS.site_path,\n        callbacks=[public_api.local_definitions_filter, filter_unwanted_inherited_methods],\n        extra_docs=_doc.RECORDED_CONST_DOCS,\n    )\n    doc_controls.decorate_all_class_attributes(\n        doc_controls.do_not_doc_inheritable, networkx.DiGraph, skip=[]\n    )\n\n    doc_generator.build(output_dir=FLAGS.output_dir)\n\n\nif __name__ == \"__main__\":\n    app.run(main)\n", "path": "dev_tools/docs/build_api_docs.py"}]}