Source code for Circuit.Circuit
1"""Abstract base class for FPGA circuit representations.
2
3Concrete subclasses (e.g. :class:`~Circuit.FileBasedCircuit.FileBasedCircuit`)
4implement compilation, bitstream access, and file-attribute storage for a
5specific hardware format.
6"""
7
8from abc import ABC, abstractmethod
9from pathlib import Path
10
11from BitstreamEvolutionProtocols import FPGA_Compilation_Data
12from Logger import Logger
13from returns.result import Result # type: ignore
14
[docs]
15class Circuit(ABC):
[docs]
16 def __repr__(self):
17 """
18 Returns the string representation of this Circuit, used in
19 functions such as 'print'.
20
21 Returns
22 -------
23 str
24 A string representation of the Circuit. (the file name)
25 """
26 return self._filename
27
28 def __init__(self, index: int, filename: str, logger: Logger):
29 self._filename = filename
30 self._index = index
31 self._logger = logger
32
[docs]
33 @abstractmethod
34 def compile(self, fpga: FPGA_Compilation_Data) -> Result[None,Exception]:
35 """
36 Performs the upload function of this Circuit. Prerequisite to collecting data
37 """
38 pass
39
[docs]
40 @abstractmethod
41 def get_bitstream(self) -> list[bool]:
42 """
43 Returns the full bitstream of the circuit
44 """
45 pass
46
[docs]
47 @abstractmethod
48 def set_bitstream(self, bitstream: list[bool]):
49 """
50 Sets the bitstream of the circuit
51 """
52 pass
53
54 def set_file_attribute(self, attribute, value):
55 pass # No default behavior
56
57 def get_file_attribute(self, attribute) -> str | None:
58 return '0' # No default behavior
59
[docs]
60 @abstractmethod
61 def copy_from(self, other):
62 """
63 Fully copy the bitstream from the other circuit
64
65 Parameters
66 ----------
67 other : Circuit
68 The other circuit to copy the bitstream from
69 """
70 pass