1# Copyright 2018 The Cirq Developers 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14"""A combination of several optimizations targeting XmonDevice.""" 15from typing import Callable, cast, Optional, TYPE_CHECKING 16 17import cirq 18from cirq_google.optimizers import optimized_for_sycamore 19 20if TYPE_CHECKING: 21 import cirq_google 22 23 24def optimized_for_xmon( 25 circuit: cirq.Circuit, 26 new_device: Optional['cirq_google.XmonDevice'] = None, 27 qubit_map: Callable[[cirq.Qid], cirq.GridQubit] = lambda e: cast(cirq.GridQubit, e), 28 allow_partial_czs: bool = False, 29) -> cirq.Circuit: 30 if allow_partial_czs: 31 return optimized_for_sycamore( 32 circuit, new_device=new_device, qubit_map=qubit_map, optimizer_type='xmon_partial_cz' 33 ) 34 else: 35 return optimized_for_sycamore( 36 circuit, new_device=new_device, qubit_map=qubit_map, optimizer_type='xmon' 37 ) 38