Example #1
0
def test_get_schedule(list_time_slots):
    results = [
        qtypes.QuantumTimeSlot(
            processor_name='potofgold',
            start_time=Timestamp(seconds=1000020000),
            end_time=Timestamp(seconds=1000040000),
            slot_type=qenums.QuantumTimeSlot.TimeSlotType.MAINTENANCE,
            maintenance_config=qtypes.QuantumTimeSlot.MaintenanceConfig(
                title='Testing',
                description='Testing some new configuration.',
            ),
        ),
        qtypes.QuantumTimeSlot(
            processor_name='potofgold',
            start_time=Timestamp(seconds=1000010000),
            end_time=Timestamp(seconds=1000020000),
            slot_type=qenums.QuantumTimeSlot.TimeSlotType.RESERVATION,
            reservation_config=qtypes.QuantumTimeSlot.ReservationConfig(
                project_id='super_secret_quantum'),
        ),
    ]
    list_time_slots.return_value = results
    processor = cg.EngineProcessor('proj', 'p0', EngineContext())
    assert (processor.get_schedule(
        datetime.datetime.fromtimestamp(1000000000),
        datetime.datetime.fromtimestamp(1000050000)) == results)
    list_time_slots.assert_called_once_with(
        'proj', 'p0', 'start_time < 1000050000 AND end_time > 1000000000')
Example #2
0
def test_list_time_slots(client_constructor):
    grpc_client = setup_mock_(client_constructor)
    results = [
        qtypes.QuantumTimeSlot(
            processor_name='potofgold',
            start_time=Timestamp(seconds=1000020000),
            end_time=Timestamp(seconds=1000040000),
            slot_type=qenums.QuantumTimeSlot.TimeSlotType.MAINTENANCE,
            maintenance_config=qtypes.QuantumTimeSlot.MaintenanceConfig(
                title='Testing',
                description='Testing some new configuration.',
            ),
        ),
        qtypes.QuantumTimeSlot(
            processor_name='potofgold',
            start_time=Timestamp(seconds=1000010000),
            end_time=Timestamp(seconds=1000020000),
            slot_type=qenums.QuantumTimeSlot.TimeSlotType.RESERVATION,
            reservation_config=qtypes.QuantumTimeSlot.ReservationConfig(
                project_id='super_secret_quantum'),
        )
    ]
    grpc_client.list_quantum_time_slots.return_value = results

    client = EngineClient()
    assert (client.list_time_slots('proj', 'processor0') == results)
Example #3
0
def test_get_available_processors_open_swim_outside_window(
        schedule_mock, time_mock, engine_mock):
    os.environ['GOOGLE_CLOUD_PROJECT'] = 'some_project'
    schedule_mock.return_value = [
        qtypes.QuantumTimeSlot(
            processor_name='Sycamore23',
            start_time=Timestamp(seconds=300),
            end_time=Timestamp(seconds=500),
            slot_type=enums.QuantumTimeSlot.TimeSlotType.OPEN_SWIM)
    ]
    time_mock.return_value = datetime.fromtimestamp(700)
    assert recirq.get_available_processors(['Sycamore23']) == []
Example #4
0
def test_get_available_processors_other_project_reservation(
        schedule_mock, time_mock, engine_mock):
    os.environ['GOOGLE_CLOUD_PROJECT'] = 'some_project'
    schedule_mock.return_value = [
        qtypes.QuantumTimeSlot(
            processor_name='Sycamore23',
            start_time=Timestamp(seconds=100),
            end_time=Timestamp(seconds=500),
            slot_type=enums.QuantumTimeSlot.TimeSlotType.RESERVATION,
            reservation_config=qtypes.QuantumTimeSlot.ReservationConfig(
                project_id='other_project'),
        )
    ]
    time_mock.return_value = datetime.fromtimestamp(300)
    assert recirq.get_available_processors(['Sycamore23']) == []