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
Commits
10e312d6
Commit
10e312d6
authored
4 years ago
by
Jacob Wahlman
Browse files
Options
Downloads
Patches
Plain Diff
Added save and load of data structures, updated w/ requirement
parent
feab0166
No related branches found
Branches containing commit
No related tags found
2 merge requests
!33
Resolve "Load/Save SFG to file"
,
!27
Resolve "Load/Save SFG to file"
Pipeline
#13764
passed
4 years ago
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
b_asic/utils.py
+28
-6
28 additions, 6 deletions
b_asic/utils.py
setup.py
+2
-1
2 additions, 1 deletion
setup.py
test/test_load_save_structure.py
+1
-19
1 addition, 19 deletions
test/test_load_save_structure.py
with
31 additions
and
26 deletions
b_asic/utils.py
+
28
−
6
View file @
10e312d6
...
...
@@ -4,12 +4,14 @@ This module contains functions that are used as utilities by other modules or by
"""
from
typing
import
Optional
import
pickle
from
os
import
getcwd
,
path
from
b_asic
import
AbstractOperation
import
dill
# Used instead of pickle to support serializing lambda functions
def
save_structure
(
struct
:
AbstractOperation
,
path
:
Optional
[
str
]
=
None
)
->
str
:
def
save_structure
(
struct
:
AbstractOperation
,
_path
:
Optional
[
str
]
=
None
,
_name
:
Optional
[
str
]
=
None
)
->
str
:
"""
Saves the structure to a specific path using the pickle module.
Returns the path to the struct if save succeeds.
...
...
@@ -17,15 +19,35 @@ def save_structure(struct: AbstractOperation, path: Optional[str] = None) -> str
struct: The structure to save.
Keyword Arguments:
path: The path to which the structure will be saved.
_path: The path (str) to which the structure will be saved.
_name: The name (str) of the file to be saved. Only used if _path is not defined and is not None.
"""
pass
try
:
_name
=
_name
if
_name
is
not
None
else
f
"
{
struct
.
type_name
}
.pickle
"
if
_path
is
None
:
_path
=
path
.
join
(
getcwd
(),
_name
)
def
load_structure
(
path
:
str
)
->
AbstractOperation
:
print
(
_path
)
with
open
(
_path
,
"
wb
"
)
as
handle
:
dill
.
dump
(
struct
,
handle
,
protocol
=
dill
.
HIGHEST_PROTOCOL
)
except
Exception
as
e
:
print
(
"
Unexpected error occured while saving structure:
"
,
e
)
return
None
return
_path
def
load_structure
(
_path
:
str
)
->
AbstractOperation
:
"""
Saves the structure to a specific path using the pickle module.
Returns the struct that was loaded from the path.
Keyword Arguments:
path: The path to which the structure will be loaded from.
"""
pass
\ No newline at end of file
try
:
with
open
(
_path
,
"
rb
"
)
as
handle
:
return
dill
.
load
(
handle
)
except
Exception
as
e
:
print
(
"
Unexpected error occured while saving structure:
"
,
e
)
return
None
This diff is collapsed.
Click to expand it.
setup.py
+
2
−
1
View file @
10e312d6
...
...
@@ -71,7 +71,8 @@ setuptools.setup(
install_requires
=
[
"
pybind11>=2.3.0
"
,
"
numpy
"
,
"
install_qt_binding
"
"
install_qt_binding
"
,
"
dill>=0.3.1.1
"
],
packages
=
[
"
b_asic
"
],
ext_modules
=
[
CMakeExtension
(
"
b_asic
"
)],
...
...
This diff is collapsed.
Click to expand it.
test/test_load_save_structure.py
+
1
−
19
View file @
10e312d6
...
...
@@ -20,22 +20,4 @@ class TestSaveStructures:
_sfg
=
load_structure
(
path
)
assert
isinstance
(
_sfg
,
SFG
)
assert
sfg
.
components
==
_sfg
.
components
def
test_save_sfg_custom_path
(
self
,
large_operation_tree
):
sfg
=
SFG
(
outputs
=
[
Output
(
large_operation_tree
)])
path
=
save_structure
(
sfg
,
path
=
"
structures/test
"
)
assert
path
is
not
None
assert
isfile
(
path
)
def
test_load_sfg_custom_path
(
self
,
large_operation_tree
):
sfg
=
SFG
(
outputs
=
[
Output
(
large_operation_tree
)])
path
=
save_structure
(
sfg
,
path
=
"
structures/test
"
)
_sfg
=
load_structure
(
path
)
assert
isinstance
(
_sfg
,
SFG
)
assert
sfg
.
components
==
_sfg
.
components
assert
sfg
.
evaluate
()
==
_sfg
.
evaluate
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment