Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B-ASIC - Better ASIC Toolbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Computer Engineering
B-ASIC - Better ASIC Toolbox
Merge requests
!208
Minor fixes
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Minor fixes
generatorchecking
into
master
Overview
0
Commits
3
Pipelines
3
Changes
1
Merged
Oscar Gustafsson
requested to merge
generatorchecking
into
master
2 years ago
Overview
0
Commits
3
Pipelines
3
Changes
1
Expand
0
0
Merge request reports
Viewing commit
d4b6da4d
Prev
Next
Show latest version
1 file
+
23
−
13
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
d4b6da4d
Add documentation
· d4b6da4d
Oscar Gustafsson
authored
2 years ago
b_asic/simulation.py
+
23
−
13
Options
@@ -35,6 +35,15 @@ class Simulation:
Use FastSimulation (from the C++ extension module) for a more effective
simulation when running many iterations.
Parameters
----------
sfg : SFG
The signal flow graph to simulate.
input_providers : list, optional
Input values, one list item per input. Each list item can be an array of values,
a callable taking a time index and returning the value, or a
number (constant input). If a value is not provided for an input, it will be 0.
"""
_sfg
:
SFG
@@ -50,23 +59,28 @@ class Simulation:
input_providers
:
Optional
[
Sequence
[
Optional
[
InputProvider
]]]
=
None
,
):
"""
Construct a Simulation of an SFG.
"""
self
.
_sfg
=
(
sfg
()
)
# Copy the SFG to make sure it's not modified from the outside.
# Copy the SFG to make sure it's not modified from the outside.
self
.
_sfg
=
sfg
()
self
.
_results
=
defaultdict
(
list
)
self
.
_delays
=
{}
self
.
_iteration
=
0
self
.
_input_functions
=
[
lambda
_
:
0
for
_
in
range
(
self
.
_sfg
.
input_count
)
]
self
.
_input_functions
=
[
lambda
_
:
0
for
_
in
range
(
self
.
_sfg
.
input_count
)]
self
.
_input_length
=
None
if
input_providers
is
not
None
:
self
.
set_inputs
(
input_providers
)
def
set_input
(
self
,
index
:
int
,
input_provider
:
InputProvider
)
->
None
:
"""
Set the input
function
used to get values for the specific input at the
Set the input used to get values for the specific input at the
given index to the internal SFG.
Parameters
----------
index : int
The input index.
input_provider : list, callable, or number
Can be an array of values, a callable taking a time index and returning the value, or a
number (constant input).
"""
if
index
<
0
or
index
>=
len
(
self
.
_input_functions
):
raise
IndexError
(
@@ -87,9 +101,7 @@ class Simulation:
)
self
.
_input_functions
[
index
]
=
lambda
n
:
input_provider
[
n
]
def
set_inputs
(
self
,
input_providers
:
Sequence
[
Optional
[
InputProvider
]]
)
->
None
:
def
set_inputs
(
self
,
input_providers
:
Sequence
[
Optional
[
InputProvider
]])
->
None
:
"""
Set the input functions used to get values for the inputs to the internal SFG.
"""
@@ -172,9 +184,7 @@ class Simulation:
"""
if
self
.
_input_length
is
None
:
raise
IndexError
(
"
Tried to run unlimited simulation
"
)
return
self
.
run_until
(
self
.
_input_length
,
save_results
,
bits_override
,
truncate
)
return
self
.
run_until
(
self
.
_input_length
,
save_results
,
bits_override
,
truncate
)
@property
def
iteration
(
self
)
->
int
:
Loading