本文整理汇总了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)