def create_program(pname: str, platf_cfg: str, nregisters: int = 0): """ Wrapper around the constructor of openQL "Program" class. Args: pname (str) : Name of the program platf_cfg (str) : location of the platform configuration used to construct the OpenQL Platform used. nregisters (int) : the number of classical registers required in the program. In addition to instantiating the Program, this function - creates a Platform based on the "platf_cfg" filename. - Adds the platform as an attribute "p.platf" - Adds the output_dir as an attribute "p.output_dir" """ platf = Platform('OpenQL_Platform', platf_cfg) nqubits = platf.get_qubit_number() p = Program(pname, platf, nqubits, nregisters) p.platf = platf p.output_dir = ql.get_option('output_dir') p.nqubits = platf.get_qubit_number() p.nregisters = nregisters return p
def test_compile(self): """ Only tests the compile helper by compiling an empty file. """ curdir = os.path.dirname(__file__) config_fn = os.path.join(curdir, 'test_cfg_CCL.json') p = oqh.create_program('test_program', config_fn) k = oqh.create_kernel('test_kernel', p) p.add_kernel(k) p = oqh.compile(p) fn_split = os.path.split(p.filename) self.assertEqual(fn_split[0], ql.get_option('output_dir')) self.assertEqual(fn_split[1], 'test_program.qisa')
def create_program(pname: str, platf_cfg: str, nregisters: int=32): """ Wrapper around the constructor of openQL "Program" class. Args: pname (str) : Name of the program platf_cfg (str) : location of the platform configuration used to construct the OpenQL Platform used. nregisters (int) : the number of classical registers required in the program. In addition to instantiating the Program, this function - creates a Platform based on the "platf_cfg" filename. - Adds the platform as an attribute "p.platf" - Adds the output_dir as an attribute "p.output_dir" """ platf = Platform('OpenQL_Platform', platf_cfg) nqubits = platf.get_qubit_number() p = Program(pname, platf, nqubits, nregisters) p.platf = platf p.output_dir = ql.get_option('output_dir') p.nqubits = platf.get_qubit_number() p.nregisters = nregisters # detect OpenQL backend ('eqasm_compiler') used p.eqasm_compiler = '' with open(platf_cfg) as f: for line in f: if 'eqasm_compiler' in line: m = re.search('"eqasm_compiler" *: *"(.*?)"', line) p.eqasm_compiler = m.group(1) break if p.eqasm_compiler == '': logging.error(f"key 'eqasm_compiler' not found in file '{platf_cfg}'") return p
def test_compilation(self): print('output dir : {}'.format(ql.get_option('output_dir'))) config_fn = os.path.join(curdir, 'hardware_config_qx.json') platf = ql.Platform("starmon", config_fn) sweep_points = [1] nqubits = 2 p = ql.Program("basic", platf, nqubits, nqubits) p.set_sweep_points(sweep_points) # populate kernel k = ql.Kernel("first_kernel", platf, nqubits, nqubits) k.gate('prep_z', [0]) k.gate('x', [0]) k.gate('x90', [0]) k.gate('measure', [0]) p.add_kernel(k) k = ql.Kernel("second_kernel", platf, nqubits, nqubits) k.gate('prep_z', [0]) k.gate('x90', [0]) k.gate('cz', [0, 1]) k.gate('x90', [0]) k.gate("measure", [0]) p.add_kernel(k) p.compile() # load qasm qasm_files = [] qasm_files.append(os.path.join(output_dir, 'basic.qasm')) qasm_files.append(os.path.join(output_dir, 'basic_scheduled.qasm')) for qasm_file in qasm_files: print('assembling: {}'.format(qasm_file)) assemble(qasm_file)
def test_get_values(self): # try to set a legal value and then test if it is indeed set ql.set_option('log_level', 'LOG_INFO') self.assertEqual(ql.get_option('log_level'), 'LOG_INFO') ql.set_option('output_dir', output_dir) self.assertEqual(ql.get_option('output_dir'), output_dir) ql.set_option('optimize', 'yes') self.assertEqual(ql.get_option('optimize'), 'yes') ql.set_option('scheduler', 'ALAP') self.assertEqual(ql.get_option('scheduler'), 'ALAP') ql.set_option('scheduler_uniform', 'yes') self.assertEqual(ql.get_option('scheduler_uniform'), 'yes') ql.set_option('use_default_gates', 'yes') self.assertEqual(ql.get_option('use_default_gates'), 'yes') ql.set_option('decompose_toffoli', 'NC') self.assertEqual(ql.get_option('decompose_toffoli'), 'NC')
def test_create_program(self): curdir = os.path.dirname(__file__) config_fn = os.path.join(curdir, 'test_cfg_CCL.json') p = oqh.create_program('test_program', config_fn) self.assertEqual(p.name, 'test_program') self.assertEqual(p.output_dir, ql.get_option('output_dir'))
import openql.openql as ql from os.path import join, dirname, isfile print(ql.get_version()) if 1: output_dir = join(dirname(__file__), 'output') ql.set_option('output_dir', output_dir) if 1: print(ql.get_option('output_dir'))
def test_default_scheduler(self): # tests if 'ALAP' is indeed the default scheduler policy self.assertEqual('ALAP', ql.get_option('scheduler'), 'ALAP is not the default scheduler!')