Skip to content

Commit

Permalink
Delete things marked as deprecated-until-v0.7 (#2594)
Browse files Browse the repository at this point in the history
- Since we're now v0.7 dev, we can delete these things
  • Loading branch information
Strilanc authored and CirqBot committed Nov 23, 2019
1 parent 6d986e6 commit 993fa1e
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 119 deletions.
1 change: 0 additions & 1 deletion cirq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@
Moment,
MutableDensePauliString,
NamedQubit,
op_gate_isinstance,
op_gate_of_type,
OP_TREE,
Operation,
Expand Down
11 changes: 0 additions & 11 deletions cirq/circuits/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1500,17 +1500,6 @@ def final_wavefunction(
result = _apply_unitary_circuit(self, state, qs, dtype)
return result.reshape((state_len,))

to_unitary_matrix = deprecated(
name='Circuit.to_unitary_matrix',
deadline='v0.7.0',
fix='Use `Circuit.unitary()` instead.')(unitary)

apply_unitary_effect_to_state = deprecated(
name='Circuit.apply_unitary_effect_to_state',
deadline='v0.7.0',
fix="Use `cirq.final_wavefunction(circuit)` or "
"`Circuit.final_wavefunction()` instead")(final_wavefunction)

def to_text_diagram(
self,
*,
Expand Down
19 changes: 0 additions & 19 deletions cirq/circuits/circuit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3186,25 +3186,6 @@ def test_moment_groups():
""", use_unicode_characters=True)


def test_deprecated_to_unitary_matrix():
with capture_logging() as log:
np.testing.assert_allclose(cirq.Circuit().to_unitary_matrix(),
cirq.Circuit().unitary())
assert len(log) == 1
assert 'to_unitary_matrix' in log[0].getMessage()
assert 'deprecated' in log[0].getMessage()


def test_deprecated_apply_unitary_effect_to_state():
with capture_logging() as log:
np.testing.assert_allclose(
cirq.Circuit().apply_unitary_effect_to_state(),
cirq.Circuit().final_wavefunction())
assert len(log) == 1
assert 'apply_unitary_effect_to_state' in log[0].getMessage()
assert 'deprecated' in log[0].getMessage()


def test_moments_property():
q = cirq.NamedQubit('q')
c = cirq.Circuit(cirq.X(q), cirq.Y(q))
Expand Down
1 change: 0 additions & 1 deletion cirq/ops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@

from cirq.ops.gate_operation import (
GateOperation,
op_gate_isinstance,
op_gate_of_type,
)

Expand Down
9 changes: 1 addition & 8 deletions cirq/ops/gate_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,9 @@ def _equal_up_to_global_phase_(self,
TV = TypeVar('TV', bound=raw_types.Gate)


@deprecated(deadline='v0.7.0',
@deprecated(deadline='v0.8.0',
fix='use: `op.gate if isinstance(op.gate, gate_type) else None`')
def op_gate_of_type(op: Any, gate_type: Type[TV]) -> Optional[TV]:
"""Returns gate of given type, if op has that gate otherwise None."""
gate = getattr(op, 'gate', None)
return gate if isinstance(gate, gate_type) else None


@deprecated(deadline='v0.7.0', fix='use: `isinstance(op.gate, gate_type)`')
def op_gate_isinstance(op: Any, gate_type: Type[TV]) -> bool:
"""Determines if op is a GateOperation with a gate of the given type."""
gate = getattr(op, 'gate', None)
return isinstance(gate, gate_type)
51 changes: 14 additions & 37 deletions cirq/ops/gate_operation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import pytest
import sympy
import cirq
from cirq._compat_test import capture_logging


def test_gate_operation_init():
Expand Down Expand Up @@ -273,38 +274,19 @@ def on(self, *qubits):
def test_op_gate_of_type():
a = cirq.NamedQubit('a')
op = cirq.X(a)
assert cirq.op_gate_of_type(op, cirq.XPowGate) == op.gate
assert cirq.op_gate_of_type(op, cirq.YPowGate) is None
with capture_logging():
assert cirq.op_gate_of_type(op, cirq.XPowGate) == op.gate
assert cirq.op_gate_of_type(op, cirq.YPowGate) is None

class NonGateOperation(cirq.Operation):
class NonGateOperation(cirq.Operation):

def qubits(self):
pass
def qubits(self):
pass

def with_qubits(self, *new_qubits):
pass
def with_qubits(self, *new_qubits):
pass

assert cirq.op_gate_of_type(NonGateOperation(), cirq.XPowGate) is None


def test_op_gate_isinstance():
a = cirq.NamedQubit('a')
op = cirq.X(a)
assert cirq.op_gate_isinstance(op, cirq.XPowGate)
assert not cirq.op_gate_isinstance(op, cirq.YPowGate)
assert cirq.op_gate_isinstance(op, (cirq.XPowGate, cirq.YPowGate))
assert not cirq.op_gate_isinstance(op, (cirq.YPowGate, cirq.ZPowGate))

class NonGateOperation(cirq.Operation):

def qubits(self):
pass

def with_qubits(self, *new_qubits):
pass

assert not cirq.op_gate_isinstance(NonGateOperation(), cirq.XPowGate)
assert not cirq.op_gate_isinstance(NonGateOperation(), NonGateOperation)
assert cirq.op_gate_of_type(NonGateOperation(), cirq.XPowGate) is None


@pytest.mark.parametrize('gate1,gate2,eq_up_to_global_phase', [
Expand All @@ -331,15 +313,10 @@ def test_equal_up_to_global_phase_on_diff_types():
def test_gate_on_operation_besides_gate_operation():
a, b = cirq.LineQubit.range(2)

assert cirq.op_gate_of_type(
-1j * cirq.X(a) * cirq.Y(b),
cirq.DensePauliString) == -1j * cirq.DensePauliString('XY')

assert cirq.op_gate_isinstance(-1j * cirq.X(a) * cirq.Y(b),
cirq.DensePauliString)

assert not cirq.op_gate_isinstance(-1j * cirq.X(a) * cirq.Y(b),
cirq.XPowGate)
op = -1j * cirq.X(a) * cirq.Y(b)
assert isinstance(op.gate, cirq.DensePauliString)
assert op.gate == -1j * cirq.DensePauliString('XY')
assert not isinstance(op.gate, cirq.XPowGate)


def test_mul():
Expand Down
9 changes: 0 additions & 9 deletions cirq/ops/pauli_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import numpy as np

from cirq import value, protocols, linalg
from cirq._compat import deprecated
from cirq._doc import document
from cirq.ops import (
global_phase_op,
Expand Down Expand Up @@ -129,14 +128,6 @@ def __init__(
self._qubit_pauli_map = p.paulis
self._coefficient = p.coef

@staticmethod
@deprecated(deadline="v0.7.0",
fix="call cirq.PauliString(pauli(qubit)) instead")
def from_single(qubit: 'cirq.Qid',
pauli: pauli_gates.Pauli) -> 'PauliString':
"""Creates a PauliString with a single qubit."""
return PauliString(qubit_pauli_map={qubit: pauli})

@property
def coefficient(self) -> complex:
return self._coefficient
Expand Down
12 changes: 0 additions & 12 deletions cirq/ops/pauli_string_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import sympy

import cirq
from cirq._compat_test import capture_logging


def _make_qubits(n):
Expand Down Expand Up @@ -220,17 +219,6 @@ def test_constructor_flexibility():
qubit_pauli_map={a: cirq.Z}, coefficient=6j)


def test_deprecated_from_single():
q0 = cirq.LineQubit(0)
with capture_logging() as log:
actual = cirq.PauliString.from_single(q0, cirq.X)
assert len(log) == 1 # May fail if deprecated thing is used elsewhere.
assert 'PauliString.from_single' in log[0].getMessage()
assert 'deprecated' in log[0].getMessage()

assert actual == cirq.PauliString([cirq.X(q0)])


@pytest.mark.parametrize('qubit_pauli_map', _sample_qubit_pauli_maps())
def test_getitem(qubit_pauli_map):
other = cirq.NamedQubit('other')
Expand Down
10 changes: 1 addition & 9 deletions cirq/value/duration.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import sympy

from cirq import protocols
from cirq._compat import proper_repr, deprecated
from cirq._compat import proper_repr
from cirq._doc import document

if TYPE_CHECKING:
Expand Down Expand Up @@ -83,14 +83,6 @@ def __init__(
micros * 1000_000 +
millis * 1000_000_000)

@classmethod
@deprecated(deadline='v0.7',
fix='Use `cirq.Duration(...)` instead.',
name='cirq.Duration.create')
def create(cls, duration: DURATION_LIKE) -> 'Duration':
"""Creates a Duration from datetime.timedelta if necessary"""
return Duration(duration)

def _is_parameterized_(self):
return protocols.is_parameterized(self._picos)

Expand Down
11 changes: 0 additions & 11 deletions cirq/value/duration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import sympy

import cirq
from cirq._compat_test import capture_logging
from cirq.value import Duration


Expand Down Expand Up @@ -93,16 +92,6 @@ def test_eq():
assert Duration(picos=1) != 0


def test_create_deprecated():
with capture_logging() as log:
actual = cirq.Duration.create(timedelta(0))
assert len(log) == 1
assert 'cirq.Duration.create was used' in log[0].getMessage()
assert 'deprecated' in log[0].getMessage()

assert actual == cirq.Duration()


def test_parameterized():
t = sympy.Symbol('t')
assert not cirq.is_parameterized(Duration())
Expand Down
1 change: 0 additions & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ Circuits, Operations, and Moments.
cirq.OP_TREE
cirq.flatten_op_tree
cirq.freeze_op_tree
cirq.op_gate_isinstance
cirq.op_gate_of_type
cirq.transform_op_tree
cirq.Circuit
Expand Down

0 comments on commit 993fa1e

Please sign in to comment.