Skip to content

Commit cb2e8fb

Browse files
committed
🚸 Expose namachine export to Python
1 parent ad7b1d1 commit cb2e8fb

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

bindings/na/zoned/zoned.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ PYBIND11_MODULE(MQT_QMAP_MODULE_NAME, m, py::mod_gil_not_used()) {
3939
&na::zoned::Architecture::fromJSONFile, "filename"_a);
4040
architecture.def_static("from_json_string",
4141
&na::zoned::Architecture::fromJSONString, "json"_a);
42+
architecture.def(
43+
"to_namachine_file",
44+
[](na::zoned::Architecture& self, const std::string& filename) -> void {
45+
self.exportNAVizMachine(filename);
46+
},
47+
"filename"_a);
48+
architecture.def("to_namachine_string",
49+
[](na::zoned::Architecture& self) -> std::string {
50+
return self.exportNAVizMachine();
51+
});
4252

4353
py::class_<na::zoned::RoutingAgnosticCompiler> routingAgnosticCompiler(
4454
m, "RoutingAgnosticCompiler");

python/mqt/qmap/na/zoned.pyi

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ class ZonedNeutralAtomArchitecture:
3939
Raises:
4040
ValueError: if the string is not a valid JSON
4141
"""
42+
def to_namachine_file(self, filename: str) -> None:
43+
"""Write the architecture to a .namachine file.
44+
45+
Args:
46+
filename: is the path to the .namachine file
47+
"""
48+
def to_namachine_string(self) -> str:
49+
"""Get the architecture as a .namachine string.
50+
51+
Returns:
52+
the architecture as a .namachine string
53+
"""
4254

4355
class RoutingAgnosticCompiler:
4456
"""MQT QMAP's routing-agnostic Zoned Neutral Atom Compiler."""

test/python/na/test_zoned.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@
4444
}"""
4545

4646

47+
def test_architecture_to_namachine_string() -> None:
48+
"""Test the Zoned Neutral Atom Architecture to namachine string conversion."""
49+
architecture = ZonedNeutralAtomArchitecture.from_json_string(architecture_specification)
50+
namachine_string = architecture.to_namachine_string()
51+
assert isinstance(namachine_string, str)
52+
assert len(namachine_string) > 0
53+
54+
4755
@pytest.fixture
4856
def compiler() -> RoutingAwareCompiler:
4957
"""Return an MQT QMAP's Zoned Neutral Atom Compiler initialized with the above architecture and settings."""

0 commit comments

Comments
 (0)