prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Class methods on GridQubit to create common lattices
  Some obvious shapes
  ```GridQubit.square(3, 3)```
  ```GirdQubit.rect(2, 4)```
  returning list of list with row and column.   Default to 0,0 as one corner, but option to set corner.
  
  Ability to construction from an ASCII diagram like xmon devices
  ```GridQubit.from_pic```
  which operations on maps like
  ```
  ...A...
  ..AAA..
  .AAAAA.
  AAAAAAAA
  ````
  
  
  --- 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/devices/grid_qubit.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 
  16 from typing import Dict
  17 
  18 from cirq import ops
  19 
  20 
  21 class GridQubit(ops.Qid):
  22     """A qubit on a 2d square lattice.
  23 
  24     GridQubits use row-major ordering:
  25 
  26         GridQubit(0, 0) < GridQubit(0, 1) < GridQubit(1, 0) < GridQubit(1, 1)
  27     """
  28 
  29     def __init__(self, row: int, col: int):
  30         self.row = row
  31         self.col = col
  32 
  33     def _comparison_key(self):
  34         return self.row, self.col
  35 
  36     def is_adjacent(self, other: ops.Qid) -> bool:
  37         """Determines if two qubits are adjacent qubits."""
  38         return (isinstance(other, GridQubit) and
  39                 abs(self.row - other.row) + abs(self.col - other.col) == 1)
  40 
  41     def __repr__(self):
  42         return 'cirq.GridQubit({}, {})'.format(self.row, self.col)
  43 
  44     def __str__(self):
  45         return '({}, {})'.format(self.row, self.col)
  46 
  47     def to_proto_dict(self) -> Dict:
  48         """Return the proto in dictionary form."""
  49         return {
  50             'row': self.row,
  51             'col': self.col,
  52         }
  53 
  54     @staticmethod
  55     def from_proto_dict(proto_dict: Dict) -> 'GridQubit':
  56         """Proto dict must have 'row' and 'col' keys."""
  57         if 'row' not in proto_dict or 'col' not in proto_dict:
  58             raise ValueError(
  59                 'Proto dict does not contain row or col: {}'.format(proto_dict))
  60         return GridQubit(row=proto_dict['row'], col=proto_dict['col'])
  61
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/cirq/devices/grid_qubit.py b/cirq/devices/grid_qubit.py
  --- a/cirq/devices/grid_qubit.py
  +++ b/cirq/devices/grid_qubit.py
  @@ -13,7 +13,7 @@
   # limitations under the License.
   
   
  -from typing import Dict
  +from typing import Dict, List
   
   from cirq import ops
   
  @@ -38,6 +38,93 @@
           return (isinstance(other, GridQubit) and
                   abs(self.row - other.row) + abs(self.col - other.col) == 1)
   
  +    @staticmethod
  +    def square(diameter: int, top: int = 0, left: int = 0) -> List['GridQubit']:
  +        """Returns a square of GridQubits.
  +
  +        Args:
  +            diameter: Length of a side of the square
  +            top: Row number of the topmost row
  +            left: Column number of the leftmost row
  +
  +        Returns:
  +            A list of GridQubits filling in a square grid
  +        """
  +        return GridQubit.rect(diameter, diameter, top=top, left=left)
  +
  +    @staticmethod
  +    def rect(rows: int, cols: int, top: int = 0,
  +             left: int = 0) -> List['GridQubit']:
  +        """Returns a rectangle of GridQubits.
  +
  +        Args:
  +            rows: Number of rows in the rectangle
  +            cols: Number of columns in the rectangle
  +            top: Row number of the topmost row
  +            left: Column number of the leftmost row
  +
  +        Returns:
  +            A list of GridQubits filling in a rectangular grid
  +        """
  +        return [
  +            GridQubit(row, col)
  +            for row in range(top, top + rows)
  +            for col in range(left, left + cols)
  +        ]
  +
  +    @staticmethod
  +    def from_diagram(diagram: str) -> List['GridQubit']:
  +        """Parse ASCII art device layout into info about qubits and
  +        connectivity. As an example, the below diagram will create a list of
  +        GridQubits in a pyramid structure.
  +        ---A---
  +        --AAA--
  +        -AAAAA-
  +        AAAAAAA
  +
  +        You can use any character other than a hyphen to mark a qubit. As an
  +        example, the qubits for the Bristlecone device could be represented by
  +        the below diagram. This produces a diamond-shaped grid of qubits, and
  +        qubits with the same letter correspond to the same readout line.
  +
  +        .....AB.....
  +        ....ABCD....
  +        ...ABCDEF...
  +        ..ABCDEFGH..
  +        .ABCDEFGHIJ.
  +        ABCDEFGHIJKL
  +        .CDEFGHIJKL.
  +        ..EFGHIJKL..
  +        ...GHIJKL...
  +        ....IJKL....
  +        .....KL.....
  +
  +        Args:
  +            diagram: String representing the qubit layout. Each line represents
  +                a row. Alphanumeric characters are assigned as qubits.
  +                Dots ('.'), dashes ('-'), and spaces (' ') are treated as
  +                empty locations in the grid. If diagram has characters other
  +                than alphanumerics, spacers, and newlines ('\n'), an error will
  +                be thrown. The top-left corner of the diagram will be have
  +                coordinate (0,0).
  +
  +        Returns:
  +            A list of GridQubits corresponding to the provided diagram
  +
  +        Raises:
  +            ValueError: If the input string contains an invalid character.
  +        """
  +        lines = diagram.strip().split('\n')
  +        no_qubit_characters = ['.', '-', ' ']
  +        qubits = []
  +        for row, line in enumerate(lines):
  +            for col, c in enumerate(line.strip()):
  +                if c not in no_qubit_characters:
  +                    if not c.isalnum():
  +                        raise ValueError("Input string has invalid character")
  +                    qubits.append(GridQubit(row, col))
  +        return qubits
  +
       def __repr__(self):
           return 'cirq.GridQubit({}, {})'.format(self.row, self.col)
  
verification_info: {"golden_diff": "diff --git a/cirq/devices/grid_qubit.py b/cirq/devices/grid_qubit.py\n--- a/cirq/devices/grid_qubit.py\n+++ b/cirq/devices/grid_qubit.py\n@@ -13,7 +13,7 @@\n # limitations under the License.\n \n \n-from typing import Dict\n+from typing import Dict, List\n \n from cirq import ops\n \n@@ -38,6 +38,93 @@\n         return (isinstance(other, GridQubit) and\n                 abs(self.row - other.row) + abs(self.col - other.col) == 1)\n \n+    @staticmethod\n+    def square(diameter: int, top: int = 0, left: int = 0) -> List['GridQubit']:\n+        \"\"\"Returns a square of GridQubits.\n+\n+        Args:\n+            diameter: Length of a side of the square\n+            top: Row number of the topmost row\n+            left: Column number of the leftmost row\n+\n+        Returns:\n+            A list of GridQubits filling in a square grid\n+        \"\"\"\n+        return GridQubit.rect(diameter, diameter, top=top, left=left)\n+\n+    @staticmethod\n+    def rect(rows: int, cols: int, top: int = 0,\n+             left: int = 0) -> List['GridQubit']:\n+        \"\"\"Returns a rectangle of GridQubits.\n+\n+        Args:\n+            rows: Number of rows in the rectangle\n+            cols: Number of columns in the rectangle\n+            top: Row number of the topmost row\n+            left: Column number of the leftmost row\n+\n+        Returns:\n+            A list of GridQubits filling in a rectangular grid\n+        \"\"\"\n+        return [\n+            GridQubit(row, col)\n+            for row in range(top, top + rows)\n+            for col in range(left, left + cols)\n+        ]\n+\n+    @staticmethod\n+    def from_diagram(diagram: str) -> List['GridQubit']:\n+        \"\"\"Parse ASCII art device layout into info about qubits and\n+        connectivity. As an example, the below diagram will create a list of\n+        GridQubits in a pyramid structure.\n+        ---A---\n+        --AAA--\n+        -AAAAA-\n+        AAAAAAA\n+\n+        You can use any character other than a hyphen to mark a qubit. As an\n+        example, the qubits for the Bristlecone device could be represented by\n+        the below diagram. This produces a diamond-shaped grid of qubits, and\n+        qubits with the same letter correspond to the same readout line.\n+\n+        .....AB.....\n+        ....ABCD....\n+        ...ABCDEF...\n+        ..ABCDEFGH..\n+        .ABCDEFGHIJ.\n+        ABCDEFGHIJKL\n+        .CDEFGHIJKL.\n+        ..EFGHIJKL..\n+        ...GHIJKL...\n+        ....IJKL....\n+        .....KL.....\n+\n+        Args:\n+            diagram: String representing the qubit layout. Each line represents\n+                a row. Alphanumeric characters are assigned as qubits.\n+                Dots ('.'), dashes ('-'), and spaces (' ') are treated as\n+                empty locations in the grid. If diagram has characters other\n+                than alphanumerics, spacers, and newlines ('\\n'), an error will\n+                be thrown. The top-left corner of the diagram will be have\n+                coordinate (0,0).\n+\n+        Returns:\n+            A list of GridQubits corresponding to the provided diagram\n+\n+        Raises:\n+            ValueError: If the input string contains an invalid character.\n+        \"\"\"\n+        lines = diagram.strip().split('\\n')\n+        no_qubit_characters = ['.', '-', ' ']\n+        qubits = []\n+        for row, line in enumerate(lines):\n+            for col, c in enumerate(line.strip()):\n+                if c not in no_qubit_characters:\n+                    if not c.isalnum():\n+                        raise ValueError(\"Input string has invalid character\")\n+                    qubits.append(GridQubit(row, col))\n+        return qubits\n+\n     def __repr__(self):\n         return 'cirq.GridQubit({}, {})'.format(self.row, self.col)\n", "issue": "Class methods on GridQubit to create common lattices\nSome obvious shapes\r\n```GridQubit.square(3, 3)```\r\n```GirdQubit.rect(2, 4)```\r\nreturning list of list with row and column.   Default to 0,0 as one corner, but option to set corner.\r\n\r\nAbility to construction from an ASCII diagram like xmon devices\r\n```GridQubit.from_pic```\r\nwhich operations on maps like\r\n```\r\n...A...\r\n..AAA..\r\n.AAAAA.\r\nAAAAAAAA\r\n````\r\n\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\n\nfrom typing import Dict\n\nfrom cirq import ops\n\n\nclass GridQubit(ops.Qid):\n    \"\"\"A qubit on a 2d square lattice.\n\n    GridQubits use row-major ordering:\n\n        GridQubit(0, 0) < GridQubit(0, 1) < GridQubit(1, 0) < GridQubit(1, 1)\n    \"\"\"\n\n    def __init__(self, row: int, col: int):\n        self.row = row\n        self.col = col\n\n    def _comparison_key(self):\n        return self.row, self.col\n\n    def is_adjacent(self, other: ops.Qid) -> bool:\n        \"\"\"Determines if two qubits are adjacent qubits.\"\"\"\n        return (isinstance(other, GridQubit) and\n                abs(self.row - other.row) + abs(self.col - other.col) == 1)\n\n    def __repr__(self):\n        return 'cirq.GridQubit({}, {})'.format(self.row, self.col)\n\n    def __str__(self):\n        return '({}, {})'.format(self.row, self.col)\n\n    def to_proto_dict(self) -> Dict:\n        \"\"\"Return the proto in dictionary form.\"\"\"\n        return {\n            'row': self.row,\n            'col': self.col,\n        }\n\n    @staticmethod\n    def from_proto_dict(proto_dict: Dict) -> 'GridQubit':\n        \"\"\"Proto dict must have 'row' and 'col' keys.\"\"\"\n        if 'row' not in proto_dict or 'col' not in proto_dict:\n            raise ValueError(\n                'Proto dict does not contain row or col: {}'.format(proto_dict))\n        return GridQubit(row=proto_dict['row'], col=proto_dict['col'])\n", "path": "cirq/devices/grid_qubit.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\n\nfrom typing import Dict, List\n\nfrom cirq import ops\n\n\nclass GridQubit(ops.Qid):\n    \"\"\"A qubit on a 2d square lattice.\n\n    GridQubits use row-major ordering:\n\n        GridQubit(0, 0) < GridQubit(0, 1) < GridQubit(1, 0) < GridQubit(1, 1)\n    \"\"\"\n\n    def __init__(self, row: int, col: int):\n        self.row = row\n        self.col = col\n\n    def _comparison_key(self):\n        return self.row, self.col\n\n    def is_adjacent(self, other: ops.Qid) -> bool:\n        \"\"\"Determines if two qubits are adjacent qubits.\"\"\"\n        return (isinstance(other, GridQubit) and\n                abs(self.row - other.row) + abs(self.col - other.col) == 1)\n\n    @staticmethod\n    def square(diameter: int, top: int = 0, left: int = 0) -> List['GridQubit']:\n        \"\"\"Returns a square of GridQubits.\n\n        Args:\n            diameter: Length of a side of the square\n            top: Row number of the topmost row\n            left: Column number of the leftmost row\n\n        Returns:\n            A list of GridQubits filling in a square grid\n        \"\"\"\n        return GridQubit.rect(diameter, diameter, top=top, left=left)\n\n    @staticmethod\n    def rect(rows: int, cols: int, top: int = 0,\n             left: int = 0) -> List['GridQubit']:\n        \"\"\"Returns a rectangle of GridQubits.\n\n        Args:\n            rows: Number of rows in the rectangle\n            cols: Number of columns in the rectangle\n            top: Row number of the topmost row\n            left: Column number of the leftmost row\n\n        Returns:\n            A list of GridQubits filling in a rectangular grid\n        \"\"\"\n        return [\n            GridQubit(row, col)\n            for row in range(top, top + rows)\n            for col in range(left, left + cols)\n        ]\n\n    @staticmethod\n    def from_diagram(diagram: str) -> List['GridQubit']:\n        \"\"\"Parse ASCII art device layout into info about qubits and\n        connectivity. As an example, the below diagram will create a list of\n        GridQubits in a pyramid structure.\n        ---A---\n        --AAA--\n        -AAAAA-\n        AAAAAAA\n\n        You can use any character other than a hyphen to mark a qubit. As an\n        example, the qubits for the Bristlecone device could be represented by\n        the below diagram. This produces a diamond-shaped grid of qubits, and\n        qubits with the same letter correspond to the same readout line.\n\n        .....AB.....\n        ....ABCD....\n        ...ABCDEF...\n        ..ABCDEFGH..\n        .ABCDEFGHIJ.\n        ABCDEFGHIJKL\n        .CDEFGHIJKL.\n        ..EFGHIJKL..\n        ...GHIJKL...\n        ....IJKL....\n        .....KL.....\n\n        Args:\n            diagram: String representing the qubit layout. Each line represents\n                a row. Alphanumeric characters are assigned as qubits.\n                Dots ('.'), dashes ('-'), and spaces (' ') are treated as\n                empty locations in the grid. If diagram has characters other\n                than alphanumerics, spacers, and newlines ('\\n'), an error will\n                be thrown. The top-left corner of the diagram will be have\n                coordinate (0,0).\n\n        Returns:\n            A list of GridQubits corresponding to the provided diagram\n\n        Raises:\n            ValueError: If the input string contains an invalid character.\n        \"\"\"\n        lines = diagram.strip().split('\\n')\n        no_qubit_characters = ['.', '-', ' ']\n        qubits = []\n        for row, line in enumerate(lines):\n            for col, c in enumerate(line.strip()):\n                if c not in no_qubit_characters:\n                    if not c.isalnum():\n                        raise ValueError(\"Input string has invalid character\")\n                    qubits.append(GridQubit(row, col))\n        return qubits\n\n    def __repr__(self):\n        return 'cirq.GridQubit({}, {})'.format(self.row, self.col)\n\n    def __str__(self):\n        return '({}, {})'.format(self.row, self.col)\n\n    def to_proto_dict(self) -> Dict:\n        \"\"\"Return the proto in dictionary form.\"\"\"\n        return {\n            'row': self.row,\n            'col': self.col,\n        }\n\n    @staticmethod\n    def from_proto_dict(proto_dict: Dict) -> 'GridQubit':\n        \"\"\"Proto dict must have 'row' and 'col' keys.\"\"\"\n        if 'row' not in proto_dict or 'col' not in proto_dict:\n            raise ValueError(\n                'Proto dict does not contain row or col: {}'.format(proto_dict))\n        return GridQubit(row=proto_dict['row'], col=proto_dict['col'])\n", "path": "cirq/devices/grid_qubit.py"}]}