Example #1
0
    def simplify_circuit(circuit: 'cirq.Circuit') -> None:
        """Simplifies and optimizes the given circuit (in place).

        Args:
            circuit (cirq.Circuit): Circuit to simplify. Modified.

        Currently it

        * merges any neighboring gates belonging to the same one-parameter family
        * merges all one-qubit rotations into phased X rotations followed by Z rotations
        * pushes the Z rotations towards the end of the circuit as far as possible
        * drops any empty Moments
        """
        # the optimizers cause the immediate decomposition of any gates they insert into the Circuit
        for _ in range(7):
            # FIXME This sucks, but it seems that Cirq optimizers have no way of communicating
            # if they actually made any changes to the Circuit, so we run a fixed number of iterations.
            # Ideally we would keep doing this until the circuit hits a fixed point and no further changes are made.
            # all mergeable 2-qubit gates are merged
            MergeOneParameterGroupGates().optimize_circuit(circuit)
            optimizers.merge_single_qubit_gates_into_phased_x_z(circuit)
            # all z rotations are pushed past the first two-qubit gate following them
            IQMEjectZ(eject_parameterized=True).optimize_circuit(circuit)
            optimizers.DropEmptyMoments().optimize_circuit(circuit)

        DropRZBeforeMeasurement().optimize_circuit(circuit)
        optimizers.DropEmptyMoments().optimize_circuit(circuit)
        DecomposeGatesFinal().optimize_circuit(circuit)
Example #2
0
    def convert_circuit(self, circuit: circuits.Circuit) -> circuits.Circuit:
        new_circuit = circuits.Circuit()
        for moment in circuit:
            for op in moment.operations:
                new_circuit.append(self.convert_one(op))
        optimizers.merge_single_qubit_gates_into_phased_x_z(new_circuit)

        return new_circuit
def _get_sycamore_optimizers(
    tolerance: float, tabulation: Optional[GateTabulation]
) -> List[Callable[['cirq.Circuit'], None]]:
    return [
        ConvertToSycamoreGates(tabulation=tabulation).optimize_circuit,
        lambda c: optimizers.merge_single_qubit_gates_into_phased_x_z(
            c, tolerance),
        *_get_common_cleanup_optimizers(tolerance=tolerance),
    ]
def _get_sqrt_iswap_optimizers(
    tolerance: float, tabulation: Optional[GateTabulation]
) -> List[Callable[['cirq.Circuit'], None]]:
    if tabulation is not None:
        # coverage: ignore
        raise ValueError("Gate tabulation not supported for sqrt_iswap")
    return [
        ConvertToSqrtIswapGates().optimize_circuit,
        lambda c: optimizers.merge_single_qubit_gates_into_phased_x_z(
            c, tolerance),
        *_get_common_cleanup_optimizers(tolerance=tolerance),
    ]
def _get_xmon_optimizers_part_cz(
    tolerance: float, tabulation: Optional[GateTabulation]
) -> List[Callable[['cirq.Circuit'], None]]:
    if tabulation is not None:
        # coverage: ignore
        raise ValueError("Gate tabulation not supported for xmon")
    return [
        convert_to_xmon_gates.ConvertToXmonGates().optimize_circuit,
        optimizers.MergeInteractions(tolerance=tolerance,
                                     allow_partial_czs=True).optimize_circuit,
        lambda c: optimizers.merge_single_qubit_gates_into_phased_x_z(
            c, tolerance),
        *_get_common_cleanup_optimizers(tolerance=tolerance),
    ]
Example #6
0
def _merge_rots(c: 'cirq.Circuit'):
    return optimizers.merge_single_qubit_gates_into_phased_x_z(c, _TOLERANCE)