本文整理匯總了Python中qiskit.QuantumCircuit.u_base方法的典型用法代碼示例。如果您正苦於以下問題:Python QuantumCircuit.u_base方法的具體用法?Python QuantumCircuit.u_base怎麽用?Python QuantumCircuit.u_base使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類qiskit.QuantumCircuit
的用法示例。
在下文中一共展示了QuantumCircuit.u_base方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestStandard1Q
# 需要導入模塊: from qiskit import QuantumCircuit [as 別名]
# 或者: from qiskit.QuantumCircuit import u_base [as 別名]
#.........這裏部分代碼省略.........
self.assertResult(U3Gate, 'u3(1,2,3) q[1];', 'u3(-1,-3,-2) q[1];')
def test_u3_invalid(self):
c = self.circuit
# CHECKME? self.assertRaises(QISKitError, c.u3, 0, self.c[0], self.q[0])
self.assertRaises(QISKitError, c.u3, 0, 0, self.c[0], self.c[1])
self.assertRaises(QISKitError, c.u3, 0, 0, self.q[1], 0)
self.assertRaises(QISKitError, c.u3, 0, 0, 0, self.c[0])
self.assertRaises(QISKitError, c.u3, 0, 0, 0, 0)
# TODO self.assertRaises(QISKitError, c.u3, 0, 0, self.q[2], self.q[1])
self.assertRaises(QISKitError, c.u3, 0, 0, 0, (self.q, 3))
self.assertRaises(QISKitError, c.u3, 0, 0, 0, self.c)
# TODO self.assertRaises(QISKitError, c.u3, 0, 0, 'a', self.q[1])
self.assertRaises(QISKitError, c.u3, 0, 0, 0, 'a')
def test_u3_reg(self):
qasm_txt = 'u3(1,2,3) q[0];\nu3(1,2,3) q[1];\nu3(1,2,3) q[2];'
instruction_set = self.circuit.u3(1, 2, 3, self.q)
self.assertStmtsType(instruction_set.instructions, U3Gate)
self.assertQasm(qasm_txt)
def test_u3_reg_inv(self):
qasm_txt = 'u3(-1,-3,-2) q[0];\nu3(-1,-3,-2) q[1];\nu3(-1,-3,-2) q[2];'
instruction_set = self.circuit.u3(1, 2, 3, self.q).inverse()
self.assertStmtsType(instruction_set.instructions, U3Gate)
self.assertQasm(qasm_txt)
def test_u3_pi(self):
c = self.circuit
c.u3(pi, pi / 2, 0.3 * pi, self.q[1])
self.assertResult(U3Gate, 'u3(pi,pi/2,0.3*pi) q[1];', 'u3(-pi,-0.3*pi,-pi/2) q[1];')
def test_ubase(self):
self.circuit.u_base(1, 2, 3, self.q[1])
self.assertResult(UBase, 'U(1,2,3) q[1];', 'U(-1,-3,-2) q[1];')
def test_ubase_invalid(self):
c = self.circuit
# CHECKME? self.assertRaises(QISKitError, c.u_base, 0, self.c[0], self.q[0])
self.assertRaises(QISKitError, c.u_base, 0, 0, self.c[0], self.c[1])
self.assertRaises(QISKitError, c.u_base, 0, 0, self.q[1], 0)
self.assertRaises(QISKitError, c.u_base, 0, 0, 0, self.c[0])
self.assertRaises(QISKitError, c.u_base, 0, 0, 0, 0)
# TODO self.assertRaises(QISKitError, c.u_base, 0, 0, self.q[2], self.q[1])
self.assertRaises(QISKitError, c.u_base, 0, 0, 0, (self.q, 3))
self.assertRaises(QISKitError, c.u_base, 0, 0, 0, self.c)
# TODO self.assertRaises(QISKitError, c.u_base, 0, 0, 'a', self.q[1])
self.assertRaises(QISKitError, c.u_base, 0, 0, 0, 'a')
def test_ubase_reg(self):
qasm_txt = 'U(1,2,3) q[0];\nU(1,2,3) q[1];\nU(1,2,3) q[2];'
instruction_set = self.circuit.u_base(1, 2, 3, self.q)
self.assertStmtsType(instruction_set.instructions, UBase)
self.assertQasm(qasm_txt)
def test_ubase_reg_inv(self):
qasm_txt = 'U(-1,-3,-2) q[0];\nU(-1,-3,-2) q[1];\nU(-1,-3,-2) q[2];'
instruction_set = self.circuit.u_base(1, 2, 3, self.q).inverse()
self.assertStmtsType(instruction_set.instructions, UBase)
self.assertQasm(qasm_txt)
def test_ubase_pi(self):
c = self.circuit
c.u_base(pi, pi / 2, 0.3 * pi, self.q[1])
self.assertResult(UBase, 'U(pi,pi/2,0.3*pi) q[1];', 'U(-pi,-0.3*pi,-pi/2) q[1];')
示例2: CircuitBackend
# 需要導入模塊: from qiskit import QuantumCircuit [as 別名]
# 或者: from qiskit.QuantumCircuit import u_base [as 別名]
#.........這裏部分代碼省略.........
"""Map qubit tuple (regname, index) to (QuantumRegister, index)."""
qregs = self.circuit.get_qregs()
if qubit[0] not in qregs:
raise BackendError("qreg %s does not exist" % qubit[0])
return (qregs[qubit[0]], qubit[1])
def _map_bit(self, bit):
"""Map bit tuple (regname, index) to (ClassicalRegister, index)."""
cregs = self.circuit.get_cregs()
if bit[0] not in cregs:
raise BackendError("creg %s does not exist" % bit[0])
return (cregs[bit[0]], bit[1])
def _map_creg(self, creg):
"""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):