Skip to content

Commit 817d6c9

Browse files
authored
Fix using mutable Extensions() instances as default parameters (#294)
* reapply issue-283 changes * remove unnecessary change * another typo * removing parens as suggested - tests still pass
1 parent bbf2cee commit 817d6c9

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

CONTRIBUTING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ To do this, you must first install `protobuf-compiler` and `virtualenv`:
3636
sudo apt-get install protobuf-compiler virtualenv
3737
```
3838

39+
If you are using python3, you must also install `python3-tk`:
40+
41+
```bash
42+
sudo apt-get install python3-tk
43+
```
44+
3945
Next, from the root directory of your clone of cirq's repository, run the
4046
continuous integration scripts:
4147

cirq/circuits/circuit.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,10 @@ def __str__(self):
333333

334334
def to_unitary_matrix(
335335
self,
336-
qubit_order_key: Callable[[QubitId], Any]=None,
336+
qubit_order_key: Callable[[QubitId], Any] = None,
337337
qubits_that_should_be_present: Iterable[QubitId] = (),
338-
ignore_terminal_measurements=True,
339-
ext: Extensions=None) -> np.ndarray:
338+
ignore_terminal_measurements = True,
339+
ext: Extensions = None) -> np.ndarray:
340340
"""Converts the circuit into a unitary matrix, if possible.
341341
342342
Args:
@@ -395,7 +395,7 @@ def is_ignorable_measurement(moment_index, operation):
395395

396396
def to_text_diagram(
397397
self,
398-
ext: Extensions = Extensions(),
398+
ext: Extensions = None,
399399
use_unicode_characters: bool = True,
400400
transpose: bool = False,
401401
qubit_order_key: Callable[[QubitId], Any] = None) -> str:
@@ -419,6 +419,9 @@ def to_text_diagram(
419419
if qubit_order_key is None:
420420
qubit_order_key = _str_lexicographic_respecting_int_order
421421

422+
if ext is None:
423+
ext = Extensions()
424+
422425
qubits = {
423426
q
424427
for moment in self.moments for op in moment.operations

cirq/circuits/expand_composite.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ class ExpandComposite(PointOptimizer):
3333
"""
3434

3535
def __init__(self,
36-
composite_gate_extension: Extensions = Extensions()) -> None:
36+
composite_gate_extension: Extensions = None) -> None:
3737
"""Construct the optimization pass.
3838
3939
Args:
4040
composite_gate_extension: An extension that that can be used
4141
to supply or override a CompositeGate decomposition.
4242
"""
43-
self.extension = composite_gate_extension
43+
self.extension = composite_gate_extension or Extensions()
4444

4545
def optimization_at(self, circuit, index, op):
4646
decomposition = self._decompose(op)

cirq/google/merge_interactions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ class MergeInteractions(PointOptimizer):
3434
def __init__(self,
3535
tolerance: float = 1e-8,
3636
allow_partial_czs: bool = True,
37-
extensions: Extensions = Extensions()) -> None:
37+
extensions: Extensions = None) -> None:
3838
self.tolerance = tolerance
3939
self.allow_partial_czs = allow_partial_czs
40-
self.extensions = extensions
40+
self.extensions = extensions or Extensions()
4141

4242
def optimization_at(self, circuit, index, op):
4343
if len(op.qubits) != 2:

0 commit comments

Comments
 (0)