VA-File and VA-Code

VA Code structure. As Includes traverse like a tree, it is implemented as a dictionary Oo.

class DMT.core.va_file.VACode(code: str = '', code_compressed: tuple[str, int] = ('', -1), ignore_checksum: bool = False)[source]

Bases: object

Base file for VA-Codes

Parameters:
codestr, optional

Code of the file

code_compressed(str, int), optional

Compressed code as loaded from a json modelcard file.

ignore_checksum: bool, optional

If True, the checksum is ignored, defaults to False.

property code_compressed[source]

zlib compressed code for saving in modelcard json files.

Returns:
(str, str)

Compressed code and CRC32 check sum after compression and before encoding.

decompress_code(code_compressed: str, csum: int, ignore_checksum: bool = False)[source]

Set compressed code to file, will be decompressed and saved in self.code

Parameters:
code_compressedstr

compressed code

csumstr

CRC32 check sum loaded from file.

ignore_checksum: bool, optional

If True, the checksum is ignored, defaults to False.

Raises:
OSError

If the saved checksum and checksum of decompressed code do not match

class DMT.core.va_file.VAFileMap(name: str | Path, files: dict[str, VACode] | None = None, code: str | VACode = '', code_compressed: tuple[str, int] = ('', -1), ignore_checksum: bool = False)[source]

Bases: object

Mapping for VA-Code. The mapping data type is chosen to correctly use possible file structures of multi-file VA-Codes

Parameters:
nameUnion[str, Path]

Absolute or relative path to file or just name of the root file.

filesdict, optional

Dictionary with {file_name: VACode}. One of the keys must be the same as the name, by default None

codeUnion[str, VACode], optional

Code of the root file, by default “”

code_compressed(str, int), optional

Compressed code as loaded from a json modelcard file.

ignore_checksum: bool, optional

If True, the checksum is ignored, defaults to False.

export_dict(compressed_code: bool = False) dict[source]

Export self and children into a dictionary for serialization

Parameters:
compressed_codebool, optional

Set to true to get compressed code, by default False

Returns:
dict

[description]

get_tree_hash() str[source]

Create a hash for all the codes from this node and all its children. Should be unique for each model…

Returns:
str

MD5 Hash for the code of this file and all its children

classmethod import_dict(data_import: dict, ignore_checksum: bool = False) VAFileMap[source]

Imports a full VAFileMap from a (serialized) dictionary

Parameters:
data_importdict

[description]

ignore_checksum: bool, optional

If True, the checksum is ignored, defaults to False.

Returns:
VAFileMap

[description]

iter_codes()[source]

Iterate through all name:code items

read_structure(path_to_own_folder: str | Path)[source]

Checks the file for imports and adds them into the dict. This is done using verilogae.

Parameters:
path_to_own_folderUnion[str, Path]

Path, in which the main file of the model is located.

Raises:
NotImplementedError

Currently only relative imports are supported. If a file includes an absolute path, the error is raised.

rename_root(name_new: str)[source]

Rename the root file

Parameters:
name_newstr

New name

Raises:
IOError

If the new name already existed.

property root_vfs: str[source]

Returns the root path inside the vfs

Returns:
str

Path to the root file

property vfs: dict[str, str][source]

Virtual file system of this VAFileMap

The vfs is saved in a dictionary with {<path>: <file content>}

Returns:
dict[str, str]

The key is the path and the values are the file contents

write_files(path_to_target: str | Path, filter: Callable[[str], str] | None = None)[source]

Writes the all Verilog-A files from this mapping into the given target path. The file structure is written as read from the “original”

Parameters:
path_to_targetUnion[str, Path]

Path to target directory

filtercallable(), optional

Called with each code file as an argument. Can be used to filter out “non-compiling” additional code parts. For example to remove VAE language extensions (spectre):

lambda code: re.sub(r"\(\*.+\*\)", "", code)