Skip to content

qubic.toolchain

ToolChainLogFilter

Bases: Filter, ABC

This is to make sure we have a reset method, and the ability to detect and remove logging filters that we have added (so we don't remove all filters).

Source code in qubic/toolchain.py
 96
 97
 98
 99
100
101
102
103
104
class ToolChainLogFilter(logging.Filter, ABC):
    """
    This is to make sure we have a reset method, and the ability to detect and
    remove logging filters that we have added (so we don't remove all filters).
    """

    @abstractmethod
    def reset(self):
        pass

initialize_logging(suppress_warnings=True)

TODO: add more logging options to user reqs, also maybe move the logging.basicConfig call to another global init method

Source code in qubic/toolchain.py
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
def initialize_logging(suppress_warnings=True):
    """
    TODO: add more logging options to user reqs, also maybe
    move the logging.basicConfig call to another global init method
    """
    logging.basicConfig()
    if suppress_warnings:
        for handler in logging.root.handlers:
            if len(handler.filters) == 0:
                handler.addFilter(WarningSuppressor())
            else:
                for filter in handler.filters:
                    if isinstance(filter, ToolChainLogFilter):
                        filter.reset()

    else:
        for handler in logging.root.handlers:
            for filter in handler.filters:
                if isinstance(filter, ToolChainLogFilter):
                    handler.removeFilter(filter)

run_assemble_stage(compiled_program, channel_configs, target_platform='rfsoc')

Wrapper around distributed processor assembler stage.

Parameters:

Name Type Description Default
compiled_program CompiledProgram | List[CompiledProgram]
required
channel_configs Dict[str, ChannelConfig]
required
target_platform str

target hardware platform; currently only 'rfsoc' is supported

'rfsoc'

Returns:

Type Description
dict or list of dict

dict(s) containing the assembled binaries

Source code in qubic/toolchain.py
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
def run_assemble_stage(compiled_program: cm.CompiledProgram | List[cm.CompiledProgram], 
                       channel_configs: Dict[str, hw.ChannelConfig], target_platform: str = 'rfsoc') -> Dict | List[Dict]:
    """
    Wrapper around distributed processor assembler stage. 

    Parameters
    ----------
    compiled_program: CompiledProgram | List[CompiledProgram]
    channel_configs: hw.ChannelConfig
    target_platform: str
        target hardware platform; currently only 'rfsoc' is supported

    Returns
    -------
    dict or list of dict
        dict(s) containing the assembled binaries 
    """
    if target_platform != 'rfsoc':
        raise Exception('rfsoc is currently the only supported platform!')

    if isinstance(compiled_program, list):
        raw_asm_progs = []
        for prog in compiled_program:
            asm = am.GlobalAssembler(prog, channel_configs, hw.elemconfig_classfactory)
            raw_asm_progs.append(asm.get_assembled_program())
        return raw_asm_progs

    else:
        asm = am.GlobalAssembler(compiled_program, channel_configs, hw.elemconfig_classfactory)
        return asm.get_assembled_program()

run_compile_stage(program, fpga_config, qchip, compiler_flags=None, qubit_grouping=('{qubit}.qdrv', '{qubit}.rdrv', '{qubit}.rdlo'), proc_grouping=[('{qubit}.qdrv', '{qubit}.rdrv', '{qubit}.rdlo')], suppress_duplicate_warnings=False)

Wrapper around distributed processor compiler stage.

Parameters:

Name Type Description Default
program List

single QubiC program or list of programs. Each program can be:

- list of dicts formatted according to the QubiC Higher-level 
  Representation
- list of QubiC intermediate representation instructions 
  (distproc.ir_instruction classes)
required
fpga_config FPGAConfig
required
qchip QChip
required
compiler_flags Dict[str, bool] | CompilerFlags

Options for configuring the compiler; see distproc.compiler.get_passes for more details. Default is None, which sets all flags to True (fine for most use cases)

None
suppress_warnings

If True, suppress duplicate instances of a warning within a batch

required

Returns:

Type Description
CompiledProgram or List[CompiledProgram]

object containing compiled program

Source code in qubic/toolchain.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
def run_compile_stage(program: List, 
                      fpga_config: hw.FPGAConfig, 
                      qchip: qc.QChip, 
                      compiler_flags: Dict[str, bool] | cm.CompilerFlags = None,
                      qubit_grouping: Tuple[str] = ('{qubit}.qdrv', '{qubit}.rdrv', '{qubit}.rdlo'),
                      proc_grouping: List[Tuple] = [('{qubit}.qdrv', '{qubit}.rdrv', '{qubit}.rdlo')],
                      suppress_duplicate_warnings: bool = False) -> cm.CompiledProgram | List[cm.CompiledProgram]:
    """
    Wrapper around distributed processor compiler stage. 

    Parameters
    ----------
    program: list
        single QubiC program or list of programs. Each program can be:

            - list of dicts formatted according to the QubiC Higher-level 
              Representation
            - list of QubiC intermediate representation instructions 
              (distproc.ir_instruction classes)
    fpga_config: hw.FPGAConfig
    qchip: qc.QChip
    compiler_flags: dict | cm.CompilerFlags
        Options for configuring the compiler; see distproc.compiler.get_passes for 
        more details. Default is None, which sets all flags to True (fine for 
        most use cases)
    suppress_warnings: bool
        If True, suppress duplicate instances of a warning within a batch

    Returns
    -------
    CompiledProgram or List[CompiledProgram]
        object containing compiled program
    """
    if suppress_duplicate_warnings:
        initialize_logging(suppress_warnings=True)
    else:
        initialize_logging(suppress_warnings=False)

    passes = cm.get_passes(fpga_config, qchip, compiler_flags=compiler_flags, 
                           qubit_grouping=qubit_grouping, proc_grouping=proc_grouping)
    if isinstance(program[0], dict):
        compiler = cm.Compiler(program, proc_grouping)
        compiler.run_ir_passes(passes)
        return compiler.compile()
    elif isinstance(program[0], list):
        compiled_progs = []
        for circuit in program:
            compiler = cm.Compiler(circuit, proc_grouping)
            compiler.run_ir_passes(passes)
            compiled_progs.append(compiler.compile())
        return compiled_progs
    else:
        raise TypeError