Skip to content

Commit 2474d47

Browse files
JaShompavoljuhas
andauthored
Removed deprecated processor_ids (#6563)
* removed deprecated processor_ids in Engine, EngineProgram and EngineClient * Made processor_id required, engine.md updated * Update engine.md removed the `[]` for processor_id * processor_id required in Engine, omitted a condition in EngineClient * Format and lint changes made --------- Co-authored-by: Pavol Juhas <[email protected]>
1 parent 5828147 commit 2474d47

File tree

7 files changed

+72
-195
lines changed

7 files changed

+72
-195
lines changed

cirq-google/cirq_google/engine/engine.py

+7-33
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import enum
2828
import random
2929
import string
30-
from typing import Dict, List, Optional, Sequence, Set, TypeVar, Union, TYPE_CHECKING
30+
from typing import Dict, List, Optional, Set, TypeVar, Union, TYPE_CHECKING
3131

3232
import duet
3333
import google.auth
@@ -210,21 +210,19 @@ def __init__(
210210
def __str__(self) -> str:
211211
return f'Engine(project_id={self.project_id!r})'
212212

213-
# TODO(#6271): Deprecate and remove processor_ids before v1.4
214213
def run(
215214
self,
216215
program: cirq.AbstractCircuit,
216+
processor_id: str,
217217
program_id: Optional[str] = None,
218218
job_id: Optional[str] = None,
219219
param_resolver: cirq.ParamResolver = cirq.ParamResolver({}),
220220
repetitions: int = 1,
221-
processor_ids: Sequence[str] = ('xmonsim',),
222221
program_description: Optional[str] = None,
223222
program_labels: Optional[Dict[str, str]] = None,
224223
job_description: Optional[str] = None,
225224
job_labels: Optional[Dict[str, str]] = None,
226225
*,
227-
processor_id: str = "",
228226
run_name: str = "",
229227
device_config_name: str = "",
230228
) -> cirq.Result:
@@ -244,15 +242,11 @@ def run(
244242
and day.
245243
param_resolver: Parameters to run with the program.
246244
repetitions: The number of repetitions to simulate.
247-
processor_ids: Deprecated list of candidate processor ids to run the program.
248-
Only allowed to contain one processor_id. If the argument `processor_id`
249-
is non-empty, `processor_ids` will be ignored.
250245
program_description: An optional description to set on the program.
251246
program_labels: Optional set of labels to set on the program.
252247
job_description: An optional description to set on the job.
253248
job_labels: Optional set of labels to set on the job.
254-
processor_id: Processor id for running the program. If not set,
255-
`processor_ids` will be used.
249+
processor_id: Processor id for running the program.
256250
run_name: A unique identifier representing an automation run for the
257251
specified processor. An Automation Run contains a collection of
258252
device configurations for a processor. If specified, `processor_id`
@@ -267,9 +261,7 @@ def run(
267261
268262
Raises:
269263
ValueError: If no gate set is provided.
270-
ValueError: If neither `processor_id` or `processor_ids` are set.
271264
ValueError: If only one of `run_name` and `device_config_name` are specified.
272-
ValueError: If `processor_ids` has more than one processor id.
273265
ValueError: If either `run_name` and `device_config_name` are set but
274266
`processor_id` is empty.
275267
"""
@@ -280,32 +272,29 @@ def run(
280272
job_id=job_id,
281273
params=[param_resolver],
282274
repetitions=repetitions,
283-
processor_ids=processor_ids,
275+
processor_id=processor_id,
284276
program_description=program_description,
285277
program_labels=program_labels,
286278
job_description=job_description,
287279
job_labels=job_labels,
288-
processor_id=processor_id,
289280
run_name=run_name,
290281
device_config_name=device_config_name,
291282
)
292283
)[0]
293284

294-
# TODO(#6271): Deprecate and remove processor_ids before v1.4
295285
async def run_sweep_async(
296286
self,
297287
program: cirq.AbstractCircuit,
288+
processor_id: str,
298289
program_id: Optional[str] = None,
299290
job_id: Optional[str] = None,
300291
params: cirq.Sweepable = None,
301292
repetitions: int = 1,
302-
processor_ids: Sequence[str] = ('xmonsim',),
303293
program_description: Optional[str] = None,
304294
program_labels: Optional[Dict[str, str]] = None,
305295
job_description: Optional[str] = None,
306296
job_labels: Optional[Dict[str, str]] = None,
307297
*,
308-
processor_id: str = "",
309298
run_name: str = "",
310299
device_config_name: str = "",
311300
) -> engine_job.EngineJob:
@@ -328,15 +317,11 @@ async def run_sweep_async(
328317
and day.
329318
params: Parameters to run with the program.
330319
repetitions: The number of circuit repetitions to run.
331-
processor_ids: Deprecated list of candidate processor ids to run the program.
332-
Only allowed to contain one processor_id. If the argument `processor_id`
333-
is non-empty, `processor_ids` will be ignored.
334320
program_description: An optional description to set on the program.
335321
program_labels: Optional set of labels to set on the program.
336322
job_description: An optional description to set on the job.
337323
job_labels: Optional set of labels to set on the job.
338-
processor_id: Processor id for running the program. If not set,
339-
`processor_ids` will be used.
324+
processor_id: Processor id for running the program.
340325
run_name: A unique identifier representing an automation run for the
341326
specified processor. An Automation Run contains a collection of
342327
device configurations for a processor. If specified, `processor_id`
@@ -352,22 +337,12 @@ async def run_sweep_async(
352337
353338
Raises:
354339
ValueError: If no gate set is provided.
355-
ValueError: If neither `processor_id` or `processor_ids` are set.
356340
ValueError: If only one of `run_name` and `device_config_name` are specified.
357-
ValueError: If `processor_ids` has more than one processor id.
358341
ValueError: If either `run_name` and `device_config_name` are set but
359342
`processor_id` is empty.
360343
"""
361344

362345
if self.context.enable_streaming:
363-
# This logic is temporary prior to deprecating the processor_ids parameter.
364-
# TODO(#6271) Remove after deprecating processor_ids elsewhere prior to v1.4.
365-
if processor_ids:
366-
if len(processor_ids) > 1:
367-
raise ValueError("The use of multiple processors is no longer supported.")
368-
if len(processor_ids) == 1 and not processor_id:
369-
processor_id = processor_ids[0]
370-
371346
if not program_id:
372347
program_id = _make_random_id('prog-')
373348
if not job_id:
@@ -403,10 +378,9 @@ async def run_sweep_async(
403378
job_id=job_id,
404379
params=params,
405380
repetitions=repetitions,
406-
processor_ids=processor_ids,
381+
processor_id=processor_id,
407382
description=job_description,
408383
labels=job_labels,
409-
processor_id=processor_id,
410384
run_name=run_name,
411385
device_config_name=device_config_name,
412386
)

cirq-google/cirq_google/engine/engine_client.py

+4-61
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
Dict,
2323
List,
2424
Optional,
25-
Sequence,
2625
Set,
2726
TypeVar,
2827
Tuple,
@@ -36,7 +35,6 @@
3635
from google.protobuf import any_pb2, field_mask_pb2
3736
from google.protobuf.timestamp_pb2 import Timestamp
3837

39-
from cirq._compat import deprecated_parameter
4038
from cirq_google.cloud import quantum
4139
from cirq_google.engine.asyncio_executor import AsyncioExecutor
4240
from cirq_google.engine import stream_manager
@@ -378,25 +376,17 @@ async def delete_program_async(
378376

379377
delete_program = duet.sync(delete_program_async)
380378

381-
@deprecated_parameter(
382-
deadline='v1.4',
383-
fix='Use `processor_id` instead of `processor_ids`.',
384-
parameter_desc='processor_ids',
385-
match=lambda args, kwargs: _match_deprecated_processor_ids(args, kwargs),
386-
rewrite=lambda args, kwargs: rewrite_processor_ids_to_processor_id(args, kwargs),
387-
)
388379
async def create_job_async(
389380
self,
390381
project_id: str,
391382
program_id: str,
392383
job_id: Optional[str],
393-
processor_ids: Optional[Sequence[str]] = None,
384+
processor_id: str,
394385
run_context: any_pb2.Any = any_pb2.Any(),
395386
priority: Optional[int] = None,
396387
description: Optional[str] = None,
397388
labels: Optional[Dict[str, str]] = None,
398389
*,
399-
processor_id: str = "",
400390
run_name: str = "",
401391
device_config_name: str = "",
402392
) -> Tuple[str, quantum.QuantumJob]:
@@ -411,16 +401,10 @@ async def create_job_async(
411401
program_id: Unique ID of the program within the parent project.
412402
job_id: Unique ID of the job within the parent program.
413403
run_context: Properly serialized run context.
414-
processor_ids: Deprecated list of candidate processor ids to run the program.
415-
Only allowed to contain one processor_id. If the argument `processor_id`
416-
is non-empty, `processor_ids` will be ignored. Otherwise the deprecated
417-
decorator will fix the arguments and call create_job_async using
418-
`processor_id` instead of `processor_ids`.
419404
priority: Optional priority to run at, 0-1000.
420405
description: Optional description to set on the job.
421406
labels: Optional set of labels to set on the job.
422-
processor_id: Processor id for running the program. If not set,
423-
`processor_ids` will be used.
407+
processor_id: Processor id for running the program.
424408
run_name: A unique identifier representing an automation run for the
425409
specified processor. An Automation Run contains a collection of
426410
device configurations for a processor. If specified, `processor_id`
@@ -434,9 +418,7 @@ async def create_job_async(
434418
435419
Raises:
436420
ValueError: If the priority is not between 0 and 1000.
437-
ValueError: If neither `processor_id` or `processor_ids` are set.
438421
ValueError: If only one of `run_name` and `device_config_name` are specified.
439-
ValueError: If `processor_ids` has more than one processor id.
440422
ValueError: If either `run_name` and `device_config_name` are set but
441423
`processor_id` is empty.
442424
"""
@@ -474,8 +456,7 @@ async def create_job_async(
474456
job = await self._send_request_async(self.grpc_client.create_quantum_job, request)
475457
return _ids_from_job_name(job.name)[2], job
476458

477-
# TODO(cxing): Remove type ignore once @deprecated_parameter decorator is removed
478-
create_job = duet.sync(create_job_async) # type: ignore
459+
create_job = duet.sync(create_job_async)
479460

480461
async def list_jobs_async(
481462
self,
@@ -775,8 +756,7 @@ def run_job_over_stream(
775756
priority: Optional priority to run at, 0-1000.
776757
job_description: Optional description to set on the job.
777758
job_labels: Optional set of labels to set on the job.
778-
processor_id: Processor id for running the program. If not set,
779-
`processor_ids` will be used.
759+
processor_id: Processor id for running the program.
780760
run_name: A unique identifier representing an automation run for the
781761
specified processor. An Automation Run contains a collection of
782762
device configurations for a processor. If specified, `processor_id`
@@ -1225,40 +1205,3 @@ def _date_or_time_to_filter_expr(param_name: str, param: Union[datetime.datetime
12251205
f"type {type(param)}. Supported types: datetime.datetime and"
12261206
f"datetime.date"
12271207
)
1228-
1229-
1230-
def rewrite_processor_ids_to_processor_id(args, kwargs):
1231-
"""Rewrites the create_job parameters so that `processor_id` is used instead of the deprecated
1232-
`processor_ids`.
1233-
1234-
Raises:
1235-
ValueError: If `processor_ids` has more than one processor id.
1236-
ValueError: If `run_name` or `device_config_name` are set but `processor_id` is not.
1237-
"""
1238-
1239-
# Use `processor_id` keyword argument instead of `processor_ids`
1240-
processor_ids = args[4] if len(args) > 4 else kwargs['processor_ids']
1241-
if len(processor_ids) > 1:
1242-
raise ValueError("The use of multiple processors is no longer supported.")
1243-
if 'processor_id' not in kwargs or not kwargs['processor_id']:
1244-
if ('run_name' in kwargs and kwargs['run_name']) or (
1245-
'device_config_name' in kwargs and kwargs['device_config_name']
1246-
):
1247-
raise ValueError(
1248-
'Cannot specify `run_name` or `device_config_name` if `processor_id` is empty.'
1249-
)
1250-
kwargs['processor_id'] = processor_ids[0]
1251-
1252-
# Erase `processor_ids` from args and kwargs
1253-
if len(args) > 4:
1254-
args_list = list(args)
1255-
args_list[4] = None
1256-
args = tuple(args_list)
1257-
else:
1258-
kwargs.pop('processor_ids')
1259-
1260-
return args, kwargs
1261-
1262-
1263-
def _match_deprecated_processor_ids(args, kwargs):
1264-
return ('processor_ids' in kwargs and kwargs['processor_ids']) or len(args) > 4

0 commit comments

Comments
 (0)