Пример #1
0
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"

    """

    # create OpenQL Program object see https://openql.readthedocs.io/en/latest/api/Program.html
    if 1:  # FIXME: workaround for OpenQL 0.8.1.dev4 re-setting option
        ql.set_option('output_dir', output_dir)

    platf = Platform('OpenQL_Platform', platf_cfg)
    nqubits = platf.get_qubit_number()
    p = Program(pname, platf, nqubits, nregisters)

    # add information to the Program object (FIXME: better create new type, seems to duplicate qubit_count and creg_count)
    p.platf = platf
    p.output_dir = output_dir
    p.nqubits = platf.get_qubit_number()
    p.nregisters = nregisters

    # detect OpenQL backend ('eqasm_compiler') used by inspecting platf_cfg
    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}'")

    # determine extension of generated file
    #if p.eqasm_compiler == 'eqasm_backend_cc':
    if 1:  # FIXME: workaround for OpenQL 0.8.1.dev4 resetting values
        ext = '.vq1asm'  # CC
    else:
        ext = '.qisa'  # CC-light, QCC

    # add filename to help finding the output files. NB: file is created by calling compile()
    p.filename = join(p.output_dir, p.name + ext)
    return p
Пример #2
0
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