Skip to content

Add an option to specify qem file type #326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions python_lib/qss_compiler/lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,40 @@ 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;
if (name == "ast-pretty")
return qssc::config::EmitAction::ASTPretty;
if (name == "mlir")
return qssc::config::EmitAction::MLIR;
if (name == "bytecode")
return qssc::config::EmitAction::Bytecode;
if (name == "wmem")
return qssc::config::EmitAction::WaveMem;
if (name == "qem")
return qssc::config::EmitAction::QEM;
if (name == "qeqem")
return qssc::config::EmitAction::QEQEM;

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 std::string &emitActionString,
const std::string &configPath,
const std::unordered_map<std::string, double> &arguments,
bool treatWarningsAsErrors,
qssc::DiagnosticCallback onDiagnostic) {

std::string inMemoryOutput("");
auto emitAction = parseEmitAction(emitActionString);

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, emitAction, configPath, input, outputPath,
arguments, treatWarningsAsErrors, enableInMemoryInput,
&inMemoryOutput, std::move(onDiagnostic));

bool const success = status == 0;
#ifndef NDEBUG
Expand Down
16 changes: 16 additions & 0 deletions python_lib/qss_compiler/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."""
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -129,6 +144,7 @@ def on_diagnostic(diag):
enable_in_memory,
output_file,
link_options.target,
str(link_options.input_type),
config_path,
link_options.arguments,
link_options.treat_warnings_as_errors,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
features:
- |
Add ``--emit`` option to ``link_file`` function to specify a file format
of target file to be linked.
Loading