We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Add QASM importer
As the other leg of #44 and maybe a partial solution to #862 depending on the gate sets - as we discussed on today's sync meeting, a QASM importer would be useful. 

I'm happy to design and implement it.  

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `cirq/contrib/qasm_import/__init__.py`
Content:
```
1 # Copyright 2018 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 from cirq.contrib.qasm_import.exception import (QasmException)
16 from cirq.contrib.qasm_import.qasm import (QasmCircuitParser)
17
```

Path: `docs/conf.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 # coverage: ignore
3 
4 # Configuration file for the Sphinx documentation builder.
5 # See http://www.sphinx-doc.org/en/master/config for help
6 
7 # -- Path setup --------------------------------------------------------------
8 
9 # If extensions (or modules to document with autodoc) are in another directory,
10 # add these directories to sys.path here. If the directory is relative to the
11 # documentation root, use os.path.abspath to make it absolute, like shown here.
12 #
13 from typing import List, Any
14 
15 import os
16 import sys
17 
18 import pypandoc
19 
20 cirq_root_path = os.path.dirname(os.path.dirname(__file__))
21 sys.path.insert(0, cirq_root_path)
22 
23 
24 def setup(app):
25     app.add_config_value('pandoc_use_parser', 'markdown', True)
26     app.connect('autodoc-process-docstring', pandoc_process)
27 
28 
29 def convert_markdown_mathjax_for_rst(lines: List[str]) -> List[str]:
30     if all('$$' not in line for line in lines):
31         return lines
32 
33     data = '\n'.join(lines)
34     sections = data.split('$$')
35     if len(sections) % 2 != 1:
36         raise ValueError('Mismatched number of "$$" latex tokens.')
37 
38     result = []
39     for i, s in enumerate(sections):
40         if i % 2:
41             # Avoid getting split across divs.
42             s = ' '.join(s.split('\n'))
43             # Avoid intermediate layers turning our newlines into slashes.
44             s = s.replace('\\\\', '\\newline')
45             # Keep the $$ so MathJax can find it.
46             result.append('$${}$$'.format(s))
47         else:
48             # Work around bad table detection in pandoc by concatenating
49             # lines from the same paragraph.
50             s = '\n\n'.join(e.replace('\n', ' ') for e in s.split('\n\n'))
51 
52             # Convert markdown to rst.
53             out = pypandoc.convert(s, to='rst', format='markdown_github')
54 
55             # Not sure why pandoc is escaping these...
56             out = out.replace(r'\|', '|')
57 
58             result.extend(out.split('\n'))
59 
60     return result
61 
62 
63 def pandoc_process(app,
64                    what: str,
65                    name: str,
66                    obj: Any,
67                    options,
68                    lines: List[str]
69                    ) -> None:
70     if not getattr(obj, '__module__', 'cirq').startswith('cirq'):
71         # Don't convert objects from other modules.
72         return
73 
74     # Don't convert output from Napoleon extension, which is already rst.
75     i = 0
76     while i < len(lines) and not lines[i].startswith(':'):
77         i += 1
78     if not i:
79         return
80 
81     converted_lines = convert_markdown_mathjax_for_rst(lines[:i])
82     kept_lines = lines[i:]
83 
84     data = pypandoc.convert(
85         '\n'.join(converted_lines),
86         to='rst',
87         format='markdown_github',
88     )
89 
90     lines[:] = data.split('\n') + kept_lines
91 
92 
93 # -- Project information -----------------------------------------------------
94 
95 project = 'Cirq'
96 copyright = '2018, The Cirq Developers'  # pylint: disable=redefined-builtin
97 author = 'The Cirq Developers'
98 
99 # The full version, including alpha/beta/rc tags
100 __version__ = ''
101 exec(open(os.path.join(cirq_root_path, 'cirq', '_version.py')).read())
102 release = __version__
103 
104 # The short X.Y version
105 version = release  # '.'.join(release.split('.')[:2])
106 
107 # -- General configuration ---------------------------------------------------
108 
109 # If your documentation needs a minimal Sphinx version, state it here.
110 # needs_sphinx = '1.0'
111 
112 # Add any Sphinx extension module names here, as strings. They can be
113 # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
114 # ones.
115 extensions = [
116     'sphinx.ext.autodoc',
117     'sphinx.ext.autosummary',
118     'sphinx.ext.doctest',
119     'sphinx.ext.mathjax',
120     'sphinx.ext.napoleon',
121     'sphinx.ext.viewcode'
122 ]
123 
124 # Add any paths that contain templates here, relative to this directory.
125 templates_path = ['_templates']
126 
127 # Allow markdown includes.
128 # http://www.sphinx-doc.org/en/master/markdown.html
129 source_parsers = {
130    '.md': 'recommonmark.parser.CommonMarkParser',
131 }
132 
133 # The suffix(es) of source filenames.
134 # You can specify multiple suffix as a list of string:
135 #
136 source_suffix = ['.rst', '.md']
137 
138 # The master toctree document.
139 master_doc = 'index'
140 
141 # The language for content autogenerated by Sphinx. Refer to documentation
142 # for a list of supported languages.
143 #
144 # This is also used if you do content translation via gettext catalogs.
145 # Usually you set "language" from the command line for these cases.
146 language = None
147 
148 # List of patterns, relative to source directory, that match files and
149 # directories to ignore when looking for source files.
150 # This pattern also affects html_static_path and html_extra_path .
151 exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
152 
153 # The name of the Pygments (syntax highlighting) style to use.
154 pygments_style = 'sphinx'
155 
156 
157 # -- Options for HTML output ---------------------------------------------
158 
159 html_theme = 'sphinx_rtd_theme'
160 html_favicon = 'favicon.ico'
161 # html_theme_options = {}
162 
163 # Add any paths that contain custom static files (such as style sheets) here,
164 # relative to this directory. They are copied after the builtin static files,
165 # so a file named "default.css" will overwrite the builtin "default.css".
166 # html_static_path = ['_static']
167 
168 # Custom sidebar templates, must be a dictionary that maps document names
169 # to template names.
170 #
171 # The default sidebars (for documents that don't match any pattern) are
172 # defined by theme itself.  Builtin themes are using these templates by
173 # default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
174 # 'searchbox.html']``.
175 #
176 # html_sidebars = {}
177 
178 
179 # -- Options for HTMLHelp output -----------------------------------------
180 
181 # Output file base name for HTML help builder.
182 htmlhelp_basename = 'Cirqdoc'
183 
184 
185 # -- Options for LaTeX output --------------------------------------------
186 
187 latex_elements = {
188     # The paper size ('letterpaper' or 'a4paper').
189     'papersize': 'letterpaper',
190 
191     # The font size ('10pt', '11pt' or '12pt').
192     # 'pointsize': '10pt',
193 
194     # Additional stuff for the LaTeX preamble.
195     # 'preamble': '',
196 
197     # Latex figure (float) alignment
198     # 'figure_align': 'htbp',
199 }
200 
201 # Grouping the document tree into LaTeX files. List of tuples
202 # (source start file, target name, title,
203 #  author, documentclass [howto, manual, or own class]).
204 latex_documents = [
205     (master_doc, 'Cirq.tex', 'Cirq Documentation',
206      'The Cirq Developers', 'manual'),
207 ]
208 
209 
210 # -- Options for manual page output --------------------------------------
211 
212 # One entry per manual page. List of tuples
213 # (source start file, name, description, authors, manual section).
214 man_pages = [
215     (master_doc, 'cirq', 'Cirq Documentation',
216      [author], 1)
217 ]
218 
219 
220 # -- Options for Texinfo output ------------------------------------------
221 
222 # Grouping the document tree into Texinfo files. List of tuples
223 # (source start file, target name, title, author,
224 #  dir menu entry, description, category)
225 texinfo_documents = [
226     (master_doc, 'Cirq', 'Cirq Documentation',
227      author, 'Cirq', 'A python library for NISQ circuits.',
228      'Miscellaneous'),
229 ]
230 
231 
232 # -- Extension configuration -------------------------------------------------
233 
234 # Generate subpages for reference docs automatically.
235 # http://www.sphinx-doc.org/en/master/ext/autosummary.html#generating-stub-pages-automatically
236 autosummary_generate = True
237
```

Path: `cirq/contrib/qasm_import/qasm.py`
Content:
```
1 # Copyright 2018 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 from cirq import circuits
16 from cirq.contrib.qasm_import._parser import QasmParser
17 
18 
19 class QasmCircuitParser:
20     """QasmCircuitParser is currently partially developed, not functional,
21     DO NOT USE.
22     TODO(https://github.com/quantumlib/Cirq/issues/1548)
23     It will serve as the entrypoint for parsing QASM files."""
24 
25     def __init__(self):
26         pass
27 
28     def parse(self, qasm: str) -> circuits.Circuit:
29         return QasmParser().parse(qasm).circuit
30
```
--- 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/cirq/contrib/qasm_import/__init__.py b/cirq/contrib/qasm_import/__init__.py
--- a/cirq/contrib/qasm_import/__init__.py
+++ b/cirq/contrib/qasm_import/__init__.py
@@ -12,5 +12,5 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from cirq.contrib.qasm_import.exception import (QasmException)
-from cirq.contrib.qasm_import.qasm import (QasmCircuitParser)
+from cirq.contrib.qasm_import.exception import QasmException
+from cirq.contrib.qasm_import.qasm import circuit_from_qasm
diff --git a/cirq/contrib/qasm_import/qasm.py b/cirq/contrib/qasm_import/qasm.py
--- a/cirq/contrib/qasm_import/qasm.py
+++ b/cirq/contrib/qasm_import/qasm.py
@@ -16,14 +16,14 @@
 from cirq.contrib.qasm_import._parser import QasmParser
 
 
-class QasmCircuitParser:
-    """QasmCircuitParser is currently partially developed, not functional,
-    DO NOT USE.
-    TODO(https://github.com/quantumlib/Cirq/issues/1548)
-    It will serve as the entrypoint for parsing QASM files."""
+def circuit_from_qasm(qasm: str) -> circuits.Circuit:
+    """Parses an OpenQASM string to `cirq.Circuit`.
 
-    def __init__(self):
-        pass
+    Args:
+        qasm: The OpenQASM string
 
-    def parse(self, qasm: str) -> circuits.Circuit:
-        return QasmParser().parse(qasm).circuit
+    Returns:
+        The parsed circuit
+    """
+
+    return QasmParser().parse(qasm).circuit
diff --git a/docs/conf.py b/docs/conf.py
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -118,7 +118,8 @@
     'sphinx.ext.doctest',
     'sphinx.ext.mathjax',
     'sphinx.ext.napoleon',
-    'sphinx.ext.viewcode'
+    'sphinx.ext.viewcode',
+    'sphinx_markdown_tables',
 ]
 
 # Add any paths that contain templates here, relative to this directory.

{"golden_diff": "diff --git a/cirq/contrib/qasm_import/__init__.py b/cirq/contrib/qasm_import/__init__.py\n--- a/cirq/contrib/qasm_import/__init__.py\n+++ b/cirq/contrib/qasm_import/__init__.py\n@@ -12,5 +12,5 @@\n # See the License for the specific language governing permissions and\n # limitations under the License.\n \n-from cirq.contrib.qasm_import.exception import (QasmException)\n-from cirq.contrib.qasm_import.qasm import (QasmCircuitParser)\n+from cirq.contrib.qasm_import.exception import QasmException\n+from cirq.contrib.qasm_import.qasm import circuit_from_qasm\ndiff --git a/cirq/contrib/qasm_import/qasm.py b/cirq/contrib/qasm_import/qasm.py\n--- a/cirq/contrib/qasm_import/qasm.py\n+++ b/cirq/contrib/qasm_import/qasm.py\n@@ -16,14 +16,14 @@\n from cirq.contrib.qasm_import._parser import QasmParser\n \n \n-class QasmCircuitParser:\n-    \"\"\"QasmCircuitParser is currently partially developed, not functional,\n-    DO NOT USE.\n-    TODO(https://github.com/quantumlib/Cirq/issues/1548)\n-    It will serve as the entrypoint for parsing QASM files.\"\"\"\n+def circuit_from_qasm(qasm: str) -> circuits.Circuit:\n+    \"\"\"Parses an OpenQASM string to `cirq.Circuit`.\n \n-    def __init__(self):\n-        pass\n+    Args:\n+        qasm: The OpenQASM string\n \n-    def parse(self, qasm: str) -> circuits.Circuit:\n-        return QasmParser().parse(qasm).circuit\n+    Returns:\n+        The parsed circuit\n+    \"\"\"\n+\n+    return QasmParser().parse(qasm).circuit\ndiff --git a/docs/conf.py b/docs/conf.py\n--- a/docs/conf.py\n+++ b/docs/conf.py\n@@ -118,7 +118,8 @@\n     'sphinx.ext.doctest',\n     'sphinx.ext.mathjax',\n     'sphinx.ext.napoleon',\n-    'sphinx.ext.viewcode'\n+    'sphinx.ext.viewcode',\n+    'sphinx_markdown_tables',\n ]\n \n # Add any paths that contain templates here, relative to this directory.\n", "issue": "Add QASM importer\nAs the other leg of #44 and maybe a partial solution to #862 depending on the gate sets - as we discussed on today's sync meeting, a QASM importer would be useful. \r\n\r\nI'm happy to design and implement it.  \n", "before_files": [{"content": "# Copyright 2018 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\nfrom cirq.contrib.qasm_import.exception import (QasmException)\nfrom cirq.contrib.qasm_import.qasm import (QasmCircuitParser)\n", "path": "cirq/contrib/qasm_import/__init__.py"}, {"content": "# -*- coding: utf-8 -*-\n# coverage: ignore\n\n# Configuration file for the Sphinx documentation builder.\n# See http://www.sphinx-doc.org/en/master/config for help\n\n# -- Path setup --------------------------------------------------------------\n\n# If extensions (or modules to document with autodoc) are in another directory,\n# add these directories to sys.path here. If the directory is relative to the\n# documentation root, use os.path.abspath to make it absolute, like shown here.\n#\nfrom typing import List, Any\n\nimport os\nimport sys\n\nimport pypandoc\n\ncirq_root_path = os.path.dirname(os.path.dirname(__file__))\nsys.path.insert(0, cirq_root_path)\n\n\ndef setup(app):\n    app.add_config_value('pandoc_use_parser', 'markdown', True)\n    app.connect('autodoc-process-docstring', pandoc_process)\n\n\ndef convert_markdown_mathjax_for_rst(lines: List[str]) -> List[str]:\n    if all('$$' not in line for line in lines):\n        return lines\n\n    data = '\\n'.join(lines)\n    sections = data.split('$$')\n    if len(sections) % 2 != 1:\n        raise ValueError('Mismatched number of \"$$\" latex tokens.')\n\n    result = []\n    for i, s in enumerate(sections):\n        if i % 2:\n            # Avoid getting split across divs.\n            s = ' '.join(s.split('\\n'))\n            # Avoid intermediate layers turning our newlines into slashes.\n            s = s.replace('\\\\\\\\', '\\\\newline')\n            # Keep the $$ so MathJax can find it.\n            result.append('$${}$$'.format(s))\n        else:\n            # Work around bad table detection in pandoc by concatenating\n            # lines from the same paragraph.\n            s = '\\n\\n'.join(e.replace('\\n', ' ') for e in s.split('\\n\\n'))\n\n            # Convert markdown to rst.\n            out = pypandoc.convert(s, to='rst', format='markdown_github')\n\n            # Not sure why pandoc is escaping these...\n            out = out.replace(r'\\|', '|')\n\n            result.extend(out.split('\\n'))\n\n    return result\n\n\ndef pandoc_process(app,\n                   what: str,\n                   name: str,\n                   obj: Any,\n                   options,\n                   lines: List[str]\n                   ) -> None:\n    if not getattr(obj, '__module__', 'cirq').startswith('cirq'):\n        # Don't convert objects from other modules.\n        return\n\n    # Don't convert output from Napoleon extension, which is already rst.\n    i = 0\n    while i < len(lines) and not lines[i].startswith(':'):\n        i += 1\n    if not i:\n        return\n\n    converted_lines = convert_markdown_mathjax_for_rst(lines[:i])\n    kept_lines = lines[i:]\n\n    data = pypandoc.convert(\n        '\\n'.join(converted_lines),\n        to='rst',\n        format='markdown_github',\n    )\n\n    lines[:] = data.split('\\n') + kept_lines\n\n\n# -- Project information -----------------------------------------------------\n\nproject = 'Cirq'\ncopyright = '2018, The Cirq Developers'  # pylint: disable=redefined-builtin\nauthor = 'The Cirq Developers'\n\n# The full version, including alpha/beta/rc tags\n__version__ = ''\nexec(open(os.path.join(cirq_root_path, 'cirq', '_version.py')).read())\nrelease = __version__\n\n# The short X.Y version\nversion = release  # '.'.join(release.split('.')[:2])\n\n# -- General configuration ---------------------------------------------------\n\n# If your documentation needs a minimal Sphinx version, state it here.\n# needs_sphinx = '1.0'\n\n# Add any Sphinx extension module names here, as strings. They can be\n# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom\n# ones.\nextensions = [\n    'sphinx.ext.autodoc',\n    'sphinx.ext.autosummary',\n    'sphinx.ext.doctest',\n    'sphinx.ext.mathjax',\n    'sphinx.ext.napoleon',\n    'sphinx.ext.viewcode'\n]\n\n# Add any paths that contain templates here, relative to this directory.\ntemplates_path = ['_templates']\n\n# Allow markdown includes.\n# http://www.sphinx-doc.org/en/master/markdown.html\nsource_parsers = {\n   '.md': 'recommonmark.parser.CommonMarkParser',\n}\n\n# The suffix(es) of source filenames.\n# You can specify multiple suffix as a list of string:\n#\nsource_suffix = ['.rst', '.md']\n\n# The master toctree document.\nmaster_doc = 'index'\n\n# The language for content autogenerated by Sphinx. Refer to documentation\n# for a list of supported languages.\n#\n# This is also used if you do content translation via gettext catalogs.\n# Usually you set \"language\" from the command line for these cases.\nlanguage = None\n\n# List of patterns, relative to source directory, that match files and\n# directories to ignore when looking for source files.\n# This pattern also affects html_static_path and html_extra_path .\nexclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']\n\n# The name of the Pygments (syntax highlighting) style to use.\npygments_style = 'sphinx'\n\n\n# -- Options for HTML output ---------------------------------------------\n\nhtml_theme = 'sphinx_rtd_theme'\nhtml_favicon = 'favicon.ico'\n# html_theme_options = {}\n\n# Add any paths that contain custom static files (such as style sheets) here,\n# relative to this directory. They are copied after the builtin static files,\n# so a file named \"default.css\" will overwrite the builtin \"default.css\".\n# html_static_path = ['_static']\n\n# Custom sidebar templates, must be a dictionary that maps document names\n# to template names.\n#\n# The default sidebars (for documents that don't match any pattern) are\n# defined by theme itself.  Builtin themes are using these templates by\n# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',\n# 'searchbox.html']``.\n#\n# html_sidebars = {}\n\n\n# -- Options for HTMLHelp output -----------------------------------------\n\n# Output file base name for HTML help builder.\nhtmlhelp_basename = 'Cirqdoc'\n\n\n# -- Options for LaTeX output --------------------------------------------\n\nlatex_elements = {\n    # The paper size ('letterpaper' or 'a4paper').\n    'papersize': 'letterpaper',\n\n    # The font size ('10pt', '11pt' or '12pt').\n    # 'pointsize': '10pt',\n\n    # Additional stuff for the LaTeX preamble.\n    # 'preamble': '',\n\n    # Latex figure (float) alignment\n    # 'figure_align': 'htbp',\n}\n\n# Grouping the document tree into LaTeX files. List of tuples\n# (source start file, target name, title,\n#  author, documentclass [howto, manual, or own class]).\nlatex_documents = [\n    (master_doc, 'Cirq.tex', 'Cirq Documentation',\n     'The Cirq Developers', 'manual'),\n]\n\n\n# -- Options for manual page output --------------------------------------\n\n# One entry per manual page. List of tuples\n# (source start file, name, description, authors, manual section).\nman_pages = [\n    (master_doc, 'cirq', 'Cirq Documentation',\n     [author], 1)\n]\n\n\n# -- Options for Texinfo output ------------------------------------------\n\n# Grouping the document tree into Texinfo files. List of tuples\n# (source start file, target name, title, author,\n#  dir menu entry, description, category)\ntexinfo_documents = [\n    (master_doc, 'Cirq', 'Cirq Documentation',\n     author, 'Cirq', 'A python library for NISQ circuits.',\n     'Miscellaneous'),\n]\n\n\n# -- Extension configuration -------------------------------------------------\n\n# Generate subpages for reference docs automatically.\n# http://www.sphinx-doc.org/en/master/ext/autosummary.html#generating-stub-pages-automatically\nautosummary_generate = True\n", "path": "docs/conf.py"}, {"content": "# Copyright 2018 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\nfrom cirq import circuits\nfrom cirq.contrib.qasm_import._parser import QasmParser\n\n\nclass QasmCircuitParser:\n    \"\"\"QasmCircuitParser is currently partially developed, not functional,\n    DO NOT USE.\n    TODO(https://github.com/quantumlib/Cirq/issues/1548)\n    It will serve as the entrypoint for parsing QASM files.\"\"\"\n\n    def __init__(self):\n        pass\n\n    def parse(self, qasm: str) -> circuits.Circuit:\n        return QasmParser().parse(qasm).circuit\n", "path": "cirq/contrib/qasm_import/qasm.py"}], "after_files": [{"content": "# Copyright 2018 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\nfrom cirq.contrib.qasm_import.exception import QasmException\nfrom cirq.contrib.qasm_import.qasm import circuit_from_qasm\n", "path": "cirq/contrib/qasm_import/__init__.py"}, {"content": "# -*- coding: utf-8 -*-\n# coverage: ignore\n\n# Configuration file for the Sphinx documentation builder.\n# See http://www.sphinx-doc.org/en/master/config for help\n\n# -- Path setup --------------------------------------------------------------\n\n# If extensions (or modules to document with autodoc) are in another directory,\n# add these directories to sys.path here. If the directory is relative to the\n# documentation root, use os.path.abspath to make it absolute, like shown here.\n#\nfrom typing import List, Any\n\nimport os\nimport sys\n\nimport pypandoc\n\ncirq_root_path = os.path.dirname(os.path.dirname(__file__))\nsys.path.insert(0, cirq_root_path)\n\n\ndef setup(app):\n    app.add_config_value('pandoc_use_parser', 'markdown', True)\n    app.connect('autodoc-process-docstring', pandoc_process)\n\n\ndef convert_markdown_mathjax_for_rst(lines: List[str]) -> List[str]:\n    if all('$$' not in line for line in lines):\n        return lines\n\n    data = '\\n'.join(lines)\n    sections = data.split('$$')\n    if len(sections) % 2 != 1:\n        raise ValueError('Mismatched number of \"$$\" latex tokens.')\n\n    result = []\n    for i, s in enumerate(sections):\n        if i % 2:\n            # Avoid getting split across divs.\n            s = ' '.join(s.split('\\n'))\n            # Avoid intermediate layers turning our newlines into slashes.\n            s = s.replace('\\\\\\\\', '\\\\newline')\n            # Keep the $$ so MathJax can find it.\n            result.append('$${}$$'.format(s))\n        else:\n            # Work around bad table detection in pandoc by concatenating\n            # lines from the same paragraph.\n            s = '\\n\\n'.join(e.replace('\\n', ' ') for e in s.split('\\n\\n'))\n\n            # Convert markdown to rst.\n            out = pypandoc.convert(s, to='rst', format='markdown_github')\n\n            # Not sure why pandoc is escaping these...\n            out = out.replace(r'\\|', '|')\n\n            result.extend(out.split('\\n'))\n\n    return result\n\n\ndef pandoc_process(app,\n                   what: str,\n                   name: str,\n                   obj: Any,\n                   options,\n                   lines: List[str]\n                   ) -> None:\n    if not getattr(obj, '__module__', 'cirq').startswith('cirq'):\n        # Don't convert objects from other modules.\n        return\n\n    # Don't convert output from Napoleon extension, which is already rst.\n    i = 0\n    while i < len(lines) and not lines[i].startswith(':'):\n        i += 1\n    if not i:\n        return\n\n    converted_lines = convert_markdown_mathjax_for_rst(lines[:i])\n    kept_lines = lines[i:]\n\n    data = pypandoc.convert(\n        '\\n'.join(converted_lines),\n        to='rst',\n        format='markdown_github',\n    )\n\n    lines[:] = data.split('\\n') + kept_lines\n\n\n# -- Project information -----------------------------------------------------\n\nproject = 'Cirq'\ncopyright = '2018, The Cirq Developers'  # pylint: disable=redefined-builtin\nauthor = 'The Cirq Developers'\n\n# The full version, including alpha/beta/rc tags\n__version__ = ''\nexec(open(os.path.join(cirq_root_path, 'cirq', '_version.py')).read())\nrelease = __version__\n\n# The short X.Y version\nversion = release  # '.'.join(release.split('.')[:2])\n\n# -- General configuration ---------------------------------------------------\n\n# If your documentation needs a minimal Sphinx version, state it here.\n# needs_sphinx = '1.0'\n\n# Add any Sphinx extension module names here, as strings. They can be\n# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom\n# ones.\nextensions = [\n    'sphinx.ext.autodoc',\n    'sphinx.ext.autosummary',\n    'sphinx.ext.doctest',\n    'sphinx.ext.mathjax',\n    'sphinx.ext.napoleon',\n    'sphinx.ext.viewcode',\n    'sphinx_markdown_tables',\n]\n\n# Add any paths that contain templates here, relative to this directory.\ntemplates_path = ['_templates']\n\n# Allow markdown includes.\n# http://www.sphinx-doc.org/en/master/markdown.html\nsource_parsers = {\n   '.md': 'recommonmark.parser.CommonMarkParser',\n}\n\n# The suffix(es) of source filenames.\n# You can specify multiple suffix as a list of string:\n#\nsource_suffix = ['.rst', '.md']\n\n# The master toctree document.\nmaster_doc = 'index'\n\n# The language for content autogenerated by Sphinx. Refer to documentation\n# for a list of supported languages.\n#\n# This is also used if you do content translation via gettext catalogs.\n# Usually you set \"language\" from the command line for these cases.\nlanguage = None\n\n# List of patterns, relative to source directory, that match files and\n# directories to ignore when looking for source files.\n# This pattern also affects html_static_path and html_extra_path .\nexclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']\n\n# The name of the Pygments (syntax highlighting) style to use.\npygments_style = 'sphinx'\n\n\n# -- Options for HTML output ---------------------------------------------\n\nhtml_theme = 'sphinx_rtd_theme'\nhtml_favicon = 'favicon.ico'\n# html_theme_options = {}\n\n# Add any paths that contain custom static files (such as style sheets) here,\n# relative to this directory. They are copied after the builtin static files,\n# so a file named \"default.css\" will overwrite the builtin \"default.css\".\n# html_static_path = ['_static']\n\n# Custom sidebar templates, must be a dictionary that maps document names\n# to template names.\n#\n# The default sidebars (for documents that don't match any pattern) are\n# defined by theme itself.  Builtin themes are using these templates by\n# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',\n# 'searchbox.html']``.\n#\n# html_sidebars = {}\n\n\n# -- Options for HTMLHelp output -----------------------------------------\n\n# Output file base name for HTML help builder.\nhtmlhelp_basename = 'Cirqdoc'\n\n\n# -- Options for LaTeX output --------------------------------------------\n\nlatex_elements = {\n    # The paper size ('letterpaper' or 'a4paper').\n    'papersize': 'letterpaper',\n\n    # The font size ('10pt', '11pt' or '12pt').\n    # 'pointsize': '10pt',\n\n    # Additional stuff for the LaTeX preamble.\n    # 'preamble': '',\n\n    # Latex figure (float) alignment\n    # 'figure_align': 'htbp',\n}\n\n# Grouping the document tree into LaTeX files. List of tuples\n# (source start file, target name, title,\n#  author, documentclass [howto, manual, or own class]).\nlatex_documents = [\n    (master_doc, 'Cirq.tex', 'Cirq Documentation',\n     'The Cirq Developers', 'manual'),\n]\n\n\n# -- Options for manual page output --------------------------------------\n\n# One entry per manual page. List of tuples\n# (source start file, name, description, authors, manual section).\nman_pages = [\n    (master_doc, 'cirq', 'Cirq Documentation',\n     [author], 1)\n]\n\n\n# -- Options for Texinfo output ------------------------------------------\n\n# Grouping the document tree into Texinfo files. List of tuples\n# (source start file, target name, title, author,\n#  dir menu entry, description, category)\ntexinfo_documents = [\n    (master_doc, 'Cirq', 'Cirq Documentation',\n     author, 'Cirq', 'A python library for NISQ circuits.',\n     'Miscellaneous'),\n]\n\n\n# -- Extension configuration -------------------------------------------------\n\n# Generate subpages for reference docs automatically.\n# http://www.sphinx-doc.org/en/master/ext/autosummary.html#generating-stub-pages-automatically\nautosummary_generate = True\n", "path": "docs/conf.py"}, {"content": "# Copyright 2018 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\nfrom cirq import circuits\nfrom cirq.contrib.qasm_import._parser import QasmParser\n\n\ndef circuit_from_qasm(qasm: str) -> circuits.Circuit:\n    \"\"\"Parses an OpenQASM string to `cirq.Circuit`.\n\n    Args:\n        qasm: The OpenQASM string\n\n    Returns:\n        The parsed circuit\n    \"\"\"\n\n    return QasmParser().parse(qasm).circuit\n", "path": "cirq/contrib/qasm_import/qasm.py"}]}