Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
51 changes: 51 additions & 0 deletions cirbo/core/circuit/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,57 @@ def from_bench_string(string: str) -> "Circuit":
with io.StringIO(string) as s:
return _parser.convert_to_circuit(s)

@staticmethod
def from_aig_file(file_path: str) -> "Circuit":
"""
Initialize the circuit from an AIG format file.

Supports both ASCII (.aag) and binary (.aig) AIGER formats. Only combinational
circuits (without latches) are supported.

:param file_path: path to the .aag or .aig file.
:return: parsed Circuit object.

"""
from cirbo.core.parser.aig import AIGParser

parser = AIGParser()
return parser.parse_file(file_path)

@staticmethod
def from_aig_string(string: str) -> "Circuit":
"""
Initialize the circuit from an AIG format string.

Only ASCII AIG format (.aag) is supported for string input. Only combinational
circuits (without latches) are supported.

:param string: string containing AIG data in ASCII format.
:return: parsed Circuit object.

"""
from cirbo.core.parser.aig import AIGParser

parser = AIGParser()
return parser.parse_string(string)

@staticmethod
def from_aig_bytes(data: bytes) -> "Circuit":
"""
Initialize the circuit from AIG format bytes.

Supports both ASCII (.aag) and binary (.aig) AIGER formats. Only combinational
circuits (without latches) are supported.

:param data: bytes containing AIG data.
:return: parsed Circuit object.

"""
from cirbo.core.parser.aig import AIGParser

parser = AIGParser()
return parser.parse_bytes(data)
Comment on lines +219 to +251
Copy link
Collaborator

Choose a reason for hiding this comment

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

Минорно: правда ли на уровне парсера (и схемы соотв.) должны быть разные методы parse_bytes и parse_string, если это можно простой проверкой isinstance вывести динамически? Отдельный parse_file нужен чтобы отличить строку с путём от строки с данными


@staticmethod
def bare_circuit_with_labels(
labels: tp.Sequence[gate.Label],
Expand Down
6 changes: 6 additions & 0 deletions cirbo/core/parser/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Parser modules for circuit file formats."""

from cirbo.core.parser.aig import AIGParser
from cirbo.core.parser.bench import BenchToCircuit

__all__ = ['AIGParser', 'BenchToCircuit']
Loading