wavekit 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
wavekit-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Microsoft Corporation.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE
wavekit-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,63 @@
1
+ Metadata-Version: 2.1
2
+ Name: wavekit
3
+ Version: 0.1.0
4
+ Summary:
5
+ Author: cxzzzz
6
+ Author-email: cxz19961010@outlook.com
7
+ Requires-Python: >=3.9,<4.0
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.9
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Requires-Dist: numpy (>=2.0.0,<3.0.0)
15
+ Requires-Dist: pytest (>=8.2.2,<9.0.0)
16
+ Requires-Dist: vcdvcd (>=2.3.5,<3.0.0)
17
+ Description-Content-Type: text/markdown
18
+
19
+ # wavekit
20
+
21
+ This is a Python library for manipulating and analyzing digital circuit waveforms. The library provides tools to read, process, and perform various operations on waveform data, suitable for various digital circuit simulation and testing scenarios.
22
+
23
+ ## Features
24
+ * Read various waveform file formats (e.g., VCD, FSDB, etc.)
25
+ * Batch extraction of waveforms using absolute paths, brace expansions and regular expressions
26
+ * Perform arithmetic operations, bitwise operations, functional operations and other operators on waveform data
27
+
28
+ ## Installation
29
+
30
+ ### Using pip
31
+ You can install the library using pip:
32
+
33
+ ``` bash
34
+ pip install wavekit
35
+ ```
36
+
37
+ ### From Source
38
+ To install the library from the source, follow these steps:
39
+
40
+ Clone the repository:
41
+
42
+ ```bash
43
+ git clone https://github.com/cxzzzz/wavekit.git
44
+ ```
45
+
46
+ Navigate to the project directory:
47
+ ``` bash
48
+ cd wavekit
49
+ ```
50
+ Install the library using pip:
51
+
52
+ ``` bash
53
+ pip install .
54
+ ```
55
+
56
+ ## Quick Start
57
+ Here is a simple example demonstrating how to use the library to read a VCD file and perform some operations on the waveform data:
58
+
59
+ ``` python
60
+ ```
61
+
62
+ ## License
63
+ This project is licensed under the MIT License. See the [LICENSE] file for details.
@@ -0,0 +1,45 @@
1
+ # wavekit
2
+
3
+ This is a Python library for manipulating and analyzing digital circuit waveforms. The library provides tools to read, process, and perform various operations on waveform data, suitable for various digital circuit simulation and testing scenarios.
4
+
5
+ ## Features
6
+ * Read various waveform file formats (e.g., VCD, FSDB, etc.)
7
+ * Batch extraction of waveforms using absolute paths, brace expansions and regular expressions
8
+ * Perform arithmetic operations, bitwise operations, functional operations and other operators on waveform data
9
+
10
+ ## Installation
11
+
12
+ ### Using pip
13
+ You can install the library using pip:
14
+
15
+ ``` bash
16
+ pip install wavekit
17
+ ```
18
+
19
+ ### From Source
20
+ To install the library from the source, follow these steps:
21
+
22
+ Clone the repository:
23
+
24
+ ```bash
25
+ git clone https://github.com/cxzzzz/wavekit.git
26
+ ```
27
+
28
+ Navigate to the project directory:
29
+ ``` bash
30
+ cd wavekit
31
+ ```
32
+ Install the library using pip:
33
+
34
+ ``` bash
35
+ pip install .
36
+ ```
37
+
38
+ ## Quick Start
39
+ Here is a simple example demonstrating how to use the library to read a VCD file and perform some operations on the waveform data:
40
+
41
+ ``` python
42
+ ```
43
+
44
+ ## License
45
+ This project is licensed under the MIT License. See the [LICENSE] file for details.
wavekit-0.1.0/build.py ADDED
@@ -0,0 +1,54 @@
1
+ # setup.py
2
+
3
+ from setuptools import setup, Extension, find_packages
4
+ from Cython.Build import cythonize
5
+ import numpy as np
6
+ import os
7
+
8
+ extensions = [
9
+ Extension(
10
+ "src.wavekit.value_change",
11
+ sources=["src/wavekit/value_change.pyx", ],
12
+ include_dirs=[np.get_include()],
13
+ extra_compile_args=["-fpic","-O3", "-march=native"],
14
+ extra_link_args=["-O3", "-march=native"],
15
+ language="c++",
16
+ #define_macros=[('CYTHON_TRACE', '1')] # open profiling
17
+ )
18
+ ]
19
+
20
+ if VERDI_HOME := os.environ.get('VERDI_HOME'):
21
+
22
+ npi_include_dir = os.path.join(VERDI_HOME,'share/NPI/inc')
23
+ npi_library_dir = os.path.join(VERDI_HOME,'share/NPI/lib/LINUX64')
24
+
25
+ extensions = [
26
+ Extension(
27
+ "src.wavekit.npi_fsdb_reader",
28
+ sources=["src/wavekit/npi_fsdb_reader.pyx", ],
29
+ include_dirs=[np.get_include(), npi_include_dir],
30
+ library_dirs=[npi_library_dir],
31
+ libraries=["NPI"],
32
+ extra_compile_args=["-fpic","-O3", "-march=native"],
33
+ extra_link_args=["-O3", "-march=native",f"-Wl,-rpath,{npi_library_dir}"],
34
+ language="c++",
35
+ #define_macros=[('CYTHON_TRACE', '1')] # open profiling
36
+ )
37
+ ]
38
+
39
+
40
+ setup(
41
+ ext_modules=cythonize(extensions,
42
+ compiler_directives={
43
+ "language_level": 3,
44
+ "embedsignature": True,
45
+ "boundscheck": False,
46
+ "wraparound": False,
47
+ "cdivision": True,
48
+ "nonecheck": False,
49
+ #'profile': True, # open profiling
50
+ #'linetrace': True
51
+ }
52
+ ),
53
+ script_args=['build_ext','--inplace'],
54
+ )
@@ -0,0 +1,18 @@
1
+ [tool.poetry]
2
+ name = "wavekit"
3
+ version = "0.1.0"
4
+ description = ""
5
+ authors = ["cxzzzz <cxz19961010@outlook.com>"]
6
+ readme = "README.md"
7
+ build = "build.py"
8
+ include = ["src/wavekit/*.so"]
9
+
10
+ [tool.poetry.dependencies]
11
+ python = "^3.9"
12
+ numpy = "^2.0.0"
13
+ vcdvcd = "^2.3.5"
14
+ pytest = "^8.2.2"
15
+
16
+ [build-system]
17
+ requires = ["poetry-core", "Cython", "setuptools", "wheel", "numpy>=2.0.0"]
18
+ build-backend = "poetry.core.masonry.api"
@@ -0,0 +1,15 @@
1
+ # -------------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # Licensed under the MIT License. See LICENSE in project root for information.
4
+ # -------------------------------------------------------------
5
+ """Python Package Template"""
6
+ from __future__ import annotations
7
+
8
+ __version__ = "0.0.1"
9
+
10
+ from .waveform import Waveform
11
+ from .vcd_reader import VcdReader
12
+ try:
13
+ from .fsdb_reader import FsdbReader
14
+ except ImportError:
15
+ pass
@@ -0,0 +1,125 @@
1
+ from __future__ import annotations
2
+ import importlib
3
+ from collections import defaultdict
4
+ from typing import Optional
5
+ from functools import cached_property
6
+ from .waveform import Waveform
7
+ from .reader import Reader, Scope
8
+ from .npi_fsdb_reader import NpiFsdbReader, NpiFsdbScope
9
+
10
+ class FsdbScope(Scope):
11
+
12
+ def __init__(self, handle: NpiFsdbScope, parent_scope: FsdbScope):
13
+ super().__init__(name=handle.name())
14
+ self.handle = handle
15
+ self.parent_scope = parent_scope
16
+
17
+ @cached_property
18
+ def signal_list(self) -> list[str]:
19
+ return [s for s in self.handle.signal_list()]
20
+
21
+ @cached_property
22
+ def child_scope_list(self) -> list[FsdbScope]:
23
+ return [FsdbScope(c, self) for c in self.handle.child_scope_list()]
24
+
25
+ @property
26
+ def type(self) -> str:
27
+ if not hasattr(self, '_type'):
28
+ self._type = self.handle.type()
29
+ return self._type
30
+
31
+ @property
32
+ def def_name(self) -> Optional[str]:
33
+ if not hasattr(self, '_def_name'):
34
+ self._def_name = self.handle.def_name()
35
+ return self._def_name
36
+
37
+ def find_scope_by_module(self, module_name: str, depth: int = 0) -> list[Scope]:
38
+ if not hasattr(self, '_preloaded_module_scope'):
39
+ self.preload_module_scope()
40
+ return self._preloaded_module_scope[module_name]
41
+
42
+ def preload_module_scope(self):
43
+ preloaded_module_scope = defaultdict(list)
44
+ for c in self.child_scope_list:
45
+ for module_name, module_scope_list in c.preload_module_scope().items():
46
+ preloaded_module_scope[module_name].extend(module_scope_list)
47
+
48
+ if self.type == 'npiFsdbScopeSvModule':
49
+ #assert self.def_name not in preloaded_module_scope , (self.def_name, preloaded_module_scope)
50
+ preloaded_module_scope[self.def_name].append(self)
51
+ self._preloaded_module_scope = preloaded_module_scope
52
+ return preloaded_module_scope
53
+
54
+ class FsdbReader(Reader):
55
+
56
+ pynpi = {}
57
+
58
+ def __init__(self, file: str):
59
+ super().__init__()
60
+
61
+ if len(FsdbReader.pynpi) == 0:
62
+ import sys
63
+ import os
64
+ rel_lib_path = os.environ["VERDI_HOME"] + "/share/NPI/python"
65
+ sys.path.append(os.path.abspath(rel_lib_path))
66
+ FsdbReader.pynpi['npisys'] = importlib.import_module(
67
+ "pynpi.npisys")
68
+ FsdbReader.pynpi['waveform'] = importlib.import_module(
69
+ "pynpi.waveform")
70
+ FsdbReader.pynpi['npisys'].init([''])
71
+
72
+ self.file = file
73
+ self.file_handle = NpiFsdbReader(file)
74
+
75
+ def load_wave(
76
+ self,
77
+ signal: str,
78
+ clock: str,
79
+ xz_value: int = 0,
80
+ signed: bool = False,
81
+ sample_on_posedge: bool = False,
82
+ begin_time: Optional[str] = None,
83
+ end_time: Optional[str] = None,
84
+ ) -> Waveform:
85
+
86
+ format = FsdbReader.pynpi['waveform'].VctFormat_e.BinStrVal
87
+ begin_time = begin_time or 0
88
+ end_time = end_time or 2**64-1
89
+
90
+ signal_value_change = self.file_handle.load_value_change(signal,
91
+ begin_time = begin_time,
92
+ end_time = end_time,
93
+ xz_value = xz_value
94
+ )
95
+
96
+ clock_value_change = self.file_handle.load_value_change(clock,
97
+ begin_time = begin_time,
98
+ end_time = end_time,
99
+ xz_value = 0
100
+ )
101
+
102
+ return self.value_change_to_waveform(
103
+ signal_value_change,
104
+ clock_value_change,
105
+ width=self.file_handle.get_signal_width(signal),
106
+ signed=signed,
107
+ sample_on_posedge=sample_on_posedge,
108
+ signal=signal
109
+ )
110
+
111
+ def top_scope_list(self) -> list[Scope]:
112
+ if not hasattr(self, "_top_scope_list"):
113
+ self._top_scope_list = [FsdbScope(s, None) for s in self.file_handle.top_scope_list()]
114
+ return self._top_scope_list
115
+
116
+ @property
117
+ def begin_time(self) -> str:
118
+ return self.file_handle.min_time()
119
+
120
+ @property
121
+ def end_time(self) -> str:
122
+ return self.file_handle.max_time()
123
+
124
+ def close(self):
125
+ self.file_handle.close()
@@ -0,0 +1,115 @@
1
+
2
+ cdef extern from "npi.h":
3
+ cdef int npi_init(int argc, char** argv)
4
+ cdef int npi_end()
5
+ cdef int npi_load_design(int argc, char** argv)
6
+
7
+ cdef extern from "npi_fsdb.h":
8
+
9
+ ctypedef unsigned long long NPI_UINT64
10
+ ctypedef long long NPI_INT64
11
+ ctypedef int NPI_INT32
12
+ ctypedef unsigned int NPI_UINT32
13
+ ctypedef short NPI_INT16
14
+ ctypedef unsigned short NPI_UINT16
15
+ ctypedef char NPI_BYTE8
16
+ ctypedef unsigned char NPI_UBYTE8
17
+
18
+ ctypedef void* npiFsdbFileHandle
19
+ ctypedef void* npiFsdbScopeHandle
20
+ ctypedef void* npiFsdbSigHandle
21
+ ctypedef void* npiFsdbSigdbHandle
22
+ ctypedef void* npiFsdbVctHandle
23
+ ctypedef void* npiFsdbFtHandle
24
+
25
+ ctypedef void* npiFsdbScopeIter
26
+ ctypedef void* npiFsdbSigIter
27
+ ctypedef void* npiFsdbEnumIter
28
+ ctypedef NPI_UINT64 npiFsdbTime
29
+
30
+ ctypedef enum npiFsdbValType:
31
+ npiFsdbBinStrVal
32
+ npiFsdbOctStrVal
33
+ npiFsdbDecStrVal
34
+ npiFsdbHexStrVal
35
+ npiFsdbSintVal
36
+ npiFsdbUintVal
37
+ npiFsdbRealVal
38
+ npiFsdbStringVal
39
+ npiFsdbEnumStrVal
40
+ npiFsdbSint64Val
41
+ npiFsdbUint64Val
42
+ npiFsdbObjTypeVal
43
+
44
+ ctypedef struct npiFsdbValueValue:
45
+ char* str
46
+ int sint
47
+ unsigned int uint
48
+ long long sint64
49
+ unsigned long long uint64
50
+ double real
51
+
52
+ ctypedef struct npiFsdbValue:
53
+ npiFsdbValType format
54
+ npiFsdbValueValue value
55
+ # union field
56
+
57
+ ctypedef enum npiFsdbSigPropertyType:
58
+ npiFsdbSigName
59
+ npiFsdbSigFullName
60
+ npiFsdbSigIsReal
61
+ npiFsdbSigHasMember
62
+ npiFsdbSigLeftRange
63
+ npiFsdbSigRightRange
64
+ npiFsdbSigRangeSize
65
+ npiFsdbSigIsString
66
+ npiFsdbSigDirection
67
+ npiFsdbSigAssertionType
68
+ npiFsdbSigCompositeType
69
+ npiFsdbSigIsPacked
70
+ npiFsdbSigHasReasonCode
71
+ npiFsdbSigReasonCode
72
+ npiFsdbSigReasonCodeDesc
73
+ npiFsdbSigIsParam
74
+ npiFsdbSigHasEnum
75
+ npiFsdbSigPowerType
76
+ npiFsdbSigHasForceTag
77
+ npiFsdbSigSpType
78
+ npiFsdbSigEnumId
79
+
80
+ ctypedef enum npiFsdbScopePropertyType:
81
+ npiFsdbScopeName
82
+ npiFsdbScopeFullName
83
+ npiFsdbScopeDefName
84
+ npiFsdbScopeType
85
+
86
+
87
+
88
+
89
+ npiFsdbFileHandle npi_fsdb_open( const NPI_BYTE8* name )
90
+ NPI_INT32 npi_fsdb_close( npiFsdbFileHandle file )
91
+ NPI_INT32 npi_fsdb_min_time( npiFsdbFileHandle file, npiFsdbTime *time )
92
+ NPI_INT32 npi_fsdb_max_time( npiFsdbFileHandle file, npiFsdbTime *time )
93
+ npiFsdbSigHandle npi_fsdb_sig_by_name( npiFsdbFileHandle file, const NPI_BYTE8* name, npiFsdbScopeHandle scope )
94
+ npiFsdbVctHandle npi_fsdb_create_vct( npiFsdbSigHandle sig )
95
+ NPI_INT32 npi_fsdb_goto_time( npiFsdbVctHandle vct, npiFsdbTime time )
96
+ NPI_INT32 npi_fsdb_goto_first( npiFsdbVctHandle vct )
97
+ NPI_INT32 npi_fsdb_goto_next( npiFsdbVctHandle vct )
98
+ NPI_INT32 npi_fsdb_goto_prev( npiFsdbVctHandle vct )
99
+
100
+ NPI_INT32 npi_fsdb_vct_time( npiFsdbVctHandle vct, npiFsdbTime *time )
101
+ NPI_INT32 npi_fsdb_vct_value( npiFsdbVctHandle vct, npiFsdbValue *value)
102
+ NPI_INT32 npi_fsdb_release_vct( npiFsdbVctHandle vct )
103
+ NPI_INT32 npi_fsdb_unload_vc( npiFsdbFileHandle file )
104
+
105
+ NPI_INT32 npi_fsdb_sig_property( npiFsdbSigPropertyType type, npiFsdbSigHandle sig, NPI_INT32* prop )
106
+ const NPI_BYTE8* npi_fsdb_sig_property_str( npiFsdbSigPropertyType type, npiFsdbSigHandle sig)
107
+ NPI_INT32 npi_fsdb_scope_property( npiFsdbScopePropertyType type, npiFsdbScopeHandle scope, NPI_INT32* prop )
108
+ const NPI_BYTE8* npi_fsdb_scope_property_str( npiFsdbScopePropertyType type, npiFsdbScopeHandle scope )
109
+
110
+ npiFsdbScopeIter npi_fsdb_iter_top_scope( npiFsdbFileHandle file )
111
+ npiFsdbScopeIter npi_fsdb_iter_child_scope( npiFsdbScopeHandle scope )
112
+ npiFsdbScopeHandle npi_fsdb_iter_scope_next( npiFsdbScopeIter iter )
113
+ npiFsdbSigHandle npi_fsdb_iter_sig_next( npiFsdbSigIter iter )
114
+ npiFsdbSigIter npi_fsdb_iter_sig( npiFsdbScopeHandle scope )
115
+ npiFsdbSigIter npi_fsdb_iter_member( npiFsdbSigHandle sig )