prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  optimized_for_sycamore fails when you measure more than 16 qubits
  ```python
  def thing():
      q = cirq.LineQubit.range(17)
      c = cirq.Circuit(cirq.H.on_each(*q), cirq.measure(*q, key='z'))
      c = cg.optimized_for_sycamore(c)
      return c
  thing()    
  ```
  
  ```
  ---------------------------------------------------------------------------
  ValueError                                Traceback (most recent call last)
  <ipython-input-44-accaace1183a> in <module>
        4     c = cg.optimized_for_sycamore(c)
        5     return c
  ----> 6 thing()
  
  <ipython-input-44-accaace1183a> in thing()
        2     q = cirq.LineQubit.range(17)
        3     c = cirq.Circuit(cirq.H.on_each(*q), cirq.measure(*q, key='z'))
  ----> 4     c = cg.optimized_for_sycamore(c)
        5     return c
        6 thing()
  
  ~/ecc/cirq/cirq/google/optimizers/optimize_for_sycamore.py in optimized_for_sycamore(circuit, new_device, qubit_map, optimizer_type, tolerance, tabulation_resolution)
      159     opts = _OPTIMIZER_TYPES[optimizer_type](tolerance=tolerance, tabulation=tabulation)
      160     for optimizer in opts:
  --> 161         optimizer(copy)
      162 
      163     return circuits.Circuit(
  
  ~/ecc/cirq/cirq/optimizers/drop_negligible.py in optimize_circuit(self, circuit)
       37         for moment_index, moment in enumerate(circuit):
       38             for op in moment.operations:
  ---> 39                 if op is not None and protocols.trace_distance_bound(op) <= self.tolerance:
       40                     deletions.append((moment_index, op))
       41         circuit.batch_remove(deletions)
  
  ~/ecc/cirq/cirq/protocols/trace_distance_bound.py in trace_distance_bound(val)
       71 
       72     for strat in strats:
  ---> 73         result = strat(val)
       74         if result is None:
       75             break
  
  ~/ecc/cirq/cirq/protocols/trace_distance_bound.py in _strat_distance_from_unitary(val)
       96 def _strat_distance_from_unitary(val: Any) -> Optional[float]:
       97     """Attempts to compute a value's trace_distance_bound from its unitary."""
  ---> 98     u = unitary_protocol.unitary(val, default=None)
       99 
      100     if u is None:
  
  ~/ecc/cirq/cirq/protocols/unitary_protocol.py in unitary(val, default)
      127     ]
      128     for strat in strats:
  --> 129         result = strat(val)
      130         if result is None:
      131             break
  
  ~/ecc/cirq/cirq/protocols/unitary_protocol.py in _strat_unitary_from_apply_unitary(val)
      173 
      174     # Apply unitary effect to an identity matrix.
  --> 175     state = qis.eye_tensor(val_qid_shape, dtype=np.complex128)
      176     buffer = np.empty_like(state)
      177     result = method(ApplyUnitaryArgs(state, buffer, range(len(val_qid_shape))))
  
  ~/ecc/cirq/cirq/qis/states.py in eye_tensor(half_shape, dtype)
      669     """
      670     identity = np.eye(np.prod(half_shape, dtype=int), dtype=dtype)
  --> 671     identity.shape = half_shape * 2
      672     return identity
  
  ValueError: maximum supported dimension for an ndarray is 32, found 34
  ```
  
  --- 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/optimizers/drop_negligible.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 """An optimization pass that removes operations with tiny effects."""
  16 
  17 from typing import List, Tuple, TYPE_CHECKING
  18 
  19 from cirq import protocols
  20 from cirq.circuits import circuit as _circuit
  21 
  22 if TYPE_CHECKING:
  23     from cirq import ops
  24 
  25 
  26 class DropNegligible:
  27     """An optimization pass that removes operations with tiny effects."""
  28 
  29     def __init__(self, tolerance: float = 1e-8) -> None:
  30         self.tolerance = tolerance
  31 
  32     def __call__(self, circuit: _circuit.Circuit):
  33         self.optimize_circuit(circuit)
  34 
  35     def optimize_circuit(self, circuit: _circuit.Circuit) -> None:
  36         deletions: List[Tuple[int, ops.Operation]] = []
  37         for moment_index, moment in enumerate(circuit):
  38             for op in moment.operations:
  39                 if op is not None and protocols.trace_distance_bound(op) <= self.tolerance:
  40                     deletions.append((moment_index, op))
  41         circuit.batch_remove(deletions)
  42
  ```
  --- 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/optimizers/drop_negligible.py b/cirq/optimizers/drop_negligible.py
  --- a/cirq/optimizers/drop_negligible.py
  +++ b/cirq/optimizers/drop_negligible.py
  @@ -36,6 +36,8 @@
           deletions: List[Tuple[int, ops.Operation]] = []
           for moment_index, moment in enumerate(circuit):
               for op in moment.operations:
  -                if op is not None and protocols.trace_distance_bound(op) <= self.tolerance:
  +                if protocols.is_measurement(op):
  +                    continue
  +                if protocols.trace_distance_bound(op) <= self.tolerance:
                       deletions.append((moment_index, op))
           circuit.batch_remove(deletions)
  
verification_info: {"golden_diff": "diff --git a/cirq/optimizers/drop_negligible.py b/cirq/optimizers/drop_negligible.py\n--- a/cirq/optimizers/drop_negligible.py\n+++ b/cirq/optimizers/drop_negligible.py\n@@ -36,6 +36,8 @@\n         deletions: List[Tuple[int, ops.Operation]] = []\n         for moment_index, moment in enumerate(circuit):\n             for op in moment.operations:\n-                if op is not None and protocols.trace_distance_bound(op) <= self.tolerance:\n+                if protocols.is_measurement(op):\n+                    continue\n+                if protocols.trace_distance_bound(op) <= self.tolerance:\n                     deletions.append((moment_index, op))\n         circuit.batch_remove(deletions)\n", "issue": "optimized_for_sycamore fails when you measure more than 16 qubits\n```python\r\ndef thing():\r\n    q = cirq.LineQubit.range(17)\r\n    c = cirq.Circuit(cirq.H.on_each(*q), cirq.measure(*q, key='z'))\r\n    c = cg.optimized_for_sycamore(c)\r\n    return c\r\nthing()    \r\n```\r\n\r\n```\r\n---------------------------------------------------------------------------\r\nValueError                                Traceback (most recent call last)\r\n<ipython-input-44-accaace1183a> in <module>\r\n      4     c = cg.optimized_for_sycamore(c)\r\n      5     return c\r\n----> 6 thing()\r\n\r\n<ipython-input-44-accaace1183a> in thing()\r\n      2     q = cirq.LineQubit.range(17)\r\n      3     c = cirq.Circuit(cirq.H.on_each(*q), cirq.measure(*q, key='z'))\r\n----> 4     c = cg.optimized_for_sycamore(c)\r\n      5     return c\r\n      6 thing()\r\n\r\n~/ecc/cirq/cirq/google/optimizers/optimize_for_sycamore.py in optimized_for_sycamore(circuit, new_device, qubit_map, optimizer_type, tolerance, tabulation_resolution)\r\n    159     opts = _OPTIMIZER_TYPES[optimizer_type](tolerance=tolerance, tabulation=tabulation)\r\n    160     for optimizer in opts:\r\n--> 161         optimizer(copy)\r\n    162 \r\n    163     return circuits.Circuit(\r\n\r\n~/ecc/cirq/cirq/optimizers/drop_negligible.py in optimize_circuit(self, circuit)\r\n     37         for moment_index, moment in enumerate(circuit):\r\n     38             for op in moment.operations:\r\n---> 39                 if op is not None and protocols.trace_distance_bound(op) <= self.tolerance:\r\n     40                     deletions.append((moment_index, op))\r\n     41         circuit.batch_remove(deletions)\r\n\r\n~/ecc/cirq/cirq/protocols/trace_distance_bound.py in trace_distance_bound(val)\r\n     71 \r\n     72     for strat in strats:\r\n---> 73         result = strat(val)\r\n     74         if result is None:\r\n     75             break\r\n\r\n~/ecc/cirq/cirq/protocols/trace_distance_bound.py in _strat_distance_from_unitary(val)\r\n     96 def _strat_distance_from_unitary(val: Any) -> Optional[float]:\r\n     97     \"\"\"Attempts to compute a value's trace_distance_bound from its unitary.\"\"\"\r\n---> 98     u = unitary_protocol.unitary(val, default=None)\r\n     99 \r\n    100     if u is None:\r\n\r\n~/ecc/cirq/cirq/protocols/unitary_protocol.py in unitary(val, default)\r\n    127     ]\r\n    128     for strat in strats:\r\n--> 129         result = strat(val)\r\n    130         if result is None:\r\n    131             break\r\n\r\n~/ecc/cirq/cirq/protocols/unitary_protocol.py in _strat_unitary_from_apply_unitary(val)\r\n    173 \r\n    174     # Apply unitary effect to an identity matrix.\r\n--> 175     state = qis.eye_tensor(val_qid_shape, dtype=np.complex128)\r\n    176     buffer = np.empty_like(state)\r\n    177     result = method(ApplyUnitaryArgs(state, buffer, range(len(val_qid_shape))))\r\n\r\n~/ecc/cirq/cirq/qis/states.py in eye_tensor(half_shape, dtype)\r\n    669     \"\"\"\r\n    670     identity = np.eye(np.prod(half_shape, dtype=int), dtype=dtype)\r\n--> 671     identity.shape = half_shape * 2\r\n    672     return identity\r\n\r\nValueError: maximum supported dimension for an ndarray is 32, found 34\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\"\"\"An optimization pass that removes operations with tiny effects.\"\"\"\n\nfrom typing import List, Tuple, TYPE_CHECKING\n\nfrom cirq import protocols\nfrom cirq.circuits import circuit as _circuit\n\nif TYPE_CHECKING:\n    from cirq import ops\n\n\nclass DropNegligible:\n    \"\"\"An optimization pass that removes operations with tiny effects.\"\"\"\n\n    def __init__(self, tolerance: float = 1e-8) -> None:\n        self.tolerance = tolerance\n\n    def __call__(self, circuit: _circuit.Circuit):\n        self.optimize_circuit(circuit)\n\n    def optimize_circuit(self, circuit: _circuit.Circuit) -> None:\n        deletions: List[Tuple[int, ops.Operation]] = []\n        for moment_index, moment in enumerate(circuit):\n            for op in moment.operations:\n                if op is not None and protocols.trace_distance_bound(op) <= self.tolerance:\n                    deletions.append((moment_index, op))\n        circuit.batch_remove(deletions)\n", "path": "cirq/optimizers/drop_negligible.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\"\"\"An optimization pass that removes operations with tiny effects.\"\"\"\n\nfrom typing import List, Tuple, TYPE_CHECKING\n\nfrom cirq import protocols\nfrom cirq.circuits import circuit as _circuit\n\nif TYPE_CHECKING:\n    from cirq import ops\n\n\nclass DropNegligible:\n    \"\"\"An optimization pass that removes operations with tiny effects.\"\"\"\n\n    def __init__(self, tolerance: float = 1e-8) -> None:\n        self.tolerance = tolerance\n\n    def __call__(self, circuit: _circuit.Circuit):\n        self.optimize_circuit(circuit)\n\n    def optimize_circuit(self, circuit: _circuit.Circuit) -> None:\n        deletions: List[Tuple[int, ops.Operation]] = []\n        for moment_index, moment in enumerate(circuit):\n            for op in moment.operations:\n                if protocols.is_measurement(op):\n                    continue\n                if protocols.trace_distance_bound(op) <= self.tolerance:\n                    deletions.append((moment_index, op))\n        circuit.batch_remove(deletions)\n", "path": "cirq/optimizers/drop_negligible.py"}]}