示例#1
0
 def _define_decompositions(self):
     decomposition = DAGCircuit()
     q = QuantumRegister(1, "q")
     decomposition.add_qreg(q)
     rule = [UBase(pi / 2, self.params[0], self.params[1], q[0])]
     for inst in rule:
         decomposition.apply_operation_back(inst)
     self._decompositions = [decomposition]
示例#2
0
 def _define(self):
     definition = []
     q = QuantumRegister(1, "q")
     rule = [(UBase(self.params[0], self.params[1],
                    self.params[2]), [q[0]], [])]
     for inst in rule:
         definition.append(inst)
     self.definition = definition
示例#3
0
 def _define_decompositions(self):
     decomposition = DAGCircuit()
     q = QuantumRegister(1, "q")
     decomposition.add_qreg(q)
     decomposition.add_basis_element("U", 1, 0, 3)
     rule = [UBase(0, 0, 0, q[0])]
     for inst in rule:
         decomposition.apply_operation_back(inst)
     self._decompositions = [decomposition]
示例#4
0
 def u(self, arg, qubit):
     """Universal single qubit rotation gate.
     """
     if not self.listen:
         return
     if self.creg is not None:
         condition = (self.creg, self.cval)
     else:
         condition = None
     self.circuit.apply_operation_back(UBase(*arg, qubit), condition)
示例#5
0
    def _process_node(self, node):
        """Carry out the action associated with a node."""
        if node.type == "program":
            self._process_children(node)

        elif node.type == "qreg":
            qreg = QuantumRegister(node.index, node.name)
            self.dag.add_qreg(qreg)

        elif node.type == "creg":
            creg = ClassicalRegister(node.index, node.name)
            self.dag.add_creg(creg)

        elif node.type == "id":
            raise QiskitError("internal error: _process_node on id")

        elif node.type == "int":
            raise QiskitError("internal error: _process_node on int")

        elif node.type == "real":
            raise QiskitError("internal error: _process_node on real")

        elif node.type == "indexed_id":
            raise QiskitError("internal error: _process_node on indexed_id")

        elif node.type == "id_list":
            # We process id_list nodes when they are leaves of barriers.
            return [
                self._process_bit_id(node_children)
                for node_children in node.children
            ]

        elif node.type == "primary_list":
            # We should only be called for a barrier.
            return [self._process_bit_id(m) for m in node.children]

        elif node.type == "gate":
            self._process_gate(node)

        elif node.type == "custom_unitary":
            self._process_custom_unitary(node)

        elif node.type == "universal_unitary":
            args = self._process_node(node.children[0])
            qid = self._process_bit_id(node.children[1])
            for element in qid:
                self.dag.apply_operation_back(UBase(*args, element),
                                              self.condition)

        elif node.type == "cnot":
            self._process_cnot(node)

        elif node.type == "expression_list":
            return node.children

        elif node.type == "binop":
            raise QiskitError("internal error: _process_node on binop")

        elif node.type == "prefix":
            raise QiskitError("internal error: _process_node on prefix")

        elif node.type == "measure":
            self._process_measure(node)

        elif node.type == "format":
            self.version = node.version()

        elif node.type == "barrier":
            ids = self._process_node(node.children[0])
            qubits = []
            for qubit in ids:
                for j, _ in enumerate(qubit):
                    qubits.append(qubit[j])
            self.dag.apply_operation_back(Barrier(len(qubits)), qubits, [])

        elif node.type == "reset":
            id0 = self._process_bit_id(node.children[0])
            for i, _ in enumerate(id0):
                self.dag.apply_operation_back(Reset(), [id0[i]], [],
                                              self.condition)

        elif node.type == "if":
            self._process_if(node)

        elif node.type == "opaque":
            self._process_gate(node, opaque=True)

        elif node.type == "external":
            raise QiskitError("internal error: _process_node on external")

        else:
            raise QiskitError("internal error: undefined node type", node.type,
                              "line=%s" % node.line, "file=%s" % node.file)
        return None