コード例 #1
0
 def __init__(self, template_list=None,
              heuristics_qubits_param=None,
              heuristics_backward_param=None):
     """
     Args:
         template_list (list[QuantumCircuit()]): list of the different template circuit to apply.
         heuristics_backward_param (list[int]): [length, survivor] Those are the parameters for
             applying heuristics on the backward part of the algorithm. This part of the
             algorithm creates a tree of matching scenario. This tree grows exponentially. The
             heuristics evaluates which scenarios have the longest match and keep only those.
             The length is the interval in the tree for cutting it and surviror is the number
             of scenarios that are kept. We advice to use l=3 and s=1 to have serious time
             advantage. We remind that the heuristics implies losing a part of the maximal
             matches. Check reference for more details.
         heuristics_qubits_param (list[int]): [length] The heuristics for the qubit choice make
             guesses from the dag dependency of the circuit in order to limit the number of
             qubit configurations to explore. The length is the number of successors or not
             predecessors that will be explored in the dag dependency of the circuit, each
             qubits of the nodes are added to the set of authorized qubits. We advice to use
             length=1. Check reference for more details.
     """
     super().__init__()
     # If no template is given; the template are set as x-x, cx-cx, ccx-ccx.
     if template_list is None:
         template_list = [template_nct_2a_1(), template_nct_2a_2(), template_nct_2a_3()]
     self.template_list = template_list
     self.heuristics_qubits_param = heuristics_qubits_param \
         if heuristics_qubits_param is not None else []
     self.heuristics_backward_param = heuristics_backward_param \
         if heuristics_backward_param is not None else []
コード例 #2
0
    def test_pass_cx_cancellation_template_from_library(self):
        """
        Check the cancellation of CX gates for the apply of the library template cx-cx (2a_2).
        """
        qr = QuantumRegister(2, 'qr')
        circuit_in = QuantumCircuit(qr)
        circuit_in.h(qr[0])
        circuit_in.h(qr[0])
        circuit_in.cx(qr[0], qr[1])
        circuit_in.cx(qr[0], qr[1])
        circuit_in.cx(qr[0], qr[1])
        circuit_in.cx(qr[0], qr[1])
        circuit_in.cx(qr[1], qr[0])
        circuit_in.cx(qr[1], qr[0])
        dag_in = circuit_to_dag(circuit_in)

        template_list = [template_nct_2a_2()]
        pass_ = TemplateOptimization(template_list)
        dag_opt = pass_.run(dag_in)

        circuit_expected = QuantumCircuit(qr)
        circuit_expected.h(qr[0])
        circuit_expected.h(qr[0])
        dag_expected = circuit_to_dag(circuit_expected)

        self.assertEqual(dag_opt, dag_expected)