當前位置: 首頁>>代碼示例>>Python>>正文


Python QuantumCircuit.cx_base方法代碼示例

本文整理匯總了Python中qiskit.QuantumCircuit.cx_base方法的典型用法代碼示例。如果您正苦於以下問題:Python QuantumCircuit.cx_base方法的具體用法?Python QuantumCircuit.cx_base怎麽用?Python QuantumCircuit.cx_base使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在qiskit.QuantumCircuit的用法示例。


在下文中一共展示了QuantumCircuit.cx_base方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestStandard1Q

# 需要導入模塊: from qiskit import QuantumCircuit [as 別名]
# 或者: from qiskit.QuantumCircuit import cx_base [as 別名]

#.........這裏部分代碼省略.........
        # TODO self.assertRaises(QISKitError, c.cu1, 'a', self.q[1], self.q[2])

    def test_cu3(self):
        self.circuit.cu3(1, 2, 3, self.q[1], self.q[2])
        self.assertResult(Cu3Gate, 'cu3(1,2,3) q[1],q[2];', 'cu3(-1,-3,-2) q[1],q[2];')

    def test_cu3_invalid(self):
        c = self.circuit
        self.assertRaises(QISKitError, c.cu3, 0, 0, self.q[0], self.q[1], self.c[2])
        self.assertRaises(QISKitError, c.cu3, 0, 0, 0, self.q[0], self.q[0])
        self.assertRaises(QISKitError, c.cu3, 0, 0, self.q[1], 0, self.q[0])
        self.assertRaises(QISKitError, c.cu3, 0, 0, 0, self.q[0], self.q[0])
        self.assertRaises(QISKitError, c.cu3, 0, 0, 0, 0, self.q[0])
        self.assertRaises(QISKitError, c.cu3, 0, 0, 0, (self.q, 3), self.q[1])
        self.assertRaises(QISKitError, c.cu3, 0, 0, 0, self.c, self.q)
        # TODO self.assertRaises(QISKitError, c.cu3, 0, 0, 'a', self.q[1], self.q[2])

    def test_cx(self):
        self.circuit.cx(self.q[1], self.q[2])
        qasm_txt = 'cx q[1],q[2];'
        self.assertResult(CnotGate, qasm_txt, qasm_txt)

    def test_cx_invalid(self):
        c = self.circuit
        self.assertRaises(QISKitError, c.cx, self.c[1], self.c[2])
        self.assertRaises(QISKitError, c.cx, self.q[0], self.q[0])
        self.assertRaises(QISKitError, c.cx, 0, self.q[0])
        self.assertRaises(QISKitError, c.cx, (self.q, 3), self.q[0])
        self.assertRaises(QISKitError, c.cx, self.c, self.q)
        self.assertRaises(QISKitError, c.cx, 'a', self.q[1])

    def test_cxbase(self):
        qasm_txt = 'CX q[1],q[2];'
        self.circuit.cx_base(self.q[1], self.q[2])
        self.assertResult(CXBase, qasm_txt, qasm_txt)

    def test_cxbase_invalid(self):
        c = self.circuit
        self.assertRaises(QISKitError, c.cx_base, self.c[1], self.c[2])
        self.assertRaises(QISKitError, c.cx_base, self.q[0], self.q[0])
        self.assertRaises(QISKitError, c.cx_base, 0, self.q[0])
        self.assertRaises(QISKitError, c.cx_base, (self.q, 3), self.q[0])
        self.assertRaises(QISKitError, c.cx_base, self.c, self.q)
        self.assertRaises(QISKitError, c.cx_base, 'a', self.q[1])

    def test_cy(self):
        qasm_txt = 'cy q[1],q[2];'
        self.circuit.cy(self.q[1], self.q[2])
        self.assertResult(CyGate, qasm_txt, qasm_txt)

    def test_cy_invalid(self):
        c = self.circuit
        self.assertRaises(QISKitError, c.cy, self.c[1], self.c[2])
        self.assertRaises(QISKitError, c.cy, self.q[0], self.q[0])
        self.assertRaises(QISKitError, c.cy, 0, self.q[0])
        self.assertRaises(QISKitError, c.cy, (self.q, 3), self.q[0])
        self.assertRaises(QISKitError, c.cy, self.c, self.q)
        self.assertRaises(QISKitError, c.cy, 'a', self.q[1])

    def test_cz(self):
        qasm_txt = 'cz q[1],q[2];'
        self.circuit.cz(self.q[1], self.q[2])
        self.assertResult(CzGate, qasm_txt, qasm_txt)

    def test_cz_invalid(self):
        c = self.circuit
開發者ID:christians94,項目名稱:qiskit-sdk-py,代碼行數:70,代碼來源:test_extensions_standard.py

示例2: TestStandard2Q

# 需要導入模塊: from qiskit import QuantumCircuit [as 別名]
# 或者: from qiskit.QuantumCircuit import cx_base [as 別名]

#.........這裏部分代碼省略.........

    def test_cx_reg_reg_inv(self):
        qasm_txt = 'cx q[0],r[0];\ncx q[1],r[1];\ncx q[2],r[2];'
        instruction_set = self.circuit.cx(self.q, self.r).inverse()
        self.assertStmtsType(instruction_set.instructions, CnotGate)
        self.assertQasm(qasm_txt)

    def test_cx_reg_bit(self):
        qasm_txt = 'cx q[0],r[1];\ncx q[1],r[1];\ncx q[2],r[1];'
        instruction_set = self.circuit.cx(self.q, self.r[1])
        self.assertStmtsType(instruction_set.instructions, CnotGate)
        self.assertQasm(qasm_txt)

    def test_cx_reg_bit_inv(self):
        qasm_txt = 'cx q[0],r[1];\ncx q[1],r[1];\ncx q[2],r[1];'
        instruction_set = self.circuit.cx(self.q, self.r[1]).inverse()
        self.assertStmtsType(instruction_set.instructions, CnotGate)
        self.assertQasm(qasm_txt)

    def test_cx_bit_reg(self):
        qasm_txt = 'cx q[1],r[0];\ncx q[1],r[1];\ncx q[1],r[2];'
        instruction_set = self.circuit.cx(self.q[1], self.r)
        self.assertStmtsType(instruction_set.instructions, CnotGate)
        self.assertQasm(qasm_txt)

    def test_cx_bit_reg_inv(self):
        qasm_txt = 'cx q[1],r[0];\ncx q[1],r[1];\ncx q[1],r[2];'
        instruction_set = self.circuit.cx(self.q[1], self.r).inverse()
        self.assertStmtsType(instruction_set.instructions, CnotGate)
        self.assertQasm(qasm_txt)

    def test_cxbase_reg_reg(self):
        qasm_txt = 'CX q[0],r[0];\nCX q[1],r[1];\nCX q[2],r[2];'
        instruction_set = self.circuit.cx_base(self.q, self.r)
        self.assertStmtsType(instruction_set.instructions, CXBase)
        self.assertQasm(qasm_txt)

    def test_cxbase_reg_reg_inv(self):
        qasm_txt = 'CX q[0],r[0];\nCX q[1],r[1];\nCX q[2],r[2];'
        instruction_set = self.circuit.cx_base(self.q, self.r).inverse()
        self.assertStmtsType(instruction_set.instructions, CXBase)
        self.assertQasm(qasm_txt)

    def test_cxbase_reg_bit(self):
        qasm_txt = 'CX q[0],r[1];\nCX q[1],r[1];\nCX q[2],r[1];'
        instruction_set = self.circuit.cx_base(self.q, self.r[1])
        self.assertStmtsType(instruction_set.instructions, CXBase)
        self.assertQasm(qasm_txt)

    def test_cxbase_reg_bit_inv(self):
        qasm_txt = 'CX q[0],r[1];\nCX q[1],r[1];\nCX q[2],r[1];'
        instruction_set = self.circuit.cx_base(self.q, self.r[1]).inverse()
        self.assertStmtsType(instruction_set.instructions, CXBase)
        self.assertQasm(qasm_txt)

    def test_cxbase_bit_reg(self):
        qasm_txt = 'CX q[1],r[0];\nCX q[1],r[1];\nCX q[1],r[2];'
        instruction_set = self.circuit.cx_base(self.q[1], self.r)
        self.assertStmtsType(instruction_set.instructions, CXBase)
        self.assertQasm(qasm_txt)

    def test_cxbase_bit_reg_inv(self):
        qasm_txt = 'CX q[1],r[0];\nCX q[1],r[1];\nCX q[1],r[2];'
        instruction_set = self.circuit.cx_base(self.q[1], self.r).inverse()
        self.assertStmtsType(instruction_set.instructions, CXBase)
        self.assertQasm(qasm_txt)
開發者ID:christians94,項目名稱:qiskit-sdk-py,代碼行數:70,代碼來源:test_extensions_standard.py

示例3: CircuitBackend

# 需要導入模塊: from qiskit import QuantumCircuit [as 別名]
# 或者: from qiskit.QuantumCircuit import cx_base [as 別名]

#.........這裏部分代碼省略.........
        """Map creg name to ClassicalRegister."""
        cregs = self.circuit.get_cregs()
        if creg not in cregs:
            raise BackendError("creg %s does not exist" % creg)
        return cregs[creg]

    def u(self, arg, qubit, nested_scope=None):
        """Fundamental single qubit gate.

        arg is 3-tuple of Node expression objects.
        qubit is (regname,idx) tuple.
        nested_scope is a list of dictionaries mapping expression variables
        to Node expression objects in order of increasing nesting depth.
        """
        if self.listen:
            if "U" not in self.basis:
                self.basis.append("U")

            (theta, phi, lam) = list(map(lambda x: x.sym(nested_scope), arg))
            this_gate = self.circuit.u_base(theta, phi, lam,
                                            self._map_qubit(qubit))
            if self.creg is not None:
                this_gate.c_if(self._map_creg(self.creg), self.cval)

    def cx(self, qubit0, qubit1):
        """Fundamental two qubit gate.

        qubit0 is (regname,idx) tuple for the control qubit.
        qubit1 is (regname,idx) tuple for the target qubit.
        """
        if self.listen:
            if "CX" not in self.basis:
                self.basis.append("CX")
            this_gate = self.circuit.cx_base(self._map_qubit(qubit0),
                                             self._map_qubit(qubit1))
            if self.creg is not None:
                this_gate.c_if(self._map_creg(self.creg), self.cval)

    def measure(self, qubit, bit):
        """Measurement operation.

        qubit is (regname, idx) tuple for the input qubit.
        bit is (regname, idx) tuple for the output bit.
        """
        if "measure" not in self.basis:
            self.basis.append("measure")
        this_op = self.circuit.measure(self._map_qubit(qubit),
                                       self._map_bit(bit))
        if self.creg is not None:
            this_op.c_if(self._map_creg(self.creg), self.cval)

    def barrier(self, qubitlists):
        """Barrier instruction.

        qubitlists is a list of lists of (regname, idx) tuples.
        """
        if self.listen:
            if "barrier" not in self.basis:
                self.basis.append("barrier")
            flatlist = map(self._map_qubit,
                           [qubit for qubitlist in qubitlists
                            for qubit in qubitlist])
            self.circuit.barrier(*list(flatlist))

    def reset(self, qubit):
        """Reset instruction.
開發者ID:christians94,項目名稱:qiskit-sdk-py,代碼行數:70,代碼來源:_circuitbackend.py


注:本文中的qiskit.QuantumCircuit.cx_base方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。