本文整理汇总了Python中qiskit.QuantumCircuit.cu3方法的典型用法代码示例。如果您正苦于以下问题:Python QuantumCircuit.cu3方法的具体用法?Python QuantumCircuit.cu3怎么用?Python QuantumCircuit.cu3使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qiskit.QuantumCircuit
的用法示例。
在下文中一共展示了QuantumCircuit.cu3方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestStandard1Q
# 需要导入模块: from qiskit import QuantumCircuit [as 别名]
# 或者: from qiskit.QuantumCircuit import cu3 [as 别名]
#.........这里部分代码省略.........
qasm_txt = 'cx q[2],q[1];\nccx q[0],q[1],q[2];\ncx q[2],q[1];'
self.assertResult(FredkinGate, qasm_txt, qasm_txt)
def test_cswap_invalid(self):
c = self.circuit
self.assertRaises(QISKitError, c.cswap, self.c[0], self.c[1], self.c[2])
self.assertRaises(QISKitError, c.cswap, self.q[1], self.q[0], self.q[0])
self.assertRaises(QISKitError, c.cswap, self.q[1], 0, self.q[0])
self.assertRaises(QISKitError, c.cswap, self.c[0], self.c[1], self.q[0])
self.assertRaises(QISKitError, c.cswap, self.q[0], self.q[0], self.q[1])
self.assertRaises(QISKitError, c.cswap, 0, self.q[0], self.q[1])
self.assertRaises(QISKitError, c.cswap, (self.q, 3), self.q[0], self.q[1])
self.assertRaises(QISKitError, c.cswap, self.c, self.q[0], self.q[1])
self.assertRaises(QISKitError, c.cswap, 'a', self.q[1], self.q[2])
def test_cu1(self):
self.circuit.cu1(1, self.q[1], self.q[2])
self.assertResult(Cu1Gate, 'cu1(1) q[1],q[2];', 'cu1(-1) q[1],q[2];')
def test_cu1_invalid(self):
c = self.circuit
self.assertRaises(QISKitError, c.cu1, self.c[0], self.c[1], self.c[2])
self.assertRaises(QISKitError, c.cu1, 1, self.q[0], self.q[0])
self.assertRaises(QISKitError, c.cu1, self.q[1], 0, self.q[0])
self.assertRaises(QISKitError, c.cu1, 0, self.c[0], self.c[1])
self.assertRaises(QISKitError, c.cu1, 0, self.q[0], self.q[0])
self.assertRaises(QISKitError, c.cu1, 0, 0, self.q[0])
# TODO self.assertRaises(QISKitError, c.cu1, self.q[2], self.q[1], self.q[0])
self.assertRaises(QISKitError, c.cu1, 0, self.q[1], self.c[2])
self.assertRaises(QISKitError, c.cu1, 0, (self.q, 3), self.q[1])
self.assertRaises(QISKitError, c.cu1, 0, self.c, self.q)
# 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)
示例2: TestStandard2Q
# 需要导入模块: from qiskit import QuantumCircuit [as 别名]
# 或者: from qiskit.QuantumCircuit import cu3 [as 别名]
#.........这里部分代码省略.........
self.assertStmtsType(instruction_set.instructions, Cu1Gate)
self.assertQasm(qasm_txt)
def test_cu1_reg_reg_inv(self):
qasm_txt = 'cu1(-1) q[0],r[0];\ncu1(-1) q[1],r[1];\ncu1(-1) q[2],r[2];'
instruction_set = self.circuit.cu1(1, self.q, self.r).inverse()
self.assertStmtsType(instruction_set.instructions, Cu1Gate)
self.assertQasm(qasm_txt)
def test_cu1_reg_bit(self):
qasm_txt = 'cu1(1) q[0],r[1];\ncu1(1) q[1],r[1];\ncu1(1) q[2],r[1];'
instruction_set = self.circuit.cu1(1, self.q, self.r[1])
self.assertStmtsType(instruction_set.instructions, Cu1Gate)
self.assertQasm(qasm_txt)
def test_cu1_reg_bit_inv(self):
qasm_txt = 'cu1(-1) q[0],r[1];\ncu1(-1) q[1],r[1];\ncu1(-1) q[2],r[1];'
instruction_set = self.circuit.cu1(1, self.q, self.r[1]).inverse()
self.assertStmtsType(instruction_set.instructions, Cu1Gate)
self.assertQasm(qasm_txt)
def test_cu1_bit_reg(self):
qasm_txt = 'cu1(1) q[1],r[0];\ncu1(1) q[1],r[1];\ncu1(1) q[1],r[2];'
instruction_set = self.circuit.cu1(1, self.q[1], self.r)
self.assertStmtsType(instruction_set.instructions, Cu1Gate)
self.assertQasm(qasm_txt)
def test_cu1_bit_reg_inv(self):
qasm_txt = 'cu1(-1) q[1],r[0];\ncu1(-1) q[1],r[1];\ncu1(-1) q[1],r[2];'
instruction_set = self.circuit.cu1(1, self.q[1], self.r).inverse()
self.assertStmtsType(instruction_set.instructions, Cu1Gate)
self.assertQasm(qasm_txt)
def test_cu3_reg_reg(self):
qasm_txt = 'cu3(1,2,3) q[0],r[0];\ncu3(1,2,3) q[1],r[1];\ncu3(1,2,3) q[2],r[2];'
instruction_set = self.circuit.cu3(1, 2, 3, self.q, self.r)
self.assertStmtsType(instruction_set.instructions, Cu3Gate)
self.assertQasm(qasm_txt)
def test_cu3_reg_reg_inv(self):
qasm_txt = 'cu3(-1,-3,-2) q[0],r[0];\ncu3(-1,-3,-2) q[1],r[1];\ncu3(-1,-3,-2) q[2],r[2];'
instruction_set = self.circuit.cu3(1, 2, 3, self.q, self.r).inverse()
self.assertStmtsType(instruction_set.instructions, Cu3Gate)
self.assertQasm(qasm_txt)
def test_cu3_reg_bit(self):
qasm_txt = 'cu3(1,2,3) q[0],r[1];\ncu3(1,2,3) q[1],r[1];\ncu3(1,2,3) q[2],r[1];'
instruction_set = self.circuit.cu3(1, 2, 3, self.q, self.r[1])
self.assertStmtsType(instruction_set.instructions, Cu3Gate)
self.assertQasm(qasm_txt)
def test_cu3_reg_bit_inv(self):
qasm_txt = 'cu3(-1,-3,-2) q[0],r[1];\ncu3(-1,-3,-2) q[1],r[1];\ncu3(-1,-3,-2) q[2],r[1];'
instruction_set = self.circuit.cu3(1, 2, 3, self.q, self.r[1]).inverse()
self.assertStmtsType(instruction_set.instructions, Cu3Gate)
self.assertQasm(qasm_txt)
def test_cu3_bit_reg(self):
qasm_txt = 'cu3(1,2,3) q[1],r[0];\ncu3(1,2,3) q[1],r[1];\ncu3(1,2,3) q[1],r[2];'
instruction_set = self.circuit.cu3(1, 2, 3, self.q[1], self.r)
self.assertStmtsType(instruction_set.instructions, Cu3Gate)
self.assertQasm(qasm_txt)
def test_cu3_bit_reg_inv(self):
qasm_txt = 'cu3(-1,-3,-2) q[1],r[0];\ncu3(-1,-3,-2) q[1],r[1];\ncu3(-1,-3,-2) q[1],r[2];'
instruction_set = self.circuit.cu3(1, 2, 3, self.q[1], self.r).inverse()
示例3: CircuitBackend
# 需要导入模块: from qiskit import QuantumCircuit [as 别名]
# 或者: from qiskit.QuantumCircuit import cu3 [as 别名]
#.........这里部分代码省略.........
creg is a name string.
cval is the integer value for the test.
"""
self.creg = creg
self.cval = cval
def drop_condition(self):
"""Drop the current condition."""
self.creg = None
self.cval = None
def start_gate(self, name, args, qubits, nested_scope=None):
"""Begin a custom gate.
name is name string.
args is list of Node expression objects.
qubits is list of (regname, idx) tuples.
nested_scope is a list of dictionaries mapping expression variables
to Node expression objects in order of increasing nesting depth.
"""
if self.listen and name not in self.basis \
and self.gates[name]["opaque"]:
raise BackendError("opaque gate %s not in basis" % name)
if self.listen and name in self.basis:
self.in_gate = name
self.listen = False
# Gate names mapped to number of arguments and qubits
# and method to invoke on [args, qubits]
lut = {"ccx": [(0, 3),
lambda x: self.circuit.ccx(x[1][0], x[1][1],
x[1][2])],
"ch": [(0, 2),
lambda x: self.circuit.ch(x[1][0], x[1][1])],
"crz": [(1, 2),
lambda x: self.circuit.crz(x[0][0], x[1][0],
x[1][1])],
"cswap": [(0, 3),
lambda x: self.circuit.cswap(x[1][0],
x[1][1],
x[1][2])],
"cu1": [(1, 2),
lambda x: self.circuit.cu1(x[0][0], x[1][0],
x[1][1])],
"cu3": [(3, 2), lambda x: self.circuit.cu3(x[0][0],
x[0][1],
x[0][2],
x[1][0],
x[1][1])],
"cx": [(0, 2), lambda x: self.circuit.cx(x[1][0], x[1][1])],
"cy": [(0, 2), lambda x: self.circuit.cy(x[1][0], x[1][1])],
"cz": [(0, 2), lambda x: self.circuit.cz(x[1][0], x[1][1])],
"swap": [(0, 2), lambda x: self.circuit.swap(x[1][0], x[1][1])],
"h": [(0, 1), lambda x: self.circuit.h(x[1][0])],
"id": [(0, 1), lambda x: self.circuit.iden(x[1][0])],
"rx": [(1, 1), lambda x: self.circuit.rx(x[0][0], x[1][0])],
"ry": [(1, 1), lambda x: self.circuit.ry(x[0][0], x[1][0])],
"rz": [(1, 1), lambda x: self.circuit.rz(x[0][0], x[1][0])],
"s": [(0, 1), lambda x: self.circuit.s(x[1][0])],
"sdg": [(0, 1), lambda x: self.circuit.s(x[1][0]).inverse()],
"t": [(0, 1), lambda x: self.circuit.t(x[1][0]).inverse()],
"tdg": [(0, 1), lambda x: self.circuit.t(x[1][0]).inverse()],
"u1": [(1, 1), lambda x: self.circuit.u1(x[0][0], x[1][0])],
"u2": [(2, 1), lambda x: self.circuit.u2(x[0][0], x[0][1],
x[1][0])],
"u3": [(3, 1), lambda x: self.circuit.u3(x[0][0], x[0][1],
x[0][2], x[1][0])],
"x": [(0, 1), lambda x: self.circuit.x(x[1][0])],
"y": [(0, 1), lambda x: self.circuit.y(x[1][0])],
"z": [(0, 1), lambda x: self.circuit.z(x[1][0])]}
if name not in lut:
raise BackendError("gate %s not in standard extensions" %
name)
gate_data = lut[name]
if gate_data[0] != (len(args), len(qubits)):
raise BackendError("gate %s signature (%d, %d) is " %
(name, len(args), len(qubits)) +
"incompatible with the standard " +
"extensions")
this_gate = gate_data[1]([list(map(lambda x:
x.sym(nested_scope), args)),
list(map(self._map_qubit, qubits))])
if self.creg is not None:
this_gate.c_if(self._map_creg(self.creg), self.cval)
def end_gate(self, name, args, qubits, nested_scope=None):
"""End a custom gate.
name is name string.
args is list of Node expression objects.
qubits is list of (regname, idx) tuples.
nested_scope is a list of dictionaries mapping expression variables
to Node expression objects in order of increasing nesting depth.
"""
if name == self.in_gate:
self.in_gate = ""
self.listen = True
def get_output(self):
"""Return the QuantumCircuit object."""
return self.circuit