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
a5ba3a3d
Commit
a5ba3a3d
authored
5 years ago
by
David Hendriks
Browse files
Options
Downloads
Patches
Plain Diff
added some tests
parent
3bc0755e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/population/grid_tests.py
+124
-94
124 additions, 94 deletions
tests/population/grid_tests.py
with
124 additions
and
94 deletions
tests/population/grid_tests.py
+
124
−
94
View file @
a5ba3a3d
...
@@ -61,32 +61,32 @@ test_pop.set(
...
@@ -61,32 +61,32 @@ test_pop.set(
## Custom logging with bigger print statement:
## Custom logging with bigger print statement:
test_pop
.
set
(
M_1
=
100
,
M_2
=
1
,
metallicity
=
0.0002
,
orbital_period
=
500000000
)
#
test_pop.set(M_1=100, M_2=1, metallicity=0.0002, orbital_period=500000000)
test_pop
.
set
(
#
test_pop.set(
C_logging_code
=
"""
#
C_logging_code="""
if(stardata->star[0].stellar_type>=MS)
#
if(stardata->star[0].stellar_type>=MS)
{
#
{
if (stardata->model.time < stardata->model.max_evolution_time)
#
if (stardata->model.time < stardata->model.max_evolution_time)
{
#
{
Printf(
"
DAVID_SCO %30.12e %g %g %g %g %d %d
\\
n
"
,
#
Printf("DAVID_SCO %30.12e %g %g %g %g %d %d\\n",
//
#
//
stardata->model.time, // 1
#
stardata->model.time, // 1
stardata->star[0].mass, //2
#
stardata->star[0].mass, //2
stardata->previous_stardata->star[0].mass, //3
#
stardata->previous_stardata->star[0].mass, //3
stardata->star[0].radius, //4
#
stardata->star[0].radius, //4
stardata->previous_stardata->star[0].radius, //5
#
stardata->previous_stardata->star[0].radius, //5
stardata->star[0].stellar_type, //6
#
stardata->star[0].stellar_type, //6
stardata->previous_stardata->star[0].stellar_type //7
#
stardata->previous_stardata->star[0].stellar_type //7
);
#
);
};
#
};
/* Kill the simulation to save time */
#
/* Kill the simulation to save time */
// stardata->model.max_evolution_time = stardata->model.time - stardata->model.dtm;
#
// stardata->model.max_evolution_time = stardata->model.time - stardata->model.dtm;
};
#
};
"""
#
"""
)
#
)
# test_pop.evolve_population()
# test_pop.evolve_population()
...
@@ -103,74 +103,73 @@ test_pop.set(
...
@@ -103,74 +103,73 @@ test_pop.set(
################# Parse function
################# Parse function
## Testing some stuff out with giving a parse_function.
## Testing some stuff out with giving a parse_function.
test_pop
.
set
(
# test_pop.set(
C_logging_code
=
"""
# C_logging_code="""
if(stardata->star[0].stellar_type>=NS)
# if(stardata->star[0].stellar_type>=NS)
{
# {
if (stardata->model.time < stardata->model.max_evolution_time)
# if (stardata->model.time < stardata->model.max_evolution_time)
{
# {
Printf(
"
DAVID_SCO %30.12e %g %g %g %g %d %d
\\
n
"
,
# Printf("DAVID_SCO %30.12e %g %g %g %g %d %d\\n",
//
# //
stardata->model.time, // 1
# stardata->model.time, // 1
stardata->star[0].mass, //2
# stardata->star[0].mass, //2
stardata->previous_stardata->star[0].mass, //3
# stardata->previous_stardata->star[0].mass, //3
stardata->star[0].radius, //4
# stardata->star[0].radius, //4
stardata->previous_stardata->star[0].radius, //5
# stardata->previous_stardata->star[0].radius, //5
stardata->star[0].stellar_type, //6
# stardata->star[0].stellar_type, //6
stardata->previous_stardata->star[0].stellar_type //7
# stardata->previous_stardata->star[0].stellar_type //7
);
# );
};
# };
/* Kill the simulation to save time */
# /* Kill the simulation to save time */
stardata->model.max_evolution_time = stardata->model.time - stardata->model.dtm;
# stardata->model.max_evolution_time = stardata->model.time - stardata->model.dtm;
};
# };
"""
# """
)
# )
# def output_lines(output):
def
output_lines
(
output
):
# """
"""
# Function that outputs the lines that were recieved from the binary_c run.
Function that outputs the lines that were recieved from the binary_c run.
# """
"""
# return output.splitlines()
return
output
.
splitlines
()
# def parse_function(self, output):
def
parse_function
(
self
,
output
):
# # extract info from the population instance
# extract info from the population instance
# # TODO: think about whether this is smart. Passing around this object might be an overkill
# TODO: think about whether this is smart. Passing around this object might be an overkill
# # Get some information from the
# Get some information from the
# data_dir = self.custom_options['data_dir']
data_dir
=
self
.
custom_options
[
'
data_dir
'
]
# base_filename = self.custom_options['base_filename']
base_filename
=
self
.
custom_options
[
'
base_filename
'
]
# outfilename = os.path.join(data_dir, base_filename)
outfilename
=
os
.
path
.
join
(
data_dir
,
base_filename
)
# # TODO: make population settings available in this function
# TODO: make population settings available in this function
# for el in output_lines(output):
for
el
in
output_lines
(
output
):
# headerline = el.split()[0]
headerline
=
el
.
split
()[
0
]
# if (headerline=='DAVID_SCO'):
if
(
headerline
==
'
DAVID_SCO
'
):
# parameters = ['time', 'mass_1', 'prev_mass_1', 'radius_1', 'prev_radius_1', 'stellar_type_1', 'prev_stellar_type_1']
parameters
=
[
'
time
'
,
'
mass_1
'
,
'
prev_mass_1
'
,
'
radius_1
'
,
'
prev_radius_1
'
,
'
stellar_type_1
'
,
'
prev_stellar_type_1
'
]
# values = el.split()[1:]
values
=
el
.
split
()[
1
:]
# seperator='\t'
seperator
=
'
\t
'
# if not os.path.exists(outfilename):
if
not
os
.
path
.
exists
(
outfilename
):
# with open(outfilename, 'w') as f:
with
open
(
outfilename
,
'
w
'
)
as
f
:
# f.write(seperator.join(parameters)+'\n')
f
.
write
(
seperator
.
join
(
parameters
)
+
'
\n
'
)
# with open(outfilename, 'a') as f:
with
open
(
outfilename
,
'
a
'
)
as
f
:
# f.write(seperator.join(values)+'\n')
f
.
write
(
seperator
.
join
(
values
)
+
'
\n
'
)
# #test_pop.evolve_single(parse_function)
#test_pop.evolve_single(parse_function)
# test_pop.set(M_1=90, data_dir=os.path.join(os.environ['BINARYC_DATA_ROOT'], 'testing_python'), base_filename='test_pop.dat')
test_pop
.
set
(
M_1
=
90
,
data_dir
=
os
.
path
.
join
(
os
.
environ
[
'
BINARYC_DATA_ROOT
'
],
'
testing_python
'
),
base_filename
=
'
test_pop.dat
'
)
# test_pop.evolve_single(parse_function)
test_pop
.
evolve_single
(
parse_function
)
# test_pop.set(M_1=80)
test_pop
.
set
(
M_1
=
80
)
# test_pop.evolve_single(parse_function)
test_pop
.
evolve_single
(
parse_function
)
# test_pop.set(M_1=70)
test_pop
.
set
(
M_1
=
70
)
# test_pop.evolve_single(parse_function)
test_pop
.
evolve_single
(
parse_function
)
# test_pop.set(M_1=60)
test_pop
.
set
(
M_1
=
60
)
# test_pop.evolve_single(parse_function)
test_pop
.
evolve_single
(
parse_function
)
##################
##################
## CHeck size of commands:
## CHeck size of commands:
...
@@ -203,3 +202,34 @@ test_pop.evolve_single(parse_function)
...
@@ -203,3 +202,34 @@ test_pop.evolve_single(parse_function)
# plt.savefig('sizes_for_commands.png')
# plt.savefig('sizes_for_commands.png')
# plt.show()
# plt.show()
### Grid generating test.
test_pop
.
add_grid_variable
(
name
=
'
lnm1
'
,
longname
=
'
log primary mass
'
,
valuerange
=
[
10
,
20
],
resolution
=
'
10
'
,
spacingfunc
=
'
const()
'
,
precode
=
'
m2=m1**2
'
,
probdist
=
'
flat()
'
,
dphasevol
=
''
,
parameter_name
=
'
M_1
'
,
condition
=
''
,
)
### Grid generating test.
test_pop
.
add_grid_variable
(
name
=
'
period
'
,
longname
=
'
period
'
,
valuerange
=
[
'
m1
'
,
20
],
resolution
=
'
10
'
,
spacingfunc
=
'
const()
'
,
precode
=
''
,
probdist
=
'
flat()
'
,
parameter_name
=
'
orbital_period
'
,
dphasevol
=
''
,
condition
=
''
,
)
test_pop
.
generate_grid_code
()
\ 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