prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Two circuit diagram tests that rest in `contrib` are failing on Windows
  See: https://travis-ci.com/quantumlib/Cirq/jobs/202641395
  
  --- 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/paulistring/convert_to_pauli_string_phasors.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 typing import Optional, cast, TYPE_CHECKING
  16 
  17 import numpy as np
  18 
  19 from cirq import ops, optimizers, protocols, linalg
  20 from cirq.circuits.circuit import Circuit
  21 from cirq.circuits.optimization_pass import (
  22     PointOptimizationSummary,
  23     PointOptimizer,
  24 )
  25 
  26 if TYPE_CHECKING:
  27     # pylint: disable=unused-import
  28     from typing import List
  29 
  30 
  31 class ConvertToPauliStringPhasors(PointOptimizer):
  32     """Attempts to convert single-qubit gates into single-qubit
  33     PauliStringPhasor operations.
  34 
  35     Checks if the operation has a known unitary effect. If so, and the gate is a
  36         1-qubit gate, then decomposes it into x, y, or z rotations and creates a
  37         PauliStringPhasor for each.
  38     """
  39 
  40     def __init__(self,
  41                  ignore_failures: bool = False,
  42                  keep_clifford: bool = False,
  43                  atol: float = 0) -> None:
  44         """
  45         Args:
  46             ignore_failures: If set, gates that fail to convert are forwarded
  47                 unchanged. If not set, conversion failures raise a TypeError.
  48             keep_clifford: If set, single qubit rotations in the Clifford group
  49                 are converted to SingleQubitCliffordGates.
  50             atol: Maximum absolute error tolerance. The optimization is
  51                 permitted to round angles with a threshold determined by this
  52                 tolerance.
  53         """
  54         super().__init__()
  55         self.ignore_failures = ignore_failures
  56         self.keep_clifford = keep_clifford
  57         self.atol = atol
  58 
  59     def _matrix_to_pauli_string_phasors(self,
  60                                         mat: np.ndarray,
  61                                         qubit: ops.Qid) -> ops.OP_TREE:
  62         rotations = optimizers.single_qubit_matrix_to_pauli_rotations(
  63             mat, self.atol)
  64         out_ops = []  # type: List[ops.Operation]
  65         for pauli, half_turns in rotations:
  66             if (self.keep_clifford
  67                     and linalg.all_near_zero_mod(half_turns, 0.5)):
  68                 cliff_gate = ops.SingleQubitCliffordGate.from_quarter_turns(
  69                     pauli, round(half_turns * 2))
  70                 if out_ops and not isinstance(out_ops[-1],
  71                                               ops.PauliStringPhasor):
  72                     op = cast(ops.GateOperation, out_ops[-1])
  73                     gate = cast(ops.SingleQubitCliffordGate, op.gate)
  74                     out_ops[-1] = gate.merged_with(cliff_gate)(qubit)
  75                 else:
  76                     out_ops.append(
  77                         cliff_gate(qubit))
  78             else:
  79                 pauli_string = ops.PauliString.from_single(qubit, pauli)
  80                 out_ops.append(
  81                     ops.PauliStringPhasor(pauli_string,
  82                                           exponent_neg=round(half_turns, 10)))
  83         return out_ops
  84 
  85     def _convert_one(self, op: ops.Operation) -> ops.OP_TREE:
  86         # Don't change if it's already a ops.PauliStringPhasor
  87         if isinstance(op, ops.PauliStringPhasor):
  88             return op
  89 
  90         if (self.keep_clifford
  91             and isinstance(op, ops.GateOperation)
  92                 and isinstance(op.gate, ops.SingleQubitCliffordGate)):
  93             return op
  94 
  95         # Single qubit gate with known matrix?
  96         if len(op.qubits) == 1:
  97             mat = protocols.unitary(op, None)
  98             if mat is not None:
  99                 return self._matrix_to_pauli_string_phasors(mat, op.qubits[0])
  100 
  101         # Just let it be?
  102         if self.ignore_failures:
  103             return op
  104 
  105         raise TypeError("Don't know how to work with {!r}. "
  106                         "It isn't a 1-qubit operation with a known unitary "
  107                         "effect.".format(op))
  108 
  109     def convert(self, op: ops.Operation) -> ops.OP_TREE:
  110         converted = self._convert_one(op)
  111         if converted is op:
  112             return converted
  113         return [self.convert(cast(ops.Operation, e))
  114                 for e in ops.flatten_op_tree(converted)]
  115 
  116     def optimization_at(self, circuit: Circuit, index: int, op: ops.Operation
  117                         ) -> Optional[PointOptimizationSummary]:
  118         converted = self.convert(op)
  119         if converted is op:
  120             return None
  121 
  122         return PointOptimizationSummary(
  123             clear_span=1,
  124             new_operations=converted,
  125             clear_qubits=op.qubits)
  126
  ```
  --- 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/contrib/paulistring/convert_to_pauli_string_phasors.py b/cirq/contrib/paulistring/convert_to_pauli_string_phasors.py
  --- a/cirq/contrib/paulistring/convert_to_pauli_string_phasors.py
  +++ b/cirq/contrib/paulistring/convert_to_pauli_string_phasors.py
  @@ -40,7 +40,7 @@
       def __init__(self,
                    ignore_failures: bool = False,
                    keep_clifford: bool = False,
  -                 atol: float = 0) -> None:
  +                 atol: float = 1e-14) -> None:
           """
           Args:
               ignore_failures: If set, gates that fail to convert are forwarded
  
verification_info: {"golden_diff": "diff --git a/cirq/contrib/paulistring/convert_to_pauli_string_phasors.py b/cirq/contrib/paulistring/convert_to_pauli_string_phasors.py\n--- a/cirq/contrib/paulistring/convert_to_pauli_string_phasors.py\n+++ b/cirq/contrib/paulistring/convert_to_pauli_string_phasors.py\n@@ -40,7 +40,7 @@\n     def __init__(self,\n                  ignore_failures: bool = False,\n                  keep_clifford: bool = False,\n-                 atol: float = 0) -> None:\n+                 atol: float = 1e-14) -> None:\n         \"\"\"\n         Args:\n             ignore_failures: If set, gates that fail to convert are forwarded\n", "issue": "Two circuit diagram tests that rest in `contrib` are failing on Windows\nSee: https://travis-ci.com/quantumlib/Cirq/jobs/202641395\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 typing import Optional, cast, TYPE_CHECKING\n\nimport numpy as np\n\nfrom cirq import ops, optimizers, protocols, linalg\nfrom cirq.circuits.circuit import Circuit\nfrom cirq.circuits.optimization_pass import (\n    PointOptimizationSummary,\n    PointOptimizer,\n)\n\nif TYPE_CHECKING:\n    # pylint: disable=unused-import\n    from typing import List\n\n\nclass ConvertToPauliStringPhasors(PointOptimizer):\n    \"\"\"Attempts to convert single-qubit gates into single-qubit\n    PauliStringPhasor operations.\n\n    Checks if the operation has a known unitary effect. If so, and the gate is a\n        1-qubit gate, then decomposes it into x, y, or z rotations and creates a\n        PauliStringPhasor for each.\n    \"\"\"\n\n    def __init__(self,\n                 ignore_failures: bool = False,\n                 keep_clifford: bool = False,\n                 atol: float = 0) -> None:\n        \"\"\"\n        Args:\n            ignore_failures: If set, gates that fail to convert are forwarded\n                unchanged. If not set, conversion failures raise a TypeError.\n            keep_clifford: If set, single qubit rotations in the Clifford group\n                are converted to SingleQubitCliffordGates.\n            atol: Maximum absolute error tolerance. The optimization is\n                permitted to round angles with a threshold determined by this\n                tolerance.\n        \"\"\"\n        super().__init__()\n        self.ignore_failures = ignore_failures\n        self.keep_clifford = keep_clifford\n        self.atol = atol\n\n    def _matrix_to_pauli_string_phasors(self,\n                                        mat: np.ndarray,\n                                        qubit: ops.Qid) -> ops.OP_TREE:\n        rotations = optimizers.single_qubit_matrix_to_pauli_rotations(\n            mat, self.atol)\n        out_ops = []  # type: List[ops.Operation]\n        for pauli, half_turns in rotations:\n            if (self.keep_clifford\n                    and linalg.all_near_zero_mod(half_turns, 0.5)):\n                cliff_gate = ops.SingleQubitCliffordGate.from_quarter_turns(\n                    pauli, round(half_turns * 2))\n                if out_ops and not isinstance(out_ops[-1],\n                                              ops.PauliStringPhasor):\n                    op = cast(ops.GateOperation, out_ops[-1])\n                    gate = cast(ops.SingleQubitCliffordGate, op.gate)\n                    out_ops[-1] = gate.merged_with(cliff_gate)(qubit)\n                else:\n                    out_ops.append(\n                        cliff_gate(qubit))\n            else:\n                pauli_string = ops.PauliString.from_single(qubit, pauli)\n                out_ops.append(\n                    ops.PauliStringPhasor(pauli_string,\n                                          exponent_neg=round(half_turns, 10)))\n        return out_ops\n\n    def _convert_one(self, op: ops.Operation) -> ops.OP_TREE:\n        # Don't change if it's already a ops.PauliStringPhasor\n        if isinstance(op, ops.PauliStringPhasor):\n            return op\n\n        if (self.keep_clifford\n            and isinstance(op, ops.GateOperation)\n                and isinstance(op.gate, ops.SingleQubitCliffordGate)):\n            return op\n\n        # Single qubit gate with known matrix?\n        if len(op.qubits) == 1:\n            mat = protocols.unitary(op, None)\n            if mat is not None:\n                return self._matrix_to_pauli_string_phasors(mat, op.qubits[0])\n\n        # Just let it be?\n        if self.ignore_failures:\n            return op\n\n        raise TypeError(\"Don't know how to work with {!r}. \"\n                        \"It isn't a 1-qubit operation with a known unitary \"\n                        \"effect.\".format(op))\n\n    def convert(self, op: ops.Operation) -> ops.OP_TREE:\n        converted = self._convert_one(op)\n        if converted is op:\n            return converted\n        return [self.convert(cast(ops.Operation, e))\n                for e in ops.flatten_op_tree(converted)]\n\n    def optimization_at(self, circuit: Circuit, index: int, op: ops.Operation\n                        ) -> Optional[PointOptimizationSummary]:\n        converted = self.convert(op)\n        if converted is op:\n            return None\n\n        return PointOptimizationSummary(\n            clear_span=1,\n            new_operations=converted,\n            clear_qubits=op.qubits)\n", "path": "cirq/contrib/paulistring/convert_to_pauli_string_phasors.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 typing import Optional, cast, TYPE_CHECKING\n\nimport numpy as np\n\nfrom cirq import ops, optimizers, protocols, linalg\nfrom cirq.circuits.circuit import Circuit\nfrom cirq.circuits.optimization_pass import (\n    PointOptimizationSummary,\n    PointOptimizer,\n)\n\nif TYPE_CHECKING:\n    # pylint: disable=unused-import\n    from typing import List\n\n\nclass ConvertToPauliStringPhasors(PointOptimizer):\n    \"\"\"Attempts to convert single-qubit gates into single-qubit\n    PauliStringPhasor operations.\n\n    Checks if the operation has a known unitary effect. If so, and the gate is a\n        1-qubit gate, then decomposes it into x, y, or z rotations and creates a\n        PauliStringPhasor for each.\n    \"\"\"\n\n    def __init__(self,\n                 ignore_failures: bool = False,\n                 keep_clifford: bool = False,\n                 atol: float = 1e-14) -> None:\n        \"\"\"\n        Args:\n            ignore_failures: If set, gates that fail to convert are forwarded\n                unchanged. If not set, conversion failures raise a TypeError.\n            keep_clifford: If set, single qubit rotations in the Clifford group\n                are converted to SingleQubitCliffordGates.\n            atol: Maximum absolute error tolerance. The optimization is\n                permitted to round angles with a threshold determined by this\n                tolerance.\n        \"\"\"\n        super().__init__()\n        self.ignore_failures = ignore_failures\n        self.keep_clifford = keep_clifford\n        self.atol = atol\n\n    def _matrix_to_pauli_string_phasors(self,\n                                        mat: np.ndarray,\n                                        qubit: ops.Qid) -> ops.OP_TREE:\n        rotations = optimizers.single_qubit_matrix_to_pauli_rotations(\n            mat, self.atol)\n        out_ops = []  # type: List[ops.Operation]\n        for pauli, half_turns in rotations:\n            if (self.keep_clifford\n                    and linalg.all_near_zero_mod(half_turns, 0.5)):\n                cliff_gate = ops.SingleQubitCliffordGate.from_quarter_turns(\n                    pauli, round(half_turns * 2))\n                if out_ops and not isinstance(out_ops[-1],\n                                              ops.PauliStringPhasor):\n                    op = cast(ops.GateOperation, out_ops[-1])\n                    gate = cast(ops.SingleQubitCliffordGate, op.gate)\n                    out_ops[-1] = gate.merged_with(cliff_gate)(qubit)\n                else:\n                    out_ops.append(\n                        cliff_gate(qubit))\n            else:\n                pauli_string = ops.PauliString.from_single(qubit, pauli)\n                out_ops.append(\n                    ops.PauliStringPhasor(pauli_string,\n                                          exponent_neg=round(half_turns, 10)))\n        return out_ops\n\n    def _convert_one(self, op: ops.Operation) -> ops.OP_TREE:\n        # Don't change if it's already a ops.PauliStringPhasor\n        if isinstance(op, ops.PauliStringPhasor):\n            return op\n\n        if (self.keep_clifford\n            and isinstance(op, ops.GateOperation)\n                and isinstance(op.gate, ops.SingleQubitCliffordGate)):\n            return op\n\n        # Single qubit gate with known matrix?\n        if len(op.qubits) == 1:\n            mat = protocols.unitary(op, None)\n            if mat is not None:\n                return self._matrix_to_pauli_string_phasors(mat, op.qubits[0])\n\n        # Just let it be?\n        if self.ignore_failures:\n            return op\n\n        raise TypeError(\"Don't know how to work with {!r}. \"\n                        \"It isn't a 1-qubit operation with a known unitary \"\n                        \"effect.\".format(op))\n\n    def convert(self, op: ops.Operation) -> ops.OP_TREE:\n        converted = self._convert_one(op)\n        if converted is op:\n            return converted\n        return [self.convert(cast(ops.Operation, e))\n                for e in ops.flatten_op_tree(converted)]\n\n    def optimization_at(self, circuit: Circuit, index: int, op: ops.Operation\n                        ) -> Optional[PointOptimizationSummary]:\n        converted = self.convert(op)\n        if converted is op:\n            return None\n\n        return PointOptimizationSummary(\n            clear_span=1,\n            new_operations=converted,\n            clear_qubits=op.qubits)\n", "path": "cirq/contrib/paulistring/convert_to_pauli_string_phasors.py"}]}