Exemplo n.º 1
0
 def _process_cnot(self, node):
     """Process a CNOT gate node."""
     id0 = self._process_bit_id(node.children[0])
     id1 = self._process_bit_id(node.children[1])
     if not(len(id0) == len(id1) or len(id0) == 1 or len(id1) == 1):
         raise QiskitError("internal error: qreg size mismatch",
                           "line=%s" % node.line, "file=%s" % node.file)
     maxidx = max([len(id0), len(id1)])
     for idx in range(maxidx):
         if len(id0) > 1 and len(id1) > 1:
             self.dag.apply_operation_back(CXBase(id0[idx], id1[idx]), self.condition)
         elif len(id0) > 1:
             self.dag.apply_operation_back(CXBase(id0[idx], id1[0]), self.condition)
         else:
             self.dag.apply_operation_back(CXBase(id0[0], id1[idx]), self.condition)
Exemplo n.º 2
0
 def cx(self, qubit0, qubit1):
     """Fundamental two-qubit gate.
     """
     if self.listen:
         if self.creg is not None:
             condition = (self.creg, self.cval)
         else:
             condition = None
         self.circuit.apply_operation_back(CXBase(qubit0, qubit1),
                                           condition)
Exemplo n.º 3
0
 def _define(self):
     """
     gate cx c,t { CX c,t; }
     """
     definition = []
     q = QuantumRegister(2, "q")
     rule = [(CXBase(), [q[0], q[1]], [])]
     for inst in rule:
         definition.append(inst)
     self.definition = definition
Exemplo n.º 4
0
 def _define_decompositions(self):
     """
     gate cx c,t { CX c,t; }
     """
     decomposition = DAGCircuit()
     q = QuantumRegister(2, "q")
     decomposition.add_qreg(q)
     rule = [CXBase(q[0], q[1])]
     for inst in rule:
         decomposition.apply_operation_back(inst)
     self._decompositions = [decomposition]