qat.frontend.auto module
- class AutoFrontend(model, *frontends)
Bases:
BaseFrontend
Automatically deploys a frontend to match the type of source language.
Provided with a number of frontends, the
AutoFrontend
will attempt to match a source program to the frontend. If successful, it will use the matched frontend to emit the source program as Qat IR.Warning
The
AutoFrontend
will check the source programs against the frontends in the order provided. If multiple frontends are capable of processing a source file, then the order should be strategically chosen to have the desired outcome. For example, if using theFallthroughFrontend
, this should be placed at the end of line to allow other frontends the opportunity to be matched.- Parameters:
model¶ (
QuantumHardwareModel
|PhysicalHardwareModel
|None
) – The hardware model is needed to instantiate the default frontends, defaults to None.frontends¶ (
BaseFrontend
) – The different frontends to check the source file against.
- assign_frontend(src)
Determines the source language and assigns the correct frontend.
- Parameters:
src¶ – The source program to discriminate.
- Return type:
BaseFrontend
|None
- Returns:
The first frontend that is able to recognise the source program. Returns None if no suitable frontend is found.
- check_and_return_source(src)
Checks the source file sequentially against the different frontends. If a suitable frontend is found, the source program is returned.
- Parameters:
src¶ – The source program, or path to the program.
- Returns:
If the program is determined to not be valid, False is returned. Otherwise, the program is returned (and loaded if required).
- static default_frontends(model)
Returns a default list of frontends to try.
- Parameters:
model¶ – The hardware model is needed to instantiate the default frontends.
- Return type:
list
[BaseFrontend
]
- emit(src, res_mgr=None, met_mgr=None, compiler_config=None)
Chooses a suitable frontend and compiles a given source program.
- Parameters:
src¶ – The source program, or path to the source program.
res_mgr¶ (
Optional
[ResultManager
]) – The result manager to store results from passes within the pipeline, defaults to None.met_mgr¶ (
Optional
[MetricsManager
]) – The metrics manager to store metrics, such as the optimized QASM circuit, defaults to None.compiler_config¶ (
Optional
[CompilerConfig
]) – The compiler config, defaults to None.
- Raises:
ValueError – An error is thrown if no suitable frontend could be found.