diff --git a/pytket/binders/circuit/Circuit/main.cpp b/pytket/binders/circuit/Circuit/main.cpp index c7fa955a14..9459cb860f 100644 --- a/pytket/binders/circuit/Circuit/main.cpp +++ b/pytket/binders/circuit/Circuit/main.cpp @@ -414,7 +414,15 @@ void def_circuit(py::class_> &pyCircuit) { "n_gates", &Circuit::n_gates, ":return: the number of gates in the Circuit") .def_property_readonly( - "wasm_uid", &Circuit::get_wasm_file_uid, + "wasm_uid", + [](const Circuit &circ) { + std::optional result; + try { + result = circ.get_wasm_file_uid(); + } catch (const std::exception &) { + } + return result; + }, ":return: the unique wasm uid of the circuit") .def_property_readonly( "n_qubits", &Circuit::n_qubits, diff --git a/pytket/pytket/_tket/circuit.pyi b/pytket/pytket/_tket/circuit.pyi index e5c2a1a76b..4b52134831 100644 --- a/pytket/pytket/_tket/circuit.pyi +++ b/pytket/pytket/_tket/circuit.pyi @@ -2572,9 +2572,9 @@ class Circuit: A list of all qubit ids in the circuit """ @property - def wasm_uid(self) -> str: + def wasm_uid(self) -> str | None: """ - :return: the wasm uid of the first wasmop found in the circuit + :return: the unique wasm uid of the circuit """ class ClBitVar: """ diff --git a/pytket/tests/classical_test.py b/pytket/tests/classical_test.py index 69e1f99a49..d45c1c052c 100644 --- a/pytket/tests/classical_test.py +++ b/pytket/tests/classical_test.py @@ -585,8 +585,7 @@ def test_wasm_uid_from_circuit_5() -> None: c = Circuit(0, 6) assert c.depth() == 0 - with pytest.raises(ValueError): - c.wasm_uid + assert c.wasm_uid is None def test_wasm_append() -> None: