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


Python QuantumCircuit.reset方法代碼示例

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


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

示例1: test_initialize_middle_circuit

# 需要導入模塊: from qiskit import QuantumCircuit [as 別名]
# 或者: from qiskit.QuantumCircuit import reset [as 別名]
 def test_initialize_middle_circuit(self):
     desired_vector = [0.5, 0.5, 0.5, 0.5]
     qr = QuantumRegister(2, "qr")
     cr = ClassicalRegister(2, "cr")
     qc = QuantumCircuit(qr, cr)
     qc.h(qr[0])
     qc.cx(qr[0], qr[1])
     qc.reset(qr[0])
     qc.reset(qr[1])
     qc.initialize(desired_vector, [qr[0], qr[1]])
     qc.measure(qr, cr)
     # statevector simulator does not support reset
     shots = 2000
     threshold = 0.04 * shots
     job = wrapper.execute(qc, 'local_qasm_simulator', shots=shots)
     result = job.result()
     counts = result.get_counts()
     target = {'00': shots / 4, '01': shots / 4, '10': shots / 4, '11': shots / 4}
     self.assertDictAlmostEqual(counts, target, threshold)
開發者ID:christians94,項目名稱:qiskit-sdk-py,代碼行數:21,代碼來源:test_initializer.py

示例2: CircuitBackend

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

#.........這裏部分代碼省略.........
            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):
        """Barrier instruction.

        qubitlists is a list of lists of (regname, idx) tuples.
        """
        if self.listen:
            if "barrier" not in self.basis:
                self.basis.append("barrier")
            flatlist = map(self._map_qubit,
                           [qubit for qubitlist in qubitlists
                            for qubit in qubitlist])
            self.circuit.barrier(*list(flatlist))

    def reset(self, qubit):
        """Reset instruction.

        qubit is a (regname, idx) tuple.
        """
        if "reset" not in self.basis:
            self.basis.append("reset")
        this_op = self.circuit.reset(self._map_qubit(qubit))
        if self.creg is not None:
            this_op.c_if(self._map_creg(self.creg), self.cval)

    def set_condition(self, creg, cval):
        """Attach a current condition.

        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.
開發者ID:christians94,項目名稱:qiskit-sdk-py,代碼行數:70,代碼來源:_circuitbackend.py


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