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


Python QuantumCircuit.sdg方法代碼示例

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


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

示例1: TestStandard1Q

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

#.........這裏部分代碼省略.........
        self.assertResult(RZGate, 'rz(1) q[1];', 'rz(-1) q[1];')

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

    def test_rz_reg(self):
        qasm_txt = 'rz(1) q[0];\nrz(1) q[1];\nrz(1) q[2];'
        instruction_set = self.circuit.rz(1, self.q)
        self.assertStmtsType(instruction_set.instructions, RZGate)
        self.assertQasm(qasm_txt)

    def test_rz_reg_inv(self):
        qasm_txt = 'rz(-1) q[0];\nrz(-1) q[1];\nrz(-1) q[2];'
        instruction_set = self.circuit.rz(1, self.q).inverse()
        self.assertStmtsType(instruction_set.instructions, RZGate)
        self.assertQasm(qasm_txt, offset=len(qasm_txt) - 37)

    def test_rz_pi(self):
        c = self.circuit
        c.rz(pi / 2, self.q[1])
        self.assertResult(RZGate, 'rz(pi/2) q[1];', 'rz(-pi/2) q[1];')

    def test_s(self):
        self.circuit.s(self.q[1])
        self.assertResult(SGate, 's q[1];', 'sdg q[1];')

    def test_s_invalid(self):
        c = self.circuit
        self.assertRaises(QISKitError, c.s, self.c[0])
        self.assertRaises(QISKitError, c.s, self.c)
        self.assertRaises(QISKitError, c.s, (self.q, 3))
        self.assertRaises(QISKitError, c.s, (self.q, 'a'))
        self.assertRaises(QISKitError, c.s, 0)

    def test_s_reg(self):
        qasm_txt = 's q[0];\ns q[1];\ns q[2];'
        instruction_set = self.circuit.s(self.q)
        self.assertStmtsType(instruction_set.instructions, SGate)
        self.assertQasm(qasm_txt)

    def test_s_reg_inv(self):
        qasm_txt = 'sdg q[0];\nsdg q[1];\nsdg q[2];'
        instruction_set = self.circuit.s(self.q).inverse()
        self.assertStmtsType(instruction_set.instructions, SGate)
        self.assertQasm(qasm_txt, offset=len(qasm_txt) - 28)

    def test_sdg(self):
        self.circuit.sdg(self.q[1])
        self.assertResult(SGate, 'sdg q[1];', 's q[1];')

    def test_sdg_invalid(self):
        c = self.circuit
        self.assertRaises(QISKitError, c.sdg, self.c[0])
        self.assertRaises(QISKitError, c.sdg, self.c)
        self.assertRaises(QISKitError, c.sdg, (self.q, 3))
        self.assertRaises(QISKitError, c.sdg, (self.q, 'a'))
        self.assertRaises(QISKitError, c.sdg, 0)
開發者ID:christians94,項目名稱:qiskit-sdk-py,代碼行數:70,代碼來源:test_extensions_standard.py


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