Skip to content
Open
Changes from 1 commit
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
21 changes: 20 additions & 1 deletion perceval/components/compiled_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,30 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from packaging.version import Version
import packaging, uuid

from perceval.components.linear_circuit import ACircuit
from perceval.utils.matrix import Matrix

class CompiledCircuit(ACircuit):
class Version:
Copy link
Copy Markdown
Contributor

@Aubaert Aubaert Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In python, this is weird to put classes inside other classes as this is not practical to use.

Also, I think you might benefit from using a @dataclasses.dataclass for this class, which will provide automatically the __str__, __repr__ and __eq__, as well as other methods like __ne__

def __init__(self):
self.hardware_version = packaging.version.Version('0')
self.carac_version = packaging.version.Version('0')
self.phase_at_output = True
self.empty_mode_list = []
self.matrix_uuid = uuid.UUID(int=0)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this UUID ?
A int representing the hash of a unitary might be better suited

def __repr__(self):
return f"[{self.hardware_version}, {self.carac_version}, {self.phase_at_output}, {self.matrix_uuid}]"
def __str__(self):
return self.__repr__()
def __eq__(self, other):
return self.hardware_version == other.hardware_version \
and self.carac_version == other.carac_version \
and self.phase_at_output == other.phase_at_output \
and self.empty_mode_list == other.empty_mode_list \
and self.matrix_uuid == other.matrix_uuid

def __init__(self, name: str, template_or_size: ACircuit | int, parameters: list[float], version: Version | None = None):
m = template_or_size if isinstance(template_or_size, int) else template_or_size.m
template = template_or_size if isinstance(template_or_size, ACircuit) else None
Expand Down