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
0d416661
Commit
0d416661
authored
5 years ago
by
David Hendriks
Browse files
Options
Downloads
Plain Diff
Merge branch 'population' of gitlab.eps.surrey.ac.uk:ri0005/binary_c-python into population
parents
1af889bd
22049a49
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
binarycpython/utils/grid.py
+46
-3
46 additions, 3 deletions
binarycpython/utils/grid.py
binarycpython/utils/grid_options_defaults.py
+3
-3
3 additions, 3 deletions
binarycpython/utils/grid_options_defaults.py
tests/population/grid_tests.py
+11
-11
11 additions, 11 deletions
tests/population/grid_tests.py
with
60 additions
and
17 deletions
binarycpython/utils/grid.py
+
46
−
3
View file @
0d416661
...
@@ -39,6 +39,7 @@ from binarycpython.utils.functions import get_defaults, parse_binary_c_version_i
...
@@ -39,6 +39,7 @@ from binarycpython.utils.functions import get_defaults, parse_binary_c_version_i
# TODO: add functionality to return the nuclear_mass_list
# TODO: add functionality to return the nuclear_mass_list
# TODO: add functionality to return the source_list
# TODO: add functionality to return the source_list
# TODO: add functionality to return the ensemble_list
# TODO: add functionality to return the ensemble_list
# TODO: change the grid_options dict structure so that there is room for descriptions
# DONE: add verbosity options
# DONE: add verbosity options
# DONE: add functionality to return the evcode_version_string
# DONE: add functionality to return the evcode_version_string
...
@@ -778,6 +779,8 @@ class Population(object):
...
@@ -778,6 +779,8 @@ class Population(object):
#######################
#######################
# MP run
# MP run
self
.
grid_options
[
'
probtot
'
]
=
0
# To make sure that the values are reset. TODO: fix this in a cleaner way
self
.
grid_options
[
'
probtot
'
]
=
0
# To make sure that the values are reset. TODO: fix this in a cleaner way
self
.
grid_options
[
'
start_time_grid
'
]
=
time
.
time
()
# Setting start time of grid
start_mp
=
time
.
time
()
start_mp
=
time
.
time
()
...
@@ -785,6 +788,7 @@ class Population(object):
...
@@ -785,6 +788,7 @@ class Population(object):
self
.
load_grid_function
()
self
.
load_grid_function
()
# def evolve_system(binary_cmdline_string):
def
evolve_system
(
binary_cmdline_string
):
def
evolve_system
(
binary_cmdline_string
):
out
=
binary_c_python_api
.
run_population
(
out
=
binary_c_python_api
.
run_population
(
binary_cmdline_string
,
binary_cmdline_string
,
...
@@ -800,9 +804,11 @@ class Population(object):
...
@@ -800,9 +804,11 @@ class Population(object):
full_system_dict
.
update
(
system
)
full_system_dict
.
update
(
system
)
binary_cmdline_string
=
self
.
return_argline
(
full_system_dict
)
binary_cmdline_string
=
self
.
return_argline
(
full_system_dict
)
print
(
"
{}/{}
"
.
format
(
i
+
1
,
total_starcount_run
),
binary_cmdline_string
)
self
.
print_info
(
i
+
1
,
total_starcount_run
,
full_system_dict
)
# print("{}/{}".format(i+1, total_starcount_run), binary_cmdline_string)
yield
binary_cmdline_string
yield
binary_cmdline_string
# yield i
print
(
"
generator done
"
)
print
(
"
generator done
"
)
# Create pool
# Create pool
...
@@ -812,11 +818,13 @@ class Population(object):
...
@@ -812,11 +818,13 @@ class Population(object):
# TODO: calculate the chunksize value based on: total starcount and cores used.
# TODO: calculate the chunksize value based on: total starcount and cores used.
r
=
list
(
p
.
imap_unordered
(
evolve_system
,
yield_system
(),
chunksize
=
20
))
r
=
list
(
p
.
imap_unordered
(
evolve_system
,
yield_system
(),
chunksize
=
20
))
# Handle clean termination of the whole multiprocessing
# Handle clean termination of the whole multiprocessing
(making sure there are no zombie processes (https://en.wikipedia.org/wiki/Zombie_process))
p
.
close
()
p
.
close
()
p
.
join
()
p
.
join
()
stop_mp
=
time
.
time
()
stop_mp
=
time
.
time
()
self
.
grid_options
[
'
start_time_grid
'
]
=
0
# Give feedback
# Give feedback
print
(
print
(
...
@@ -1422,4 +1430,39 @@ class Population(object):
...
@@ -1422,4 +1430,39 @@ class Population(object):
raise
KeyError
raise
KeyError
def
print_info
(
self
,
run_number
,
total_systems
,
full_system_dict
):
"""
Function to print info about the current system and the progress of the grid.
# color info tricks from https://ozzmaker.com/add-colour-to-text-in-python/
https://stackoverflow.com/questions/287871/how-to-print-colored-text-in-terminal-in-python
"""
# Define frequency
if
self
.
grid_options
[
'
verbose
'
]
==
1
:
print_freq
=
10
else
:
print_freq
=
1
# Calculate amount of time left
# calculate amount of time passed
time_passed
=
time
.
time
()
-
self
.
grid_options
[
'
start_time_grid
'
]
if
run_number
%
print_freq
==
0
:
binary_cmdline_string
=
self
.
return_argline
(
full_system_dict
)
info_string
=
"
{color_part_1} {text_part_1}{end_part_1}{color_part_2} {text_part_2}{end_part_2}
"
.
format
(
color_part_1
=
"
\033
[1;32;41m
"
,
text_part_1
=
"
{}/{}
"
.
format
(
run_number
,
total_systems
),
end_part_1
=
"
\033
[0m
"
,
color_part_2
=
"
\033
[1;32;42m
"
,
text_part_2
=
"
{}
"
.
format
(
binary_cmdline_string
),
end_part_2
=
"
\033
[0m
"
,
)
print
(
info_string
)
################################################################################################
################################################################################################
This diff is collapsed.
Click to expand it.
binarycpython/utils/grid_options_defaults.py
+
3
−
3
View file @
0d416661
...
@@ -40,12 +40,12 @@ grid_options_defaults_dict = {
...
@@ -40,12 +40,12 @@ grid_options_defaults_dict = {
# binary
# binary
"
binary
"
:
0
,
"
binary
"
:
0
,
# Locations:
# Locations:
"
tmp_dir
"
:
temp_dir
(),
"
tmp_dir
"
:
temp_dir
(),
# Setting the temp dir of the program
# Probability:
# Probability:
"
weight
"
:
1.0
,
# weighting for the probability
"
weight
"
:
1.0
,
# weighting for the probability
"
repeat
"
:
1.0
,
# number of times to repeat each system (probability is adjusted to be 1/repeat)
"
repeat
"
:
1.0
,
# number of times to repeat each system (probability is adjusted to be 1/repeat)
"
parse_function
"
:
None
,
"
parse_function
"
:
None
,
#
"
start_time_grid
"
:
0
,
# Start time of the grid
##
##
# return_array_refs=>1, # quicker data parsing mode
# return_array_refs=>1, # quicker data parsing mode
# sort_args=>1,
# sort_args=>1,
...
...
This diff is collapsed.
Click to expand it.
tests/population/grid_tests.py
+
11
−
11
View file @
0d416661
...
@@ -294,19 +294,21 @@ test_pop.set(verbose=1,
...
@@ -294,19 +294,21 @@ test_pop.set(verbose=1,
binary
=
0
,
binary
=
0
,
)
)
resolution
=
{
'
M_1
'
:
10
,
'
per
'
:
10
}
test_pop
.
add_grid_variable
(
test_pop
.
add_grid_variable
(
name
=
"
M_1
"
,
name
=
"
M_1
"
,
longname
=
"
log primary mass
"
,
longname
=
"
log primary mass
"
,
valuerange
=
[
10
,
100
],
valuerange
=
[
10
,
100
],
resolution
=
"
20
"
,
resolution
=
"
{}
"
.
format
(
resolution
[
'
M_1
'
]),
spacingfunc
=
"
const(10, 100, 20)
"
,
spacingfunc
=
"
const(10, 100, {})
"
.
format
(
resolution
[
'
M_1
'
]),
precode
=
""
,
# precode="M_1=math.exp(lnm1)",
# precode="M_1=math.exp(lnm1)",
probdist
=
"
flat(M_1)
"
,
probdist
=
"
flat(M_1)
"
,
# probdist='self.custom_options["extra_prob_function"](M_1)',
# probdist='self.custom_options["extra_prob_function"](M_1)',
dphasevol
=
"
dM_1
"
,
dphasevol
=
"
dM_1
"
,
parameter_name
=
"
M_1
"
,
parameter_name
=
"
M_1
"
,
condition
=
""
,
)
)
### Grid generating test.
### Grid generating test.
...
@@ -314,8 +316,8 @@ test_pop.add_grid_variable(
...
@@ -314,8 +316,8 @@ test_pop.add_grid_variable(
name
=
"
period
"
,
name
=
"
period
"
,
longname
=
"
period
"
,
longname
=
"
period
"
,
valuerange
=
[
"
M_1
"
,
20
],
valuerange
=
[
"
M_1
"
,
20
],
resolution
=
"
20
"
,
resolution
=
"
{}
"
.
format
(
resolution
[
'
per
'
])
,
spacingfunc
=
"
np.linspace(1, 10,
20)
"
,
spacingfunc
=
"
np.linspace(1, 10,
{})
"
.
format
(
resolution
[
'
per
'
])
,
precode
=
"
orbital_period = period**2
"
,
precode
=
"
orbital_period = period**2
"
,
probdist
=
"
flat(orbital_period)
"
,
probdist
=
"
flat(orbital_period)
"
,
parameter_name
=
"
orbital_period
"
,
parameter_name
=
"
orbital_period
"
,
...
@@ -324,12 +326,10 @@ test_pop.add_grid_variable(
...
@@ -324,12 +326,10 @@ test_pop.add_grid_variable(
)
)
test_pop
.
set
(
verbose
=
1
,
test_pop
.
set
(
verbose
=
1
,
amt_cores
=
4
,
amt_cores
=
1
,
binary
=
0
,
binary
=
0
,
)
)
test_pop
.
test_evolve_population_mp
()
# test_pop.test_evolve_population_mp()
test_pop
.
evolve_population_mp_chunks
()
# print(test_pop.grid_options["probtot"])
# print(test_pop.grid_options["count"])
\ 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