def get_ion_gateset() -> ops.Gateset: return ops.Gateset( ops.XXPowGate, ops.MeasurementGate, ops.XPowGate, ops.YPowGate, ops.ZPowGate, ops.PhasedXPowGate, unroll_circuit_op=False, )
def neutral_atom_gateset(max_parallel_z=None, max_parallel_xy=None): return ops.Gateset( ops.AnyIntegerPowerGateFamily(ops.CNotPowGate), ops.AnyIntegerPowerGateFamily(ops.CCNotPowGate), ops.AnyIntegerPowerGateFamily(ops.CZPowGate), ops.AnyIntegerPowerGateFamily(ops.CCZPowGate), ops.ParallelGateFamily(ops.ZPowGate, max_parallel_allowed=max_parallel_z), ops.ParallelGateFamily(ops.XPowGate, max_parallel_allowed=max_parallel_xy), ops.ParallelGateFamily(ops.YPowGate, max_parallel_allowed=max_parallel_xy), ops.ParallelGateFamily(ops.PhasedXPowGate, max_parallel_allowed=max_parallel_xy), ops.MeasurementGate, ops.IdentityGate, unroll_circuit_op=False, )
def __init__( self, tolerance: float = 1e-8, *, required_sqrt_iswap_count: Optional[int] = None, use_sqrt_iswap_inv: bool = False, post_clean_up: Callable[[Sequence[ops.Operation]], ops.OP_TREE] = lambda op_list: op_list, ) -> None: """Inits MergeInteractionsToSqrtIswap. Args: tolerance: A limit on the amount of absolute error introduced by the construction. required_sqrt_iswap_count: When specified, each merged group of two-qubit gates will be decomposed into exactly this many sqrt-iSWAP gates even if fewer is possible (maximum 3). Circuit optimization will raise a ``ValueError`` if this number is 2 or lower and synthesis of any set of merged interactions requires more. use_sqrt_iswap_inv: If True, optimizes circuits using ``SQRT_ISWAP_INV`` gates instead of ``SQRT_ISWAP``. post_clean_up: This function is called on each set of optimized operations before they are put into the circuit to replace the old operations. Raises: ValueError: If ``required_sqrt_iswap_count`` is not one of the supported values 0, 1, 2, or 3. """ if required_sqrt_iswap_count is not None and not 0 <= required_sqrt_iswap_count <= 3: raise ValueError( 'the argument `required_sqrt_iswap_count` must be 0, 1, 2, or 3.' ) super().__init__(tolerance=tolerance, post_clean_up=post_clean_up) self.required_sqrt_iswap_count = required_sqrt_iswap_count self.use_sqrt_iswap_inv = use_sqrt_iswap_inv self.gateset = ops.Gateset( ops.SQRT_ISWAP_INV if use_sqrt_iswap_inv else ops.SQRT_ISWAP, unroll_circuit_op=False, accept_global_phase_op=True, )
def __init__(self, ignore_failures: bool = False, allow_partial_czs: bool = False) -> None: """Inits ConvertToCzAndSingleGates. Args: ignore_failures: If set, gates that fail to convert are forwarded unchanged. If not set, conversion failures raise a TypeError. allow_partial_czs: If set, the decomposition is permitted to use gates of the form `cirq.CZ**t`, instead of only `cirq.CZ`. """ super().__init__() self.ignore_failures = ignore_failures self.allow_partial_czs = allow_partial_czs self.gateset = ops.Gateset( ops.CZPowGate if allow_partial_czs else ops.CZ, ops.MeasurementGate, ops.AnyUnitaryGateFamily(1), )
def __init__( self, tolerance: float = 1e-8, allow_partial_czs: bool = True, post_clean_up: Callable[[Sequence[ops.Operation]], ops.OP_TREE] = lambda op_list: op_list, ) -> None: """Inits MergeInteractions. Args: tolerance: A limit on the amount of absolute error introduced by the construction. allow_partial_czs: Enables the use of Partial-CZ gates. post_clean_up: This function is called on each set of optimized operations before they are put into the circuit to replace the old operations. """ super().__init__(tolerance=tolerance, post_clean_up=post_clean_up) self.allow_partial_czs = allow_partial_czs self.gateset = ops.Gateset( ops.CZPowGate if allow_partial_czs else ops.CZ, unroll_circuit_op=False, accept_global_phase_op=True, )
def __init__( self, measurement_duration: 'cirq.DURATION_LIKE', gate_duration: 'cirq.DURATION_LIKE', control_radius: float, max_parallel_z: int, max_parallel_xy: int, max_parallel_c: int, qubits: Iterable[GridQubit], ) -> None: """Initializes the description of the AQuA device. Args: measurement_duration: the maximum duration of a measurement. gate_duration: the maximum duration of a gate control_radius: the maximum distance between qubits for a controlled gate. Distance is measured in units of the indices passed into the GridQubit constructor. max_parallel_z: The maximum number of qubits that can be acted on in parallel by a Z gate max_parallel_xy: The maximum number of qubits that can be acted on in parallel by a local XY gate max_parallel_c: the maximum number of qubits that can be acted on in parallel by a controlled gate. Must be less than or equal to the lesser of max_parallel_z and max_parallel_xy qubits: Qubits on the device, identified by their x, y location. Must be of type GridQubit Raises: ValueError: if the wrong qubit type is provided or if invalid parallel parameters are provided """ self._measurement_duration = Duration(measurement_duration) self._gate_duration = Duration(gate_duration) self._control_radius = control_radius self._max_parallel_z = max_parallel_z self._max_parallel_xy = max_parallel_xy if max_parallel_c > min(max_parallel_z, max_parallel_xy): raise ValueError("max_parallel_c must be less than or equal to the" "min of max_parallel_z and max_parallel_xy") self._max_parallel_c = max_parallel_c self.xy_gateset_all_allowed = ops.Gateset( ops.ParallelGateFamily(ops.XPowGate), ops.ParallelGateFamily(ops.YPowGate), ops.ParallelGateFamily(ops.PhasedXPowGate), unroll_circuit_op=False, ) self.controlled_gateset = ops.Gateset( ops.AnyIntegerPowerGateFamily(ops.CNotPowGate), ops.AnyIntegerPowerGateFamily(ops.CCNotPowGate), ops.AnyIntegerPowerGateFamily(ops.CZPowGate), ops.AnyIntegerPowerGateFamily(ops.CCZPowGate), unroll_circuit_op=False, ) self.gateset = NeutralAtomGateset(max_parallel_z, max_parallel_xy) for q in qubits: if not isinstance(q, GridQubit): raise ValueError(f'Unsupported qubit type: {q!r}') self.qubits = frozenset(qubits) self._metadata = devices.GridDeviceMetadata( [(a, b) for a in self.qubits for b in self.qubits if a.is_adjacent(b)], self.gateset)
if TYPE_CHECKING: import cirq TDefault = TypeVar('TDefault') TError = TypeVar('TError', bound=Exception) RaiseTypeErrorIfNotProvided: Any = ([], ) DecomposeResult = Union[None, NotImplementedType, 'cirq.OP_TREE'] OpDecomposer = Callable[['cirq.Operation'], DecomposeResult] DECOMPOSE_TARGET_GATESET = ops.Gateset( ops.XPowGate, ops.YPowGate, ops.ZPowGate, ops.CZPowGate, ops.MeasurementGate, ops.GlobalPhaseGate, ) def _value_error_describing_bad_operation(op: 'cirq.Operation') -> ValueError: return ValueError( f"Operation doesn't satisfy the given `keep` but can't be decomposed: {op!r}" ) class SupportsDecompose(Protocol): """An object that can be decomposed into simpler operations. All decomposition methods should ultimately terminate on basic 1-qubit and