Skip to content

Commit

Permalink
cr
Browse files Browse the repository at this point in the history
  • Loading branch information
apchytr committed Oct 28, 2024
1 parent fbb5083 commit 22e7696
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions mrmustard/lab_dev/circuit_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ def _serialize(self) -> tuple[dict[str, Any], dict[str, ArrayLike]]:
serializable = {"class": f"{cls.__module__}.{cls.__qualname__}"}
params = signature(cls).parameters
if "name" in params: # assume abstract type, serialize the representation
rep_cls = type(self.ansatz)
ansatz_cls = type(self.ansatz)
serializable["name"] = self.name
serializable["wires"] = self.wires.sorted_args
serializable["rep_class"] = f"{rep_cls.__module__}.{rep_cls.__qualname__}"
serializable["ansatz_cls"] = f"{ansatz_cls.__module__}.{ansatz_cls.__qualname__}"
return serializable, self.ansatz.to_dict()

# handle modes parameter
Expand All @@ -110,10 +110,10 @@ def _deserialize(cls, data: dict) -> CircuitComponent:
r"""
Deserialization when within a circuit.
"""
if "rep_class" in data:
rep_class, wires, name = map(data.pop, ["rep_class", "wires", "name"])
rep = locate(rep_class).from_dict(data)
return cls._from_attributes(Representation(rep, Wires(*map(set, wires))), name=name)
if "ansatz_cls" in data:
ansatz_cls, wires, name = map(data.pop, ["ansatz_cls", "wires", "name"])
ansatz = locate(ansatz_cls).from_dict(data)
return cls._from_attributes(Representation(ansatz, Wires(*map(set, wires))), name=name)

return cls(**data)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_lab_dev/test_circuit_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ def test_serialize_default_behaviour(self):
assert kwargs == {
"class": f"{CircuitComponent.__module__}.CircuitComponent",
"wires": cc.wires.sorted_args,
"rep_class": f"{PolyExpAnsatz.__module__}.PolyExpAnsatz",
"ansatz_cls": f"{PolyExpAnsatz.__module__}.PolyExpAnsatz",
"name": name,
}
assert arrays == {"A": ansatz.A, "b": ansatz.b, "c": ansatz.c}
Expand Down

0 comments on commit 22e7696

Please sign in to comment.