From 299e2ee40924de5d279034245754901c08edf4e2 Mon Sep 17 00:00:00 2001 From: Hiroshi Horii Date: Tue, 30 Apr 2024 23:59:42 +0900 Subject: [PATCH 1/4] add an option to specify qem file type --- python_lib/qss_compiler/lib.cpp | 9 +++++---- python_lib/qss_compiler/link.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/python_lib/qss_compiler/lib.cpp b/python_lib/qss_compiler/lib.cpp index 865a112ae..47213d734 100644 --- a/python_lib/qss_compiler/lib.cpp +++ b/python_lib/qss_compiler/lib.cpp @@ -224,6 +224,7 @@ py::tuple py_compile_file(const std::string &inputFile, py::tuple py_link_file(const std::string &input, const bool enableInMemoryInput, const std::string &outputPath, const std::string &target, + const qssc::config::EmitAction action, const std::string &configPath, const std::unordered_map &arguments, bool treatWarningsAsErrors, @@ -231,10 +232,10 @@ py::tuple py_link_file(const std::string &input, const bool enableInMemoryInput, std::string inMemoryOutput(""); - int const status = qssc::bindArguments( - target, qssc::config::EmitAction::QEM, configPath, input, outputPath, - arguments, treatWarningsAsErrors, enableInMemoryInput, &inMemoryOutput, - std::move(onDiagnostic)); + int const status = + qssc::bindArguments(target, action, configPath, input, outputPath, + arguments, treatWarningsAsErrors, enableInMemoryInput, + &inMemoryOutput, std::move(onDiagnostic)); bool const success = status == 0; #ifndef NDEBUG diff --git a/python_lib/qss_compiler/link.py b/python_lib/qss_compiler/link.py index 7244614e1..c571e37ea 100644 --- a/python_lib/qss_compiler/link.py +++ b/python_lib/qss_compiler/link.py @@ -20,6 +20,7 @@ """ from dataclasses import dataclass, field +from enum import Enum from importlib import resources as importlib_resources from os import environ as os_environ from typing import Mapping, Any, Optional, Callable, Union @@ -31,6 +32,16 @@ from . import exceptions +class InputType(Enum): + """Enumeration of input types supported by the link""" + + QEM = "qem" + QEQEM = "qe-qem" + + def __str__(self): + return self.value + + @dataclass class LinkOptions: """Options to the linker tool.""" @@ -42,6 +53,8 @@ class LinkOptions: output_file: Union[str, None] = None """Output file, if not supplied raw bytes will be returned.""" target: str = None + """Input source type.""" + input_type: InputType = InputType.QEM """Hardware target to select.""" arguments: Mapping[str, Any] = field(default_factory=lambda: {}) """Set the specific execution arguments of a pre-compiled program @@ -75,6 +88,8 @@ def link_file( output_file: Path to write the output payload to. target: Compiler target to invoke for binding arguments (must match with the target that created the module). + input_type: Input file type to invoke for binding arguments (must match + with the output type that created the module). arguments: Circuit arguments as name/value map. Returns: Produces a payload in a file. @@ -129,6 +144,7 @@ def on_diagnostic(diag): enable_in_memory, output_file, link_options.target, + link_options.input_type, config_path, link_options.arguments, link_options.treat_warnings_as_errors, From a59468aa789db5adeb4b3c7bd7d452f18f799d1f Mon Sep 17 00:00:00 2001 From: Hiroshi Horii Date: Sat, 11 May 2024 00:08:41 +0900 Subject: [PATCH 2/4] fix build error --- python_lib/qss_compiler/lib.cpp | 24 ++++++++++++++++++++++-- python_lib/qss_compiler/link.py | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/python_lib/qss_compiler/lib.cpp b/python_lib/qss_compiler/lib.cpp index 47213d734..dc3713e7d 100644 --- a/python_lib/qss_compiler/lib.cpp +++ b/python_lib/qss_compiler/lib.cpp @@ -222,18 +222,38 @@ py::tuple py_compile_file(const std::string &inputFile, std::move(onDiagnostic)); } +qssc::config::EmitAction parseEmitAction(const std::string &name) { + if (name == "ast") + return qssc::config::EmitAction::AST; + else if (name == "ast-pretty") + return qssc::config::EmitAction::ASTPretty; + else if (name == "mlir") + return qssc::config::EmitAction::MLIR; + else if (name == "bytecode") + return qssc::config::EmitAction::Bytecode; + else if (name == "wmem") + return qssc::config::EmitAction::WaveMem; + else if (name == "qem") + return qssc::config::EmitAction::QEM; + else if (name == "qeqem") + return qssc::config::EmitAction::QEQEM; + else + return qssc::config::EmitAction::None; +} + py::tuple py_link_file(const std::string &input, const bool enableInMemoryInput, const std::string &outputPath, const std::string &target, - const qssc::config::EmitAction action, + const std::string &emitActionString, const std::string &configPath, const std::unordered_map &arguments, bool treatWarningsAsErrors, qssc::DiagnosticCallback onDiagnostic) { std::string inMemoryOutput(""); + auto emitAction = parseEmitAction(emitActionString); int const status = - qssc::bindArguments(target, action, configPath, input, outputPath, + qssc::bindArguments(target, emitAction, configPath, input, outputPath, arguments, treatWarningsAsErrors, enableInMemoryInput, &inMemoryOutput, std::move(onDiagnostic)); diff --git a/python_lib/qss_compiler/link.py b/python_lib/qss_compiler/link.py index c571e37ea..1ced6b7f6 100644 --- a/python_lib/qss_compiler/link.py +++ b/python_lib/qss_compiler/link.py @@ -144,7 +144,7 @@ def on_diagnostic(diag): enable_in_memory, output_file, link_options.target, - link_options.input_type, + str(link_options.input_type), config_path, link_options.arguments, link_options.treat_warnings_as_errors, From 8afc504576f86451d6bf3079a05bdcae24779d44 Mon Sep 17 00:00:00 2001 From: Hiroshi Horii Date: Sat, 11 May 2024 00:29:07 +0900 Subject: [PATCH 3/4] add reno --- .../notes/add_emit_option_to_link_file-8901fd3d6ed51d98.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 releasenotes/notes/add_emit_option_to_link_file-8901fd3d6ed51d98.yaml diff --git a/releasenotes/notes/add_emit_option_to_link_file-8901fd3d6ed51d98.yaml b/releasenotes/notes/add_emit_option_to_link_file-8901fd3d6ed51d98.yaml new file mode 100644 index 000000000..b8ddb080c --- /dev/null +++ b/releasenotes/notes/add_emit_option_to_link_file-8901fd3d6ed51d98.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Add ``--emit`` option to ``link_file`` function to specify a file format + of target file to be linked. From 680dc118d7b2f946f50313027a53080485e23dc2 Mon Sep 17 00:00:00 2001 From: Hiroshi Horii Date: Mon, 13 May 2024 09:30:22 +0900 Subject: [PATCH 4/4] apply clang-format suggestions --- python_lib/qss_compiler/lib.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/python_lib/qss_compiler/lib.cpp b/python_lib/qss_compiler/lib.cpp index dc3713e7d..63f1f09ef 100644 --- a/python_lib/qss_compiler/lib.cpp +++ b/python_lib/qss_compiler/lib.cpp @@ -225,20 +225,20 @@ py::tuple py_compile_file(const std::string &inputFile, qssc::config::EmitAction parseEmitAction(const std::string &name) { if (name == "ast") return qssc::config::EmitAction::AST; - else if (name == "ast-pretty") + if (name == "ast-pretty") return qssc::config::EmitAction::ASTPretty; - else if (name == "mlir") + if (name == "mlir") return qssc::config::EmitAction::MLIR; - else if (name == "bytecode") + if (name == "bytecode") return qssc::config::EmitAction::Bytecode; - else if (name == "wmem") + if (name == "wmem") return qssc::config::EmitAction::WaveMem; - else if (name == "qem") + if (name == "qem") return qssc::config::EmitAction::QEM; - else if (name == "qeqem") + if (name == "qeqem") return qssc::config::EmitAction::QEQEM; - else - return qssc::config::EmitAction::None; + + return qssc::config::EmitAction::None; } py::tuple py_link_file(const std::string &input, const bool enableInMemoryInput,