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


Python QuantumCircuit.u3方法代碼示例

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


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

示例1: qc_approx_sim

# 需要導入模塊: from qiskit import QuantumCircuit [as 別名]
# 或者: from qiskit.QuantumCircuit import u3 [as 別名]
def qc_approx_sim(x, t1, t2):
    theta1 = x - t1;
    theta2 = x - t2;

    q = QuantumRegister(2, 'q')
    c = ClassicalRegister(2, 'c')
    qc = QuantumCircuit(q, c)

    qc.h( q[0] )
    qc.h( q[1] )

    qc.u3(t1, 0.0, 0.0, q[0]);
    qc.u3(t2, 0.0, 0.0, q[1]);

    qc.barrier( q )
    #qc.measure(q,c)
    qc.measure( q[0], c[0] )
    qc.measure( q[1], c[1] )

    job = execute(qc, backend, shots=1024)

    rslt = job.result()
    #counts = rslt.get_counts(qc)
    #print(counts)

    outputstate = rslt.get_statevector( qc, decimals=13 )
    #print(outputstate)

    qval = outputstate;

    return qval;
開發者ID:qMSUZ,項目名稱:QCS,代碼行數:33,代碼來源:qapprox.py

示例2: TestStandard1Q

# 需要導入模塊: from qiskit import QuantumCircuit [as 別名]
# 或者: from qiskit.QuantumCircuit import u3 [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)
開發者ID:christians94,項目名稱:qiskit-sdk-py,代碼行數:70,代碼來源:test_extensions_standard.py

示例3: CircuitBackend

# 需要導入模塊: from qiskit import QuantumCircuit [as 別名]
# 或者: from qiskit.QuantumCircuit import u3 [as 別名]
class CircuitBackend(UnrollerBackend):
    """Backend for the unroller that produces a QuantumCircuit.

    By default, basis gates are the QX gates.
    """

    def __init__(self, basis=None):
        """Setup this backend.

        basis is a list of operation name strings.
        """
        super().__init__(basis)
        self.creg = None
        self.cval = None
        if basis:
            self.basis = basis
        else:
            self.basis = ["cx", "u1", "u2", "u3"]
        self.gates = {}
        self.listen = True
        self.in_gate = ""
        self.circuit = QuantumCircuit()

    def set_basis(self, basis):
        """Declare the set of user-defined gates to emit.

        basis is a list of operation name strings.
        """
        self.basis = basis

    def version(self, version):
        """Ignore the version string.

        v is a version number.
        """
        pass

    def new_qreg(self, name, size):
        """Create a new quantum register.

        name = name of the register
        sz = size of the register
        """
        assert size >= 0, "invalid qreg size"
        q_register = QuantumRegister(size, name)
        self.circuit.add(q_register)

    def new_creg(self, name, size):
        """Create a new classical register.

        name = name of the register
        sz = size of the register
        """
        assert size >= 0, "invalid creg size"
        c_register = ClassicalRegister(size, name)
        self.circuit.add(c_register)

    def define_gate(self, name, gatedata):
        """Define a new quantum gate.

        We don't check that the definition and name agree.

        name is a string.
        gatedata is the AST node for the gate.
        """
        self.gates[name] = gatedata

    def _map_qubit(self, qubit):
        """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")

#.........這裏部分代碼省略.........
開發者ID:christians94,項目名稱:qiskit-sdk-py,代碼行數:103,代碼來源:_circuitbackend.py


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