本文整理汇总了Python中qiskit.QuantumProgram.get_compiled_qasm方法的典型用法代码示例。如果您正苦于以下问题:Python QuantumProgram.get_compiled_qasm方法的具体用法?Python QuantumProgram.get_compiled_qasm怎么用?Python QuantumProgram.get_compiled_qasm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qiskit.QuantumProgram
的用法示例。
在下文中一共展示了QuantumProgram.get_compiled_qasm方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_compiled_qasm
# 需要导入模块: from qiskit import QuantumProgram [as 别名]
# 或者: from qiskit.QuantumProgram import get_compiled_qasm [as 别名]
def test_get_compiled_qasm(self):
"""Test get_compiled_qasm.
If all correct should return lenght dictionary.
"""
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[0])
qc.cx(qr[0], qr[1])
qc.measure(qr[0], cr[0])
qc.measure(qr[1], cr[1])
backend = 'local_qasm_simulator'
coupling_map = None
qobj = QP_program.compile(['circuitName'], backend=backend,
coupling_map=coupling_map)
result = QP_program.get_compiled_qasm(qobj, 'circuitName',)
# print(result)
self.assertEqual(len(result), 184)
示例2: MapperTest
# 需要导入模块: from qiskit import QuantumProgram [as 别名]
# 或者: from qiskit.QuantumProgram import get_compiled_qasm [as 别名]
class MapperTest(QiskitTestCase):
"""Test the mapper."""
def setUp(self):
self.seed = 42
self.qp = QuantumProgram()
def test_mapper_overoptimization(self):
"""
The mapper should not change the semantics of the input. An overoptimization introduced
the issue #81: https://github.com/QISKit/qiskit-sdk-py/issues/81
"""
self.qp.load_qasm_file(self._get_resource_path('qasm/overoptimization.qasm'), name='test')
coupling_map = [[0, 2], [1, 2], [2, 3]]
result1 = self.qp.execute(["test"], backend="local_qasm_simulator",
coupling_map=coupling_map)
count1 = result1.get_counts("test")
result2 = self.qp.execute(["test"], backend="local_qasm_simulator", coupling_map=None)
count2 = result2.get_counts("test")
self.assertEqual(count1.keys(), count2.keys(), )
def test_math_domain_error(self):
"""
The math library operates over floats and introduce floating point errors that should be
avoided.
See: https://github.com/QISKit/qiskit-sdk-py/issues/111
"""
self.qp.load_qasm_file(self._get_resource_path('qasm/math_domain_error.qasm'), name='test')
coupling_map = [[0, 2], [1, 2], [2, 3]]
shots = 2000
result = self.qp.execute("test", backend="local_qasm_simulator",
coupling_map=coupling_map,
seed=self.seed, shots=shots)
counts = result.get_counts("test")
target = {'0001': shots / 2, '0101': shots / 2}
threshold = 0.04 * shots
self.assertDictAlmostEqual(counts, target, threshold)
def test_optimize_1q_gates_issue159(self):
"""Test change in behavior for optimize_1q_gates that removes u1(2*pi) rotations.
See: https://github.com/QISKit/qiskit-sdk-py/issues/159
"""
self.qp = QuantumProgram()
qr = self.qp.create_quantum_register('qr', 2)
cr = self.qp.create_classical_register('cr', 2)
qc = self.qp.create_circuit('Bell', [qr], [cr])
qc.h(qr[0])
qc.cx(qr[1], qr[0])
qc.cx(qr[1], qr[0])
qc.cx(qr[1], qr[0])
qc.measure(qr[0], cr[0])
qc.measure(qr[1], cr[1])
backend = 'local_qasm_simulator'
coupling_map = [[1, 0], [2, 0], [2, 1], [2, 4], [3, 2], [3, 4]]
initial_layout = {('qr', 0): ('q', 1), ('qr', 1): ('q', 0)}
qobj = self.qp.compile(["Bell"], backend=backend,
initial_layout=initial_layout, coupling_map=coupling_map)
self.assertEqual(self.qp.get_compiled_qasm(qobj, "Bell"), EXPECTED_QASM_1Q_GATES_3_5)
def test_random_parameter_circuit(self):
"""Run a circuit with randomly generated parameters."""
self.qp.load_qasm_file(self._get_resource_path('qasm/random_n5_d5.qasm'), name='rand')
coupling_map = [[0, 1], [1, 2], [2, 3], [3, 4]]
shots = 1024
result1 = self.qp.execute(["rand"], backend="local_qasm_simulator",
coupling_map=coupling_map, shots=shots, seed=self.seed)
counts = result1.get_counts("rand")
expected_probs = {
'00000': 0.079239867254200971,
'00001': 0.032859032998526903,
'00010': 0.10752610993531816,
'00011': 0.018818532050952699,
'00100': 0.054830807251011054,
'00101': 0.0034141983951965164,
'00110': 0.041649309748902276,
'00111': 0.039967731207338125,
'01000': 0.10516937819949743,
'01001': 0.026635620063700002,
'01010': 0.0053475143548793866,
'01011': 0.01940513314416064,
'01100': 0.0044028405481225047,
'01101': 0.057524760052126644,
'01110': 0.010795354134597078,
'01111': 0.026491296821535528,
'10000': 0.094827455395274859,
'10001': 0.0008373965072688836,
'10010': 0.029082297894094441,
'10011': 0.012386622870598416,
'10100': 0.018739140061148799,
'10101': 0.01367656456536896,
'10110': 0.039184170706009248,
'10111': 0.062339335178438288,
'11000': 0.00293674365989009,
'11001': 0.012848433960739968,
'11010': 0.018472497159499782,
'11011': 0.0088903691234912003,
'11100': 0.031305389080034329,
'11101': 0.0004788556283690458,
#.........这里部分代码省略.........