Skip to content

Commit 59b1315

Browse files
fix: Fixes from integration tests - rotation codegen, array results, process environment management (#1)
* Add rotation codegen extension to selene-hugr-qis-compiler * Coerce array results to lists (rather than tuples) for compatibility with HUGR result handling * When spawning a selene process, append to the host environment paths rather than replacing it. * Update guppy test to take into account new list format of parsed array results * Further update guppy test to take into account new list format of parsed array results * Remove unnecessary QIS prelude codegen clone when creating the RotationCodegenExtension
1 parent 52ec1d3 commit 59b1315

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

selene-compilers/hugr_qis/rust/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ use std::rc::Rc;
2727
use std::vec::Vec;
2828
use std::{fs, str, vec};
2929
use tket2::extension::TKET2_EXTENSION;
30+
use tket2::extension::rotation::ROTATION_EXTENSION;
3031
use tket2::hugr::extension::{ExtensionRegistry, prelude};
3132
use tket2::hugr::std_extensions::arithmetic::{
3233
conversions, float_ops, float_types, int_ops, int_types,
3334
};
3435
use tket2::hugr::std_extensions::{collections, logic, ptr};
3536
use tket2::hugr::{self, llvm::inkwell};
3637
use tket2::hugr::{Hugr, HugrView, Node};
38+
use tket2::llvm::rotation::RotationCodegenExtension;
3739
use tket2_hseries::QSystemPass;
3840
use tket2_hseries::extension::{futures as qsystem_futures, qsystem, result as qsystem_result};
3941
pub use tket2_hseries::llvm::futures::FuturesCodegenExtension;
@@ -67,6 +69,7 @@ static REGISTRY: std::sync::LazyLock<ExtensionRegistry> = std::sync::LazyLock::n
6769
qsystem_futures::EXTENSION.to_owned(),
6870
qsystem_result::EXTENSION.to_owned(),
6971
qsystem::EXTENSION.to_owned(),
72+
ROTATION_EXTENSION.to_owned(),
7073
TKET2_EXTENSION.to_owned(),
7174
tket2::extension::bool::BOOL_EXTENSION.to_owned(),
7275
tket2::extension::debug::DEBUG_EXTENSION.to_owned(),
@@ -144,9 +147,10 @@ fn codegen_extensions() -> CodegenExtsMap<'static, Hugr> {
144147
.add_extension(ArrayCodegenExtension::new(DefaultArrayCodegen))
145148
.add_default_static_array_extensions()
146149
.add_extension(FuturesCodegenExtension)
147-
.add_extension(QSystemCodegenExtension::from(pcg))
150+
.add_extension(QSystemCodegenExtension::from(pcg.clone()))
148151
.add_extension(RandomCodegenExtension)
149152
.add_extension(ResultsCodegenExtension)
153+
.add_extension(RotationCodegenExtension::new(pcg))
150154
.add_extension(UtilsCodegenExtension)
151155
.add_extension(DebugCodegenExtension)
152156
.finish()

selene-sim/python/selene_sim/instance.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,19 @@ def get_environment(self) -> dict:
8585
Get the environment variables for the process.
8686
"""
8787
env = os.environ.copy()
88+
additional_dirs = os.pathsep.join(str(p) for p in self.library_search_dirs)
89+
path_name = ""
8890
match platform.system():
8991
case "Linux":
90-
env["LD_LIBRARY_PATH"] = os.pathsep.join(
91-
str(p) for p in self.library_search_dirs
92-
)
92+
path_name = "LD_LIBRARY_PATH"
9393
case "Darwin":
94-
env["DYLD_LIBRARY_PATH"] = os.pathsep.join(
95-
str(p) for p in self.library_search_dirs
96-
)
94+
path_name = "DYLD_LIBRARY_PATH"
9795
case "Windows":
98-
env["PATH"] = os.pathsep.join(str(p) for p in self.library_search_dirs)
96+
path_name = "PATH"
97+
if path_name in env:
98+
env[path_name] += os.pathsep + additional_dirs
99+
else:
100+
env[path_name] = additional_dirs
99101
return env
100102

101103
def spawn(self):

selene-sim/python/selene_sim/result_handling/result_stream.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,25 +105,25 @@ def _parse_row(self) -> tuple[Any, ...]:
105105
res.append(val)
106106
case (self.UINT_TAG, sz):
107107
vals = unpack(f"{sz}Q", self.get_chunk(sz * 8))
108-
res.append(vals)
108+
res.append(list(vals))
109109
case (self.INT_TAG, 0):
110110
(val,) = unpack("q", self.get_chunk(8))
111111
res.append(val)
112112
case (self.INT_TAG, sz):
113113
vals = unpack(f"{sz}q", self.get_chunk(sz * 8))
114-
res.append(vals)
114+
res.append(list(vals))
115115
case (self.FLT_TAG, 0):
116116
(val,) = unpack("d", self.get_chunk(8))
117117
res.append(val)
118118
case (self.FLT_TAG, sz):
119119
vals = unpack(f"{sz}d", self.get_chunk(sz * 8))
120-
res.append(vals)
120+
res.append(list(vals))
121121
case (self.BIT_TAG, 0):
122122
(val,) = unpack("B", self.get_chunk(1))
123123
res.append(val)
124124
case (self.BIT_TAG, sz):
125125
vals = unpack(f"{sz}B", self.get_chunk(sz))
126-
res.append(vals)
126+
res.append(list(vals))
127127
case (self.STR_TAG, sz):
128128
val = self.get_chunk(sz).decode("utf-8")
129129
res.append(val)

selene-sim/python/tests/test_guppy.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ def main() -> None:
105105

106106
runner = build(guppy.compile(main), "flip_n4_arr")
107107
expected = {
108-
"cs": (1, 0, 1, 1, 0, 0, 0, 0, 0, 1),
109-
"is": tuple(range(100)),
110-
"fs": tuple(i * 0.0625 for i in range(100)),
108+
"cs": [1, 0, 1, 1, 0, 0, 0, 0, 0, 1],
109+
"is": list(range(100)),
110+
"fs": list(i * 0.0625 for i in range(100)),
111111
}
112112

113113
# run the simulation on Quest and Stim

0 commit comments

Comments
 (0)