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


Python QuantumProgram.compile方法代码示例

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


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

示例1: test_change_circuit_qobj_after_compile_noname

# 需要导入模块: from qiskit import QuantumProgram [as 别名]
# 或者: from qiskit.QuantumProgram import compile [as 别名]
 def test_change_circuit_qobj_after_compile_noname(self):
     q_program = QuantumProgram(specs=self.QPS_SPECS_NONAMES)
     qr = q_program.get_quantum_register()
     cr = q_program.get_classical_register()
     qc2 = q_program.create_circuit(qregisters=[qr], cregisters=[cr])
     qc3 = q_program.create_circuit(qregisters=[qr], cregisters=[cr])
     qc2.h(qr[0])
     qc2.cx(qr[0], qr[1])
     qc2.cx(qr[0], qr[2])
     qc3.h(qr)
     qc2.measure(qr, cr)
     qc3.measure(qr, cr)
     circuits = [qc2.name, qc3.name]
     shots = 1024
     backend = 'local_qasm_simulator'
     config = {'seed': 10, 'shots': 1, 'xvals': [1, 2, 3, 4]}
     qobj1 = q_program.compile(circuits, backend=backend, shots=shots, seed=88, config=config)
     qobj1['circuits'][0]['config']['shots'] = 50
     qobj1['circuits'][0]['config']['xvals'] = [1, 1, 1]
     config['shots'] = 1000
     config['xvals'][0] = 'only for qobj2'
     qobj2 = q_program.compile(circuits, backend=backend, shots=shots, seed=88, config=config)
     self.assertTrue(qobj1['circuits'][0]['config']['shots'] == 50)
     self.assertTrue(qobj1['circuits'][1]['config']['shots'] == 1)
     self.assertTrue(qobj1['circuits'][0]['config']['xvals'] == [1, 1, 1])
     self.assertTrue(qobj1['circuits'][1]['config']['xvals'] == [1, 2, 3, 4])
     self.assertTrue(qobj1['config']['shots'] == 1024)
     self.assertTrue(qobj2['circuits'][0]['config']['shots'] == 1000)
     self.assertTrue(qobj2['circuits'][1]['config']['shots'] == 1000)
     self.assertTrue(qobj2['circuits'][0]['config']['xvals'] == [
         'only for qobj2', 2, 3, 4])
     self.assertTrue(qobj2['circuits'][1]['config']['xvals'] == [
         'only for qobj2', 2, 3, 4])
开发者ID:christians94,项目名称:qiskit-sdk-py,代码行数:35,代码来源:test_identifiers.py

示例2: test_compile_coupling_map

# 需要导入模块: from qiskit import QuantumProgram [as 别名]
# 或者: from qiskit.QuantumProgram import compile [as 别名]
    def test_compile_coupling_map(self):
        """Test compile_coupling_map.

        If all correct should return data with the same stats. The circuit may
        be different.
        """
        QP_program = QuantumProgram()
        q = QP_program.create_quantum_register("q", 3, verbose=False)
        c = QP_program.create_classical_register("c", 3, verbose=False)
        qc = QP_program.create_circuit("circuitName", [q], [c])
        qc.h(q[0])
        qc.cx(q[0], q[1])
        qc.cx(q[0], q[2])
        qc.measure(q[0], c[0])
        qc.measure(q[1], c[1])
        qc.measure(q[2], c[2])
        backend = 'local_qasm_simulator'  # the backend to run on
        shots = 1024  # the number of shots in the experiment.
        coupling_map = {0: [1], 1: [2]}
        initial_layout = {("q", 0): ("q", 0), ("q", 1): ("q", 1),
                          ("q", 2): ("q", 2)}
        circuits = ["circuitName"]
        qobj = QP_program.compile(circuits, backend=backend, shots=shots,
                                  coupling_map=coupling_map,
                                  initial_layout=initial_layout, seed=88)
        result = QP_program.run(qobj)
        to_check = QP_program.get_qasm("circuitName")
        self.assertEqual(len(to_check), 160)
        self.assertEqual(result.get_counts("circuitName"),
                         {'000': 518, '111': 506})
开发者ID:SKRohit,项目名称:The_Math_of_Intelligence,代码行数:32,代码来源:test_quantumprogram.py

示例3: test_run_program

# 需要导入模块: from qiskit import QuantumProgram [as 别名]
# 或者: from qiskit.QuantumProgram import compile [as 别名]
    def test_run_program(self):
        """Test run.

        If all correct should the data.
        """
        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])
        qc2.cx(qr[0], qr[1])
        qc2.cx(qr[0], qr[2])
        qc3.h(qr)
        qc2.measure(qr, cr)
        qc3.measure(qr, cr)
        circuits = ['qc2', 'qc3']
        shots = 1024  # the number of shots in the experiment.
        backend = 'local_qasm_simulator'
        qobj = QP_program.compile(circuits, backend=backend, shots=shots,
                                  seed=88)
        out = QP_program.run(qobj)
        results2 = out.get_counts('qc2')
        results3 = out.get_counts('qc3')
        self.assertEqual(results2, {'000': 518, '111': 506})
        self.assertEqual(results3, {'001': 119, '111': 129, '110': 134,
                                    '100': 117, '000': 129, '101': 126,
                                    '010': 145, '011': 125})
开发者ID:SKRohit,项目名称:The_Math_of_Intelligence,代码行数:30,代码来源:test_quantumprogram.py

示例4: test_simple_compile

# 需要导入模块: from qiskit import QuantumProgram [as 别名]
# 或者: from qiskit.QuantumProgram import compile [as 别名]
    def test_simple_compile(self):
        """
        Compares with and without skip_translation
        """
        name = 'test_simple'
        qp = QuantumProgram()
        qr = qp.create_quantum_register('qr', 2)
        cr = qp.create_classical_register('cr', 2)
        qc = qp.create_circuit(name, [qr], [cr])
        qc.u1(3.14, qr[0])
        qc.u2(3.14, 1.57, qr[0])
        qc.measure(qr, cr)

        rtrue = qp.compile([name], backend='local_qasm_simulator', shots=1024,
                           skip_translation=True)
        rfalse = qp.compile([name], backend='local_qasm_simulator', shots=1024,
                            skip_translation=False)
        self.assertEqual(rtrue['config'], rfalse['config'])
        self.assertEqual(rtrue['circuits'], rfalse['circuits'])
开发者ID:christians94,项目名称:qiskit-sdk-py,代码行数:21,代码来源:test_skip_translation.py

示例5: test_get_execution_list_noname

# 需要导入模块: from qiskit import QuantumProgram [as 别名]
# 或者: from qiskit.QuantumProgram import compile [as 别名]
 def test_get_execution_list_noname(self):
     """Test get_execution_list for circuits without name.
     """
     q_program = QuantumProgram(specs=self.QPS_SPECS_NONAMES)
     qc = q_program.get_circuit()
     qr = q_program.get_quantum_register()
     cr = q_program.get_classical_register()
     qc.h(qr[0])
     qc.cx(qr[0], qr[1])
     qc.measure(qr[0], cr[0])
     qc.measure(qr[1], cr[1])
     qobj = q_program.compile()
     result = q_program.get_execution_list(qobj, print_func=self.log.info)
     self.assertEqual(len(result), 1)
开发者ID:christians94,项目名称:qiskit-sdk-py,代码行数:16,代码来源:test_identifiers.py

示例6: test_compile_program_noname

# 需要导入模块: from qiskit import QuantumProgram [as 别名]
# 或者: from qiskit.QuantumProgram import compile [as 别名]
 def test_compile_program_noname(self):
     """Test compile with a no name.
     """
     q_program = QuantumProgram(specs=self.QPS_SPECS_NONAMES)
     qc = q_program.get_circuit()
     qr = q_program.get_quantum_register()
     cr = q_program.get_classical_register()
     qc.h(qr[0])
     qc.cx(qr[0], qr[1])
     qc.measure(qr[0], cr[0])
     qc.measure(qr[1], cr[1])
     out = q_program.compile()
     self.log.info(out)
     self.assertEqual(len(out), 3)
开发者ID:christians94,项目名称:qiskit-sdk-py,代码行数:16,代码来源:test_identifiers.py

示例7: test_teleport

# 需要导入模块: from qiskit import QuantumProgram [as 别名]
# 或者: from qiskit.QuantumProgram import compile [as 别名]
    def test_teleport(self):
        """test teleportation as in tutorials"""

        self.log.info('test_teleport')
        pi = np.pi
        shots = 1000
        qp = QuantumProgram()
        qr = qp.create_quantum_register('qr', 3)
        cr0 = qp.create_classical_register('cr0', 1)
        cr1 = qp.create_classical_register('cr1', 1)
        cr2 = qp.create_classical_register('cr2', 1)
        circuit = qp.create_circuit('teleport', [qr],
                                    [cr0, cr1, cr2])
        circuit.h(qr[1])
        circuit.cx(qr[1], qr[2])
        circuit.ry(pi/4, qr[0])
        circuit.cx(qr[0], qr[1])
        circuit.h(qr[0])
        circuit.barrier(qr)
        circuit.measure(qr[0], cr0[0])
        circuit.measure(qr[1], cr1[0])
        circuit.z(qr[2]).c_if(cr0, 1)
        circuit.x(qr[2]).c_if(cr1, 1)
        circuit.measure(qr[2], cr2[0])
        backend = 'local_qasm_simulator'
        qobj = qp.compile('teleport', backend=backend, shots=shots,
                   seed=self.seed)
        results = qp.run(qobj)
        data = results.get_counts('teleport')
        alice = {}
        bob = {}
        alice['00'] = data['0 0 0'] + data['1 0 0']
        alice['01'] = data['0 1 0'] + data['1 1 0']
        alice['10'] = data['0 0 1'] + data['1 0 1']
        alice['11'] = data['0 1 1'] + data['1 1 1']
        bob['0'] = data['0 0 0'] + data['0 1 0'] +  data['0 0 1'] + data['0 1 1']
        bob['1'] = data['1 0 0'] + data['1 1 0'] +  data['1 0 1'] + data['1 1 1']
        self.log.info('test_telport: circuit:')
        self.log.info( circuit.qasm() )
        self.log.info('test_teleport: data {0}'.format(data))
        self.log.info('test_teleport: alice {0}'.format(alice))
        self.log.info('test_teleport: bob {0}'.format(bob))
        alice_ratio = 1/np.tan(pi/8)**2
        bob_ratio = bob['0']/float(bob['1'])
        error = abs(alice_ratio - bob_ratio) / alice_ratio
        self.log.info('test_teleport: relative error = {0:.4f}'.format(error))
        self.assertLess(error, 0.05)
开发者ID:tathagatnawadia,项目名称:qiskit-sdk-py,代码行数:49,代码来源:test_qasm_python_simulator.py

示例8: test_compile_program

# 需要导入模块: from qiskit import QuantumProgram [as 别名]
# 或者: from qiskit.QuantumProgram import compile [as 别名]
    def test_compile_program(self):
        """Test compile_program.

        If all correct should return COMPLETED.
        """
        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 = 'test'
        coupling_map = None
        out = QP_program.compile(['circuitName'], backend=backend,
                                 coupling_map=coupling_map, qobjid='cooljob')
        # print(out)
        self.assertEqual(len(out), 3)
开发者ID:SKRohit,项目名称:The_Math_of_Intelligence,代码行数:21,代码来源:test_quantumprogram.py

示例9: test_get_execution_list

# 需要导入模块: from qiskit import QuantumProgram [as 别名]
# 或者: from qiskit.QuantumProgram import compile [as 别名]
    def test_get_execution_list(self):
        """Test get_execution_list.

        If all correct should return {'local_qasm_simulator': ['circuitName']}.
        """
        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, qobjid="cooljob")
        result = QP_program.get_execution_list(qobj)
        # print(result)
        self.assertEqual(result, ['circuitName'])
开发者ID:SKRohit,项目名称:The_Math_of_Intelligence,代码行数:22,代码来源:test_quantumprogram.py

示例10: test_get_compiled_qasm

# 需要导入模块: from qiskit import QuantumProgram [as 别名]
# 或者: from qiskit.QuantumProgram import compile [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)
开发者ID:SKRohit,项目名称:The_Math_of_Intelligence,代码行数:22,代码来源:test_quantumprogram.py

示例11: test_run_program_map

# 需要导入模块: from qiskit import QuantumProgram [as 别名]
# 或者: from qiskit.QuantumProgram import compile [as 别名]
    def test_run_program_map(self):
        """Test run_program_map.

        If all correct should return 10010.
        """
        QP_program = QuantumProgram()
        QP_program.set_api(API_TOKEN, URL)
        backend = 'local_qasm_simulator'  # the backend to run on
        shots = 100  # the number of shots in the experiment.
        max_credits = 3
        coupling_map = {0: [1], 1: [2], 2: [3], 3: [4]}
        initial_layout = {("q", 0): ("q", 0), ("q", 1): ("q", 1),
                          ("q", 2): ("q", 2), ("q", 3): ("q", 3),
                          ("q", 4): ("q", 4)}
        QP_program.load_qasm_file(QASM_FILE_PATH_2, name="circuit-dev")
        circuits = ["circuit-dev"]
        qobj = QP_program.compile(circuits, backend=backend, shots=shots,
                                  max_credits=max_credits, seed=65,
                                  coupling_map=coupling_map,
                                  initial_layout=initial_layout)
        result = QP_program.run(qobj)
        self.assertEqual(result.get_counts("circuit-dev"), {'10010': 100})
开发者ID:SKRohit,项目名称:The_Math_of_Intelligence,代码行数:24,代码来源:test_quantumprogram.py

示例12: print

# 需要导入模块: from qiskit import QuantumProgram [as 别名]
# 或者: from qiskit.QuantumProgram import compile [as 别名]
qc = qp.create_circuit('Bell', [qr], [cr])

qc.h(qr[0])
qc.cx(qr[0], qr[1])
qc.measure(qr[0], cr[0])
qc.measure(qr[1], cr[1])

source = qp.get_qasm('Bell')
print(source)

#result = qp.execute('Bell')


circuits = ['Bell']

qobj = qp.compile(circuits, backend)

result = qp.run(qobj, wait=2, timeout=240)


#print(result.get_counts('Bell'))

pprint(qp.available_backends())

#pprint(qp.get_backend_status('ibmqx2'))


pprint(qp.get_backend_configuration('ibmqx5'))


开发者ID:vtomole,项目名称:project-1,代码行数:30,代码来源:bell.py

示例13: test_example_multiple_compile

# 需要导入模块: from qiskit import QuantumProgram [as 别名]
# 或者: from qiskit.QuantumProgram import compile [as 别名]
    def test_example_multiple_compile(self):
        """Test a toy example compiling multiple circuits.

        Pass if the results are correct.
        """
        coupling_map = {0: [1, 2],
                        1: [2],
                        2: [],
                        3: [2, 4],
                        4: [2]}
        QPS_SPECS = {
            "circuits": [{
                "name": "ghz",
                "quantum_registers": [{
                    "name": "q",
                    "size": 5
                }],
                "classical_registers": [{
                    "name": "c",
                    "size": 5}
                ]}, {
                "name": "bell",
                "quantum_registers": [{
                    "name": "q",
                    "size": 5
                }],
                "classical_registers": [{
                    "name": "c",
                    "size": 5
                }]}
            ]
        }
        qp = QuantumProgram(specs=QPS_SPECS)
        ghz = qp.get_circuit("ghz")
        bell = qp.get_circuit("bell")
        q = qp.get_quantum_register("q")
        c = qp.get_classical_register("c")
        # Create a GHZ state
        ghz.h(q[0])
        for i in range(4):
            ghz.cx(q[i], q[i+1])
        # Insert a barrier before measurement
        ghz.barrier()
        # Measure all of the qubits in the standard basis
        for i in range(5):
            ghz.measure(q[i], c[i])
        # Create a Bell state
        bell.h(q[0])
        bell.cx(q[0], q[1])
        bell.barrier()
        bell.measure(q[0], c[0])
        bell.measure(q[1], c[1])
        qp.set_api(API_TOKEN, URL)
        bellobj = qp.compile(["bell"], backend='local_qasm_simulator',
                             shots=2048, seed=10)
        ghzobj = qp.compile(["ghz"], backend='local_qasm_simulator',
                            shots=2048, coupling_map=coupling_map,
                            seed=10)
        bellresult = qp.run(bellobj)
        ghzresult = qp.run(ghzobj)
        print(bellresult.get_counts("bell"))
        print(ghzresult.get_counts("ghz"))
        self.assertEqual(bellresult.get_counts("bell"),
                         {'00000': 1034, '00011': 1014})
        self.assertEqual(ghzresult.get_counts("ghz"),
                         {'00000': 1047, '11111': 1001})
开发者ID:SKRohit,项目名称:The_Math_of_Intelligence,代码行数:68,代码来源:test_quantumprogram.py

示例14: range

# 需要导入模块: from qiskit import QuantumProgram [as 别名]
# 或者: from qiskit.QuantumProgram import compile [as 别名]
qc.x(a[0])  # Set input a = 0...0001
qc.x(b)   # Set input b = 1...1111
# Apply the adder
qc += adder_subcircuit
# Measure the output register in the computational basis
for j in range(n):
    qc.measure(b[j], ans[j])
qc.measure(cout[0], ans[n])

###############################################################
# Set up the API and execute the program.
###############################################################
qp.set_api(Qconfig.APItoken, Qconfig.config["url"])

# First version: not mapped
result = qp.execute(["rippleadd"], backend=backend,
                    coupling_map=None, shots=1024)
print(result)
print(result.get_counts("rippleadd"))

# Second version: mapped to 2x8 array coupling graph
obj = qp.compile(["rippleadd"], backend=backend,
                 coupling_map=coupling_map, shots=1024)
result = qp.run(obj)

print(result)
print(result.get_ran_qasm("rippleadd"))
print(result.get_counts("rippleadd"))

# Both versions should give the same distribution
开发者ID:christians94,项目名称:qiskit-sdk-py,代码行数:32,代码来源:rippleadd.py

示例15: print

# 需要导入模块: from qiskit import QuantumProgram [as 别名]
# 或者: from qiskit.QuantumProgram import compile [as 别名]
###############################################################
try:
    qp.set_api(Qconfig.APItoken, Qconfig.config["url"])
except:
    offline = True
    print("""WARNING: There's no connection with IBMQuantumExperience servers.
             cannot test I/O intesive tasks, will only test CPU intensive tasks
             running the jobs in the local simulator""")

qobjs = []
# Create online (so I/O bound) jobs if we have connetion or local (so CPU bound)
# jobs otherwise
if offline == False:
    print("Creating %d online jobs..." % NUM_JOBS)
    for _ in range(0, NUM_JOBS):
        qobjs.append(qp.compile(["rippleadd"], backend=online_backend,
                coupling_map=None, shots=1024))

print("Creating %d local jobs..." % NUM_JOBS)
# Create CPU intensive jobs
for _ in range(0, NUM_JOBS):
    qobjs.append(qp.compile(["rippleadd"], backend=local_backend,
              coupling_map=None, shots=1024))

end = False
# This function will be called once all jobs have finished.
def print_results_callback(results, error=None):
    if error != None:
        print("There was an error executing the circuits!!: Error = {}".format(error))
        return

    for result in results:
开发者ID:tathagatnawadia,项目名称:qiskit-sdk-py,代码行数:34,代码来源:rippleadd-async.py


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