Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
binary_c-python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
Izzard, Robert Dr (Maths & Physics)
binary_c-python
Commits
3fd1d856
Commit
3fd1d856
authored
4 years ago
by
David Hendriks
Browse files
Options
Downloads
Patches
Plain Diff
changed name of function
parent
cbcc519d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_persistent_data.py
+46
-10
46 additions, 10 deletions
tests/test_persistent_data.py
with
46 additions
and
10 deletions
tests/test_
return_
persistent_data
_memaddr
.py
→
tests/test_persistent_data.py
+
46
−
10
View file @
3fd1d856
...
...
@@ -8,12 +8,14 @@ import json
import
textwrap
import
binary_c_python_api
from
mergedict
import
ConfigDict
from
mergedict
import
MergeDict
class
SumDict
(
MergeDict
):
@MergeDict.dispatch
(
float
)
def
merge_float
(
this
,
other
):
return
this
+
other
# import unicode
class
Decoder
(
json
.
JSONDecoder
):
"""
...
...
@@ -47,6 +49,8 @@ class Decoder(json.JSONDecoder):
else
:
return
o
####
# Evolution functions
def
test_return_persistent_data_memaddr
():
output
=
binary_c_python_api
.
return_persistent_data_memaddr
(
""
)
...
...
@@ -132,6 +136,8 @@ def ensemble_output():
print
(
json
.
dumps
(
json_1
,
indent
=
4
))
print
(
"
took {}s to decode
"
.
format
(
stop
-
start
))
def
adding_ensemble_output
():
m1
=
2
# Msun
m2
=
0.1
# Msun
...
...
@@ -166,6 +172,9 @@ def adding_ensemble_output():
json_1
=
json
.
loads
(
ensemble_jsons_1
[
0
][
len
(
"
ENSEMBLE_JSON
"
):],
cls
=
Decoder
)
json_2
=
json
.
loads
(
ensemble_jsons_2
[
0
][
len
(
"
ENSEMBLE_JSON
"
):],
cls
=
Decoder
)
# test_1_total_dict = SumDict(json_1)
# test_1_total_dict.merge(json_2)
with
open
(
"
json_1.json
"
,
'
w
'
)
as
f
:
f
.
write
(
json
.
dumps
(
json_1
,
indent
=
4
))
with
open
(
"
json_2.json
"
,
'
w
'
)
as
f
:
...
...
@@ -267,14 +276,41 @@ def test_free_and_json_output():
print
(
textwrap
.
indent
(
str
(
json_output_by_freeing
),
"
\t
"
))
def
full_output
():
m1
=
15.0
# Msun
m2
=
14.0
# Msun
separation
=
0
# 0 = ignored, use period
orbital_period
=
453000000000.0
# days
eccentricity
=
0.0
metallicity
=
0.02
max_evolution_time
=
15000
argstring_1
=
"
binary_c M_1 {0:g} M_2 {1:g} separation {2:g} orbital_period {3:g} eccentricity {4:g} metallicity {5:g} max_evolution_time {6:g} ensemble 1 ensemble_defer 0
"
.
format
(
m1
,
m2
,
separation
,
orbital_period
,
eccentricity
,
metallicity
,
max_evolution_time
,
)
output_1
=
binary_c_python_api
.
run_system
(
argstring
=
argstring_1
)
ensemble_jsons_1
=
[
line
for
line
in
output_1
.
splitlines
()
if
line
.
startswith
(
"
ENSEMBLE_JSON
"
)]
start
=
time
.
time
()
json_1
=
json
.
loads
(
ensemble_jsons_1
[
0
][
len
(
"
ENSEMBLE_JSON
"
):],
cls
=
Decoder
)
stop
=
time
.
time
()
print
(
"
took {}s to decode
"
.
format
(
stop
-
start
))
with
open
(
"
json_full_ensemble.json
"
,
'
w
'
)
as
f
:
f
.
write
(
json
.
dumps
(
json_1
,
indent
=
4
))
####
if
__name__
==
"
__main__
"
:
# test_return_persistent_data_memaddr()
# test_passing_persistent_data_to_run_system()
# ensemble_output()
adding_ensemble_output
()
# test_free_and_json_output()
\ No newline at end of file
# adding_ensemble_output()
# test_free_and_json_output()
full_output
()
\ No newline at end of file
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