Exemplo n.º 1
0
    def optimization_at(self, circuit, index, op):
        if len(op.qubits) != 1:
            return

        indices, gates = self._scan_single_qubit_ops(circuit, index,
                                                     op.qubits[0])
        if not gates or (len(gates) == 1 and isinstance(gates[0], XmonGate)):
            return

        # Replace the gates with a max-2-op XY + Z construction.
        operations = self._merge_rotations(op.qubits[0], gates)

        return PointOptimizationSummary(clear_span=max(indices) + 1 - index,
                                        clear_qubits=op.qubits,
                                        new_operations=operations)
Exemplo n.º 2
0
    def optimization_at(self, circuit, index, op):
        if len(op.qubits) != 1:
            return

        indices, operations = self._scan_single_qubit_ops(
            circuit, index, op.qubits[0])
        if not operations or (len(operations) == 1 and
                              XmonGate.is_supported_op(operations[0])):
            return

        # Replace the gates with a max-2-op XY + Z construction.
        new_operations = self._merge_rotations(op.qubits[0], operations)

        converter = convert_to_xmon_gates.ConvertToXmonGates()
        new_xmon_operations = [converter.convert(new_op)
                               for new_op in new_operations]

        return PointOptimizationSummary(
            clear_span=max(indices) + 1 - index,
            clear_qubits=op.qubits,
            new_operations=new_xmon_operations)
Exemplo n.º 3
0
    def optimization_at(self, circuit: Circuit, index: int,
                        op: Operation) -> Optional[PointOptimizationSummary]:

        if isinstance(op.gate, (MeasurementGate, SingleQubitGate, WaitGate)):
            new_op = op
        else:
            if op.gate is None:
                raise IncompatibleMomentError(
                    f'Operation {op} has a missing gate')
            translated_gate = self._simulator.gates_translator(op.gate)
            if translated_gate is None:
                raise IncompatibleMomentError(
                    f'Moment contains non-single qubit operation '
                    f'{op} with unsupported gate')
            a, b = op.qubits
            new_op = self._simulator.create_gate_with_drift(
                a, b, translated_gate).on(a, b)

        return PointOptimizationSummary(clear_span=1,
                                        clear_qubits=op.qubits,
                                        new_operations=new_op)
Exemplo n.º 4
0
    def optimization_at(self, circuit, index, op):
        if len(op.qubits) != 2:
            return None

        interaction_count, indices, matrix = (
            self._scan_two_qubit_ops_into_matrix(circuit, index, op.qubits))
        if interaction_count <= 1:
            return None

        # Find a max-3-cz construction.
        operations = two_qubit_matrix_to_native_gates(
            op.qubits[0],
            op.qubits[1],
            matrix,
            self.allow_partial_czs,
            self.tolerance)

        # TODO: don't replace if there's no benefit in CZ depth.

        return PointOptimizationSummary(
            clear_span=max(indices) + 1 - index,
            clear_qubits=op.qubits,
            new_operations=operations)