当前位置: 首页>>代码示例>>Python>>正文


Python qiskit.QuantumCircuit方法代码示例

本文整理汇总了Python中qiskit.QuantumCircuit方法的典型用法代码示例。如果您正苦于以下问题:Python qiskit.QuantumCircuit方法的具体用法?Python qiskit.QuantumCircuit怎么用?Python qiskit.QuantumCircuit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在qiskit的用法示例。


在下文中一共展示了qiskit.QuantumCircuit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: h_gate_circuits_deterministic

# 需要导入模块: import qiskit [as 别名]
# 或者: from qiskit import QuantumCircuit [as 别名]
def h_gate_circuits_deterministic(final_measure=True):
    """H-gate test circuits with deterministic counts."""
    circuits = []
    qr = QuantumRegister(1)
    if final_measure:
        cr = ClassicalRegister(1)
        regs = (qr, cr)
    else:
        regs = (qr, )
    # HH=I
    circuit = QuantumCircuit(*regs)
    circuit.h(qr)
    circuit.barrier(qr)
    circuit.h(qr)
    if final_measure:
        circuit.barrier(qr)
        circuit.measure(qr, cr)
    circuits.append(circuit)
    return circuits 
开发者ID:Qiskit,项目名称:qiskit-aer,代码行数:21,代码来源:ref_1q_clifford.py

示例2: qft_circuit

# 需要导入模块: import qiskit [as 别名]
# 或者: from qiskit import QuantumCircuit [as 别名]
def qft_circuit(num_qubits, measure=True):
    """Create a qft circuit.

    Args:
        num_qubits (int): number of qubits
        measure (bool): include measurement in circuit.

    Returns:
        QftCircuit: A qft circuit.
    """
    # Create quantum/classical registers of size n
    qr = QuantumRegister(num_qubits)
    circuit = QuantumCircuit(qr)

    for i in range(num_qubits):
        for j in range(i):
            circuit.cu1(math.pi/float(2**(i-j)), qr[i], qr[j])
        circuit.h(qr[i])

    if measure is True:
        circuit = _add_measurements(circuit, qr)
    return circuit 
开发者ID:Qiskit,项目名称:qiskit-aer,代码行数:24,代码来源:tools.py

示例3: simple_cnot_circuit

# 需要导入模块: import qiskit [as 别名]
# 或者: from qiskit import QuantumCircuit [as 别名]
def simple_cnot_circuit(num_qubits, measure=True):
    """Creates a simple circuit composed by cnot gates, with measurements or
    not at the end of each qubit.

    Args:
        num_qubits (int): Number of qubits
        measure (bool): Add measurements at the end of each qubit

    Returns:
        QuantumCircuit: The simple quantum circuit
    """
    qr = QuantumRegister(num_qubits)
    circuit = QuantumCircuit(qr)
    for i in range(num_qubits):
        # for the last qubit, we exchange control and target qubits
        target_qubit = i + 1 if num_qubits - 1 > i else i - 1
        circuit.cx(qr[i], qr[target_qubit])

    if measure:
        circuit = _add_measurements(circuit, qr)
    return circuit


# pylint: disable=invalid-name 
开发者ID:Qiskit,项目名称:qiskit-aer,代码行数:26,代码来源:tools.py

示例4: quantum_fourier_transform_circuit

# 需要导入模块: import qiskit [as 别名]
# 或者: from qiskit import QuantumCircuit [as 别名]
def quantum_fourier_transform_circuit(num_qubits):
    """Create quantum fourier transform circuit.

    Args:
        num_qubits (int): Number of qubits

    Returns:
        QuantumCircuit: QFT circuit
    """
    qreg = QuantumRegister(num_qubits)
    creg = ClassicalRegister(num_qubits)

    circuit = QuantumCircuit(qreg, creg, name="qft")

    n = len(qreg)

    for i in range(n):
        for j in range(i):
            circuit.cu1(math.pi/float(2**(i-j)), qreg[i], qreg[j])
        circuit.h(qreg[i])
    circuit.measure(qreg, creg)
    return circuit 
开发者ID:Qiskit,项目名称:qiskit-aer,代码行数:24,代码来源:tools.py

示例5: test_no_noise

# 需要导入模块: import qiskit [as 别名]
# 或者: from qiskit import QuantumCircuit [as 别名]
def test_no_noise(self):
        qr = QuantumRegister(3, 'qr')
        circuit = QuantumCircuit(qr)
        circuit.x(qr[0])
        circuit.y(qr[1])
        circuit.z(qr[2])

        target_circuit = QuantumCircuit(qr)
        target_circuit.x(qr[0])
        target_circuit.y(qr[1])
        target_circuit.z(qr[2])

        noise_model = NoiseModel() #empty

        result_circuit = insert_noise(circuit, noise_model)

        self.assertEqual(target_circuit, result_circuit) 
开发者ID:Qiskit,项目名称:qiskit-aer,代码行数:19,代码来源:test_noise_inserter.py

示例6: test_all_qubit_quantum_errors

# 需要导入模块: import qiskit [as 别名]
# 或者: from qiskit import QuantumCircuit [as 别名]
def test_all_qubit_quantum_errors(self):
        qr = QuantumRegister(3, 'qr')
        circuit = QuantumCircuit(qr)
        circuit.x(qr[0])
        circuit.y(qr[1])
        circuit.z(qr[2])

        error_x = pauli_error([('Y', 0.25), ('I', 0.75)])
        error_y = pauli_error([('X', 0.35), ('Z', 0.65)])
        noise_model = NoiseModel()
        noise_model.add_all_qubit_quantum_error(error_x, 'x')
        noise_model.add_all_qubit_quantum_error(error_y, 'y')

        target_circuit = QuantumCircuit(qr)
        target_circuit.x(qr[0])
        target_circuit.append(error_x.to_instruction(), [qr[0]])
        target_circuit.y(qr[1])
        target_circuit.append(error_y.to_instruction(), [qr[1]])
        target_circuit.z(qr[2])

        result_circuit = insert_noise(circuit, noise_model)

        self.assertEqual(target_circuit, result_circuit) 
开发者ID:Qiskit,项目名称:qiskit-aer,代码行数:25,代码来源:test_noise_inserter.py

示例7: test_local_quantum_errors

# 需要导入模块: import qiskit [as 别名]
# 或者: from qiskit import QuantumCircuit [as 别名]
def test_local_quantum_errors(self):
        qr = QuantumRegister(3, 'qr')
        circuit = QuantumCircuit(qr)
        circuit.x(qr[0])
        circuit.x(qr[1])
        circuit.y(qr[2])

        error_x = pauli_error([('Y', 0.25), ('I', 0.75)])
        error_y = pauli_error([('X', 0.35), ('Z', 0.65)])
        noise_model = NoiseModel()
        noise_model.add_quantum_error(error_x, 'x', [0])
        noise_model.add_quantum_error(error_y, 'y', [2])

        target_circuit = QuantumCircuit(qr)
        target_circuit.x(qr[0])
        target_circuit.append(error_x.to_instruction(), [qr[0]])
        target_circuit.x(qr[1])
        target_circuit.y(qr[2])
        target_circuit.append(error_y.to_instruction(), [qr[2]])

        result_circuit = insert_noise(circuit, noise_model)

        self.assertEqual(target_circuit, result_circuit) 
开发者ID:Qiskit,项目名称:qiskit-aer,代码行数:25,代码来源:test_noise_inserter.py

示例8: test_transpiling

# 需要导入模块: import qiskit [as 别名]
# 或者: from qiskit import QuantumCircuit [as 别名]
def test_transpiling(self):
        qr = QuantumRegister(3, 'qr')
        circuit = QuantumCircuit(qr)
        circuit.x(qr[0])
        circuit.y(qr[1])
        circuit.z(qr[2])

        error_x = pauli_error([('Y', 0.25), ('I', 0.75)])
        error_y = pauli_error([('X', 0.35), ('Z', 0.65)])
        noise_model = NoiseModel()
        noise_model.add_all_qubit_quantum_error(error_x, 'x')
        noise_model.add_all_qubit_quantum_error(error_y, 'u1')

        target_circuit = QuantumCircuit(qr)
        target_circuit.x(qr[0])
        target_circuit.append(error_x.to_instruction(), [qr[0]])
        target_circuit.u3(pi, pi / 2, pi / 2, qr[1])
        target_circuit.u1(pi, qr[2])
        target_circuit.append(error_y.to_instruction(), [qr[2]])

        result_circuit = insert_noise(circuit, noise_model, transpile=True)
        self.assertEqual(target_circuit, result_circuit) 
开发者ID:Qiskit,项目名称:qiskit-aer,代码行数:24,代码来源:test_noise_inserter.py

示例9: create_circuit_for_truncate

# 需要导入模块: import qiskit [as 别名]
# 或者: from qiskit import QuantumCircuit [as 别名]
def create_circuit_for_truncate(self):
        qr = QuantumRegister(4)
        cr = ClassicalRegister(4)
        circuit = QuantumCircuit(qr, cr)
        circuit.u3(0.1,0.1,0.1,qr[1])
        circuit.barrier(qr)
        circuit.x(qr[2])
        circuit.barrier(qr)
        circuit.x(qr[1])
        circuit.barrier(qr)
        circuit.x(qr[3])
        circuit.barrier(qr)
        circuit.u3(0.1,0.1,0.1,qr[0])
        circuit.barrier(qr)
        circuit.measure(qr[0], cr[0])
        circuit.measure(qr[1], cr[1])
        return circuit 
开发者ID:Qiskit,项目名称:qiskit-aer,代码行数:19,代码来源:qasm_truncate.py

示例10: h_gate_circuits_nondeterministic

# 需要导入模块: import qiskit [as 别名]
# 或者: from qiskit import QuantumCircuit [as 别名]
def h_gate_circuits_nondeterministic(final_measure=True):
    """X-gate test circuits with non-deterministic counts."""
    circuits = []
    qr = QuantumRegister(1)
    if final_measure:
        cr = ClassicalRegister(1)
        regs = (qr, cr)
    else:
        regs = (qr, )
    # H
    circuit = QuantumCircuit(*regs)
    circuit.h(qr)
    if final_measure:
        circuit.barrier(qr)
        circuit.measure(qr, cr)
    circuits.append(circuit)
    return circuits 
开发者ID:Qiskit,项目名称:qiskit-aer,代码行数:19,代码来源:ref_1q_clifford.py

示例11: unitary_random_gate_circuits_nondeterministic

# 需要导入模块: import qiskit [as 别名]
# 或者: from qiskit import QuantumCircuit [as 别名]
def unitary_random_gate_circuits_nondeterministic(final_measure=True):
    """Unitary gate test circuits with random unitary gate and nondeterministic count output."""
    # random_unitary seed = nq
    circuits = []
    for n in range(1, 5):
        qr = QuantumRegister(n, 'qr')
        if final_measure:
            cr = ClassicalRegister(n, 'cr')
            regs = (qr, cr)
        else:
            regs = (qr, )

        circuit = QuantumCircuit(*regs)
        circuit.unitary(random_unitary(2 ** n, seed=n), list(range(n)))
        if final_measure:
            circuit.barrier(qr)
            circuit.measure(qr, cr)
        circuits.append(circuit)

    return circuits 
开发者ID:Qiskit,项目名称:qiskit-aer,代码行数:22,代码来源:ref_unitary_gate.py

示例12: _gate_rules_to_qiskit_circuit

# 需要导入模块: import qiskit [as 别名]
# 或者: from qiskit import QuantumCircuit [as 别名]
def _gate_rules_to_qiskit_circuit(self, node, params):
        """From a gate definition in qasm, to a QuantumCircuit format."""
        rules = []
        qreg = QuantumRegister(node['n_bits'])
        bit_args = {node['bits'][i]: q for i, q in enumerate(qreg)}
        exp_args = {node['args'][i]: Real(q) for i, q in enumerate(params)}

        for child_op in node['body'].children:
            qparams = []
            eparams = []
            for param_list in child_op.children[1:]:
                if param_list.type == 'id_list':
                    qparams = [bit_args[param.name] for param in param_list.children]
                elif param_list.type == 'expression_list':
                    for param in param_list.children:
                        eparams.append(param.sym(nested_scope=[exp_args]))
            op = self._create_op(child_op.name, params=eparams)
            rules.append((op, qparams, []))
        circ = QuantumCircuit(qreg)
        circ.data = rules
        return circ 
开发者ID:Qiskit,项目名称:qiskit-terra,代码行数:23,代码来源:ast_to_dag.py

示例13: definition

# 需要导入模块: import qiskit [as 别名]
# 或者: from qiskit import QuantumCircuit [as 别名]
def definition(self) -> List:
        """Return definition in terms of other basic gates. If the gate has
        open controls, as determined from `self.ctrl_state`, the returned
        definition is conjugated with X without changing the internal
        `_definition`.
        """
        if self._open_ctrl:
            closed_gate = self.copy()
            closed_gate.ctrl_state = None
            bit_ctrl_state = bin(self.ctrl_state)[2:].zfill(self.num_ctrl_qubits)
            qreg = QuantumRegister(self.num_qubits, 'q')
            qc_open_ctrl = QuantumCircuit(qreg)
            for qind, val in enumerate(bit_ctrl_state[::-1]):
                if val == '0':
                    qc_open_ctrl.x(qind)
            qc_open_ctrl.append(closed_gate, qargs=qreg[:])
            for qind, val in enumerate(bit_ctrl_state[::-1]):
                if val == '0':
                    qc_open_ctrl.x(qind)
            return qc_open_ctrl
        else:
            return super().definition 
开发者ID:Qiskit,项目名称:qiskit-terra,代码行数:24,代码来源:controlledgate.py

示例14: _build_additional_layers

# 需要导入模块: import qiskit [as 别名]
# 或者: from qiskit import QuantumCircuit [as 别名]
def _build_additional_layers(self, which):
        if which == 'appended':
            blocks = self._appended_blocks
            entanglements = self._appended_entanglement
        elif which == 'prepended':
            blocks = reversed(self._prepended_blocks)
            entanglements = reversed(self._prepended_entanglement)
        else:
            raise ValueError('`which` must be either `appended` or `prepended`.')

        for i, (block, ent) in enumerate(zip(blocks, entanglements)):
            layer = QuantumCircuit(*self.qregs)
            if isinstance(ent, str):
                ent = get_entangler_map(block.num_block_qubits, self.num_qubits, ent)
            for indices in ent:
                layer.compose(block, indices, inplace=True)

            self += layer 
开发者ID:Qiskit,项目名称:qiskit-terra,代码行数:20,代码来源:n_local.py

示例15: to_circuit

# 需要导入模块: import qiskit [as 别名]
# 或者: from qiskit import QuantumCircuit [as 别名]
def to_circuit(self):
        """Return a QuantumCircuit implementing the Clifford.

        For N <= 3 qubits this is based on optimal CX cost decomposition
        from reference [1]. For N > 3 qubits this is done using the general
        non-optimal compilation routine from reference [2].

        Return:
            QuantumCircuit: a circuit implementation of the Clifford.

        References:
            1. S. Bravyi, D. Maslov, *Hadamard-free circuits expose the
               structure of the Clifford group*,
               `arXiv:2003.09412 [quant-ph] <https://arxiv.org/abs/2003.09412>`_

            2. S. Aaronson, D. Gottesman, *Improved Simulation of Stabilizer Circuits*,
               Phys. Rev. A 70, 052328 (2004).
               `arXiv:quant-ph/0406196 <https://arxiv.org/abs/quant-ph/0406196>`_
        """
        return decompose_clifford(self) 
开发者ID:Qiskit,项目名称:qiskit-terra,代码行数:22,代码来源:clifford.py


注:本文中的qiskit.QuantumCircuit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。