本文整理汇总了Python中qiskit.QuantumProgram.online_simulators方法的典型用法代码示例。如果您正苦于以下问题:Python QuantumProgram.online_simulators方法的具体用法?Python QuantumProgram.online_simulators怎么用?Python QuantumProgram.online_simulators使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qiskit.QuantumProgram
的用法示例。
在下文中一共展示了QuantumProgram.online_simulators方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_online_simulators
# 需要导入模块: from qiskit import QuantumProgram [as 别名]
# 或者: from qiskit.QuantumProgram import online_simulators [as 别名]
def test_online_simulators(self):
"""Test if there are online backends (which are simulators).
If all correct some should exists. NEED internet connection for this.
"""
# TODO: Jay should we check if we the QX is online before runing.
qp = QuantumProgram(specs=QPS_SPECS)
qp.set_api(API_TOKEN, URL)
online_simulators = qp.online_simulators()
# print(online_simulators)
self.assertTrue(isinstance(online_simulators, list))
示例2: test_execute_one_circuit_simulator_online
# 需要导入模块: from qiskit import QuantumProgram [as 别名]
# 或者: from qiskit.QuantumProgram import online_simulators [as 别名]
def test_execute_one_circuit_simulator_online(self):
QP_program = QuantumProgram(specs=QPS_SPECS)
qc = QP_program.get_circuit("circuitName")
qr = QP_program.get_quantum_register("qname")
cr = QP_program.get_classical_register("cname")
qc.h(qr[1])
qc.measure(qr[0], cr[0])
shots = 1024 # the number of shots in the experiment.
QP_program.set_api(API_TOKEN, URL)
backend = QP_program.online_simulators()[0]
# print(backend)
result = QP_program.execute(['circuitName'], backend=backend,
shots=shots, max_credits=3, silent=True)
self.assertIsInstance(result, Result)
示例3: test_execute_several_circuits_simulator_online
# 需要导入模块: from qiskit import QuantumProgram [as 别名]
# 或者: from qiskit.QuantumProgram import online_simulators [as 别名]
def test_execute_several_circuits_simulator_online(self):
QP_program = QuantumProgram(specs=QPS_SPECS)
qr = QP_program.get_quantum_register("qname")
cr = QP_program.get_classical_register("cname")
qc2 = QP_program.create_circuit("qc2", [qr], [cr])
qc3 = QP_program.create_circuit("qc3", [qr], [cr])
qc2.h(qr[0])
qc3.h(qr[0])
qc2.measure(qr[0], cr[0])
qc3.measure(qr[0], cr[0])
circuits = ['qc2', 'qc3']
shots = 1024 # the number of shots in the experiment.
QP_program.set_api(API_TOKEN, URL)
backend = QP_program.online_simulators()[0]
result = QP_program.execute(circuits, backend=backend, shots=shots,
max_credits=3, silent=True)
self.assertIsInstance(result, Result)
示例4: test_example_swap_bits
# 需要导入模块: from qiskit import QuantumProgram [as 别名]
# 或者: from qiskit.QuantumProgram import online_simulators [as 别名]
def test_example_swap_bits(self):
"""Test a toy example swapping a set bit around.
Uses the mapper. Pass if results are correct.
"""
backend = "ibmqx_qasm_simulator"
coupling_map = {0: [1, 8], 1: [2, 9], 2: [3, 10], 3: [4, 11], 4: [5, 12],
5: [6, 13], 6: [7, 14], 7: [15], 8: [9], 9: [10], 10: [11],
11: [12], 12: [13], 13: [14], 14: [15]}
def swap(qc, q0, q1):
"""Swap gate."""
qc.cx(q0, q1)
qc.cx(q1, q0)
qc.cx(q0, q1)
n = 3 # make this at least 3
QPS_SPECS = {
"circuits": [{
"name": "swapping",
"quantum_registers": [{
"name": "q",
"size": n},
{"name": "r",
"size": n}
],
"classical_registers": [
{"name": "ans",
"size": 2*n},
]
}]
}
qp = QuantumProgram(specs=QPS_SPECS)
qp.set_api(API_TOKEN, URL)
if backend not in qp.online_simulators():
return
qc = qp.get_circuit("swapping")
q = qp.get_quantum_register("q")
r = qp.get_quantum_register("r")
ans = qp.get_classical_register("ans")
# Set the first bit of q
qc.x(q[0])
# Swap the set bit
swap(qc, q[0], q[n-1])
swap(qc, q[n-1], r[n-1])
swap(qc, r[n-1], q[1])
swap(qc, q[1], r[1])
# Insert a barrier before measurement
qc.barrier()
# Measure all of the qubits in the standard basis
for j in range(n):
qc.measure(q[j], ans[j])
qc.measure(r[j], ans[j+n])
# First version: no mapping
result = qp.execute(["swapping"], backend=backend,
coupling_map=None, shots=1024,
seed=14)
self.assertEqual(result.get_counts("swapping"),
{'010000': 1024})
# Second version: map to coupling graph
result = qp.execute(["swapping"], backend=backend,
coupling_map=coupling_map, shots=1024,
seed=14)
self.assertEqual(result.get_counts("swapping"),
{'010000': 1024})