Skip to content

Commit

Permalink
Delete schedules (#2589)
Browse files Browse the repository at this point in the history
- Delete cirq/schedules directory
- Remove Device.duration_of/validate_schedule/validate_scheduled_operation
- Remove all validate_schedule methods (but leave duration_of on specific devices for now)
- Remove all references to cirq.Schedule
- Maintain engine backwards compatibility by auto-converting to circuits in schedule contexts

Skipping deprecation because there's no reasonable way to half support schedules, and
this would tie us up for months bending over backwards for a feature we think
nobody uses.

Fixes #2478
  • Loading branch information
Strilanc authored and CirqBot committed Nov 22, 2019
1 parent 8902820 commit 1c5084a
Show file tree
Hide file tree
Showing 70 changed files with 370 additions and 2,092 deletions.
7 changes: 0 additions & 7 deletions cirq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
from cirq import (
# Core
circuits,
schedules,
# Optimize and run
optimizers,
work,
Expand Down Expand Up @@ -299,12 +298,6 @@
two_qubit_matrix_to_operations,
)

from cirq.schedules import (
moment_by_moment_schedule,
Schedule,
ScheduledOperation,
)

from cirq.sim import (
bloch_vector_from_state_vector,
StabilizerStateChForm,
Expand Down
21 changes: 11 additions & 10 deletions cirq/aqt/aqt_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@
import json
import time
import uuid
from typing import Iterable, List, Union, Tuple, Dict, cast
from typing import Iterable, List, Union, Tuple, Dict, cast, TYPE_CHECKING

import numpy as np
from requests import put
from cirq import circuits, Sampler, resolve_parameters, LineQubit
from cirq.study.sweeps import Sweep
from cirq.aqt.aqt_device import AQTSimulator, get_op_string
from cirq import study, ops, schedules, IonDevice
from cirq import study, ops, IonDevice

if TYPE_CHECKING:
import cirq

Sweepable = Union[study.ParamResolver, Iterable[study.ParamResolver], Sweep,
Iterable[Sweep]]
Expand Down Expand Up @@ -168,16 +171,16 @@ def _send_json(self,
return measurements

def run_sweep(self,
program: Union[circuits.Circuit, schedules.Schedule],
program: 'cirq.Circuit',
params: study.Sweepable,
repetitions: int = 1) -> List[study.TrialResult]:
"""Samples from the given Circuit or Schedule.
"""Samples from the given Circuit.
In contrast to run, this allows for sweeping over different parameter
values.
Args:
program: The circuit or schedule to simulate.
program: The circuit to simulate.
Should be generated using AQTSampler.generate_circuit_from_list
params: Parameters to run with the program.
repetitions: The number of repetitions to simulate.
Expand All @@ -187,14 +190,12 @@ def run_sweep(self,
resolver.
"""
meas_name = 'm' # TODO: Get measurement name from circuit. Issue #2195
circuit = (program.to_circuit()
if isinstance(program, schedules.Schedule) else program)
assert isinstance(circuit.device, IonDevice)
assert isinstance(program.device, IonDevice)
trial_results = [] # type: List[study.TrialResult]
for param_resolver in study.to_resolvers(params):
id_str = uuid.uuid1()
num_qubits = len(circuit.device.qubits)
json_str = self._generate_json(circuit=circuit,
num_qubits = len(program.device.qubits)
json_str = self._generate_json(circuit=program,
param_resolver=param_resolver)
results = self._send_json(json_str=json_str,
id_str=id_str,
Expand Down
22 changes: 0 additions & 22 deletions cirq/circuits/circuit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@ def validate_moment(self, moment):
raise ValueError('not isinstance({!r}, {!r})'.format(
moment, cirq.Moment))

def duration_of(self, operation):
return cirq.Duration(picos=0) # coverage: ignore

def validate_schedule(self, schedule):
pass

def validate_scheduled_operation(self, schedule, scheduled_operation):
pass


moment_and_op_type_validating_device = _MomentAndOpTypeValidatingDeviceType()

Expand Down Expand Up @@ -125,22 +116,9 @@ def test_approx_eq():

class TestDevice(cirq.Device):

def duration_of(self, operation: cirq.Operation) -> cirq.Duration:
pass

def validate_operation(self, operation: cirq.Operation) -> None:
pass

def validate_scheduled_operation(
self,
schedule: cirq.Schedule,
scheduled_operation: cirq.ScheduledOperation
) -> None:
pass

def validate_schedule(self, schedule: 'cirq.Schedule') -> None:
pass

a = cirq.NamedQubit('a')
b = cirq.NamedQubit('b')

Expand Down
23 changes: 2 additions & 21 deletions cirq/contrib/acquaintance/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import abc

from cirq import circuits, devices, ops, schedules
from cirq import circuits, devices, ops
from cirq.contrib.acquaintance.gates import (
AcquaintanceOpportunityGate, SwapNetworkGate)
from cirq.contrib.acquaintance.bipartite import (
Expand All @@ -31,12 +31,7 @@


class AcquaintanceDevice(devices.Device, metaclass=abc.ABCMeta):
"""A device that contains only acquaintance and permutation gates.
Raises:
NotImplementedError: Any of the schedule-related methods (duration_of,
validate_schedule[d_operation]) is called.
"""
"""A device that contains only acquaintance and permutation gates."""
gate_types = (AcquaintanceOpportunityGate, PermutationGate)

def validate_operation(self, operation: 'cirq.Operation') -> None:
Expand All @@ -47,20 +42,6 @@ def validate_operation(self, operation: 'cirq.Operation') -> None:
'ininstance({0!r}.gate, {2!r})'.format(
operation, ops.Operation, self.gate_types))

def duration_of(self, operation):
raise NotImplementedError()

def validate_scheduled_operation(
self,
schedule: schedules.Schedule,
scheduled_operation: schedules.ScheduledOperation
) -> None:
raise NotImplementedError()


def validate_schedule(self, schedule: schedules.Schedule) -> None:
raise NotImplementedError()


def is_acquaintance_strategy(circuit: 'cirq.Circuit'):
return isinstance(circuit._device, AcquaintanceDevice)
Expand Down
17 changes: 1 addition & 16 deletions cirq/contrib/graph_device/graph_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from typing import Iterable, Optional

from cirq import devices, ops, value, schedules
from cirq import devices, ops, value

from cirq.contrib.graph_device.hypergraph import UndirectedHypergraph

Expand Down Expand Up @@ -196,21 +196,6 @@ def validate_moment(self, moment: ops.Moment):
other_ops = ops[:i] + ops[i + 1:]
self.validate_crosstalk(op, other_ops)

def validate_scheduled_operation(
self, schedule: schedules.Schedule,
scheduled_operation: schedules.ScheduledOperation) -> None:
operation = scheduled_operation.operation
self.validate_operation(operation)

other_operations = (
scheduled_operation.operation for scheduled_operation in
schedule.operations_happening_at_same_time_as(scheduled_operation))
self.validate_crosstalk(operation, other_operations)

def validate_schedule(self, schedule: schedules.Schedule) -> None:
for scheduled_operation in schedule.scheduled_operations:
self.validate_scheduled_operation(schedule, scheduled_operation)

def __eq__(self, other):
return ((self.device_graph == other.device_graph) and
(self.crosstalk_graph == other.crosstalk_graph))
Expand Down
13 changes: 0 additions & 13 deletions cirq/contrib/graph_device/graph_device_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,30 +148,17 @@ def not_cnots(first_op, second_op):
moment = cirq.Moment([cirq.CNOT(*qubits[:2]), cirq.CNOT(*qubits[2:])])
with pytest.raises(ValueError):
graph_device.validate_moment(moment)
with pytest.raises(ValueError):
scheduled_operations = (cirq.ScheduledOperation.op_at_on(
op, cirq.Timestamp(), graph_device) for op in moment.operations)
schedule = cirq.Schedule(graph_device, scheduled_operations)
graph_device.validate_schedule(schedule)

moment = cirq.Moment(
[cirq.CNOT(qubits[0], qubits[3]),
cirq.CZ(qubits[1], qubits[2])])
graph_device.validate_moment(moment)
circuit = cirq.Circuit(moment, device=graph_device)
schedule = cirq.moment_by_moment_schedule(graph_device, circuit)
assert graph_device.validate_schedule(schedule) is None

moment = cirq.Moment(
[cirq.CNOT(qubits[0], qubits[3]),
cirq.CNOT(qubits[1], qubits[2])])
with pytest.raises(ValueError):
graph_device.validate_moment(moment)
with pytest.raises(ValueError):
scheduled_operations = (cirq.ScheduledOperation.op_at_on(
op, cirq.Timestamp(), graph_device) for op in moment.operations)
schedule = cirq.Schedule(graph_device, scheduled_operations)
graph_device.validate_schedule(schedule)


def test_graph_device_copy_and_add():
Expand Down
8 changes: 3 additions & 5 deletions cirq/contrib/noise_models/noise_models_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@

def test_moment_is_measurements():
q = cirq.LineQubit.range(2)
circ = cirq.Circuit.from_ops(
[cirq.X(q[0]), cirq.X(q[1]),
cirq.measure(*q, key='z')])
circ = cirq.Circuit([cirq.X(q[0]), cirq.X(q[1]), cirq.measure(*q, key='z')])
assert not _homogeneous_moment_is_measurements(circ[0])
assert _homogeneous_moment_is_measurements(circ[1])


def test_moment_is_measurements_mixed1():
q = cirq.LineQubit.range(2)
circ = cirq.Circuit.from_ops([
circ = cirq.Circuit([
cirq.X(q[0]),
cirq.X(q[1]),
cirq.measure(q[0], key='z'),
Expand All @@ -46,7 +44,7 @@ def test_moment_is_measurements_mixed1():

def test_moment_is_measurements_mixed2():
q = cirq.LineQubit.range(2)
circ = cirq.Circuit.from_ops([
circ = cirq.Circuit([
cirq.X(q[0]),
cirq.X(q[1]),
cirq.Z(q[0]),
Expand Down
36 changes: 1 addition & 35 deletions cirq/devices/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

import abc

from cirq.value import Duration


if TYPE_CHECKING:
import cirq
Expand All @@ -26,7 +24,7 @@


class Device(metaclass=abc.ABCMeta):
"""Hardware constraints for validating circuits and schedules."""
"""Hardware constraints for validating circuits."""

def decompose_operation(self, operation: 'cirq.Operation'
) -> 'cirq.OP_TREE':
Expand All @@ -38,10 +36,6 @@ def decompose_operation(self, operation: 'cirq.Operation'
"""
return operation

@abc.abstractmethod
def duration_of(self, operation: 'cirq.Operation') -> Duration:
pass

@abc.abstractmethod
def validate_operation(self, operation: 'cirq.Operation') -> None:
"""Raises an exception if an operation is not valid.
Expand All @@ -53,23 +47,6 @@ def validate_operation(self, operation: 'cirq.Operation') -> None:
ValueError: The operation isn't valid for this device.
"""

@abc.abstractmethod
def validate_scheduled_operation(
self,
schedule: 'cirq.Schedule',
scheduled_operation: 'cirq.ScheduledOperation'
) -> None:
"""Raises an exception if the scheduled operation is not valid.
Args:
schedule: The schedule to validate against.
scheduled_operation: The scheduled operation to validate.
Raises:
ValueError: If the scheduled operation is not valid for the
schedule.
"""

def validate_circuit(self, circuit: 'cirq.Circuit') -> None:
"""Raises an exception if a circuit is not valid.
Expand Down Expand Up @@ -110,14 +87,3 @@ def can_add_operation_into_moment(self,
Whether or not the moment will validate after adding the operation.
"""
return not moment.operates_on(operation.qubits)

@abc.abstractmethod
def validate_schedule(self, schedule: 'cirq.Schedule') -> None:
"""Raises an exception if a schedule is not valid.
Args:
schedule: The schedule to validate.
Raises:
ValueError: The schedule isn't valid for this device.
"""
6 changes: 0 additions & 6 deletions cirq/devices/unconstrained_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,12 @@ def duration_of(self, operation):
def validate_operation(self, operation):
pass

def validate_scheduled_operation(self, schedule, scheduled_operation):
pass

def validate_moment(self, moment):
pass

def validate_circuit(self, circuit):
pass

def validate_schedule(self, schedule):
pass

def __repr__(self):
return 'cirq.UNCONSTRAINED_DEVICE'

Expand Down
4 changes: 2 additions & 2 deletions cirq/experiments/single_qubit_readout_calibration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import List, Union
from typing import List

import numpy as np

Expand All @@ -39,7 +39,7 @@ def __init__(self,

def run_sweep(
self,
program: Union[cirq.Circuit, cirq.Schedule],
program: 'cirq.Circuit',
params: cirq.Sweepable,
repetitions: int = 1,
) -> List[cirq.TrialResult]:
Expand Down
4 changes: 2 additions & 2 deletions cirq/google/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
is_native_xmon_gate,
is_native_xmon_op,
pack_results,
schedule_from_proto_dicts,
schedule_to_proto_dicts,
circuit_as_schedule_to_proto_dicts,
circuit_from_schedule_from_proto_dicts,
unpack_results,
xmon_op_from_proto_dict,
)
Expand Down
4 changes: 2 additions & 2 deletions cirq/google/api/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
is_native_xmon_gate,
is_native_xmon_op,
pack_results,
schedule_from_proto_dicts,
schedule_to_proto_dicts,
circuit_as_schedule_to_proto_dicts,
circuit_from_schedule_from_proto_dicts,
unpack_results,
xmon_op_from_proto_dict,
)
Loading

0 comments on commit 1c5084a

Please sign in to comment.