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
a502a03d
Commit
a502a03d
authored
5 years ago
by
David Hendriks
Browse files
Options
Downloads
Patches
Plain Diff
removed grid class functions that were not necessary anymore
parent
e303b591
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
binarycpython/utils/grid.py
+1
-236
1 addition, 236 deletions
binarycpython/utils/grid.py
with
1 addition
and
236 deletions
binarycpython/utils/grid.py
+
1
−
236
View file @
a502a03d
...
...
@@ -554,246 +554,11 @@ class Population(object):
pass
# TODO: add call to function that cleans up the temp customlogging dir, and unloads the loaded libraries.
def
evolve_population_comparison
(
self
,
parse_function
,
amt
,
nodes
,
custom_arg_file
=
None
):
"""
The function that will evolve the population. This function contains many steps
"""
### Custom logging code:
self
.
set_custom_logging
()
### Load store
self
.
grid_options
[
"
store_memaddr
"
]
=
binary_c_python_api
.
return_store
(
""
)
# Execute.
### Part to test running this with and without multiprocessing.
import
time
import
multiprocessing
as
mp
from
pathos.multiprocessing
import
ProcessingPool
as
Pool
import
random
start_no_mp
=
time
.
time
()
self
.
set
(
base_filename
=
"
no_mp_{}.dat
"
.
format
(
amt
))
# amt = 1000
masses
=
range
(
1
,
amt
+
1
)
for
i
in
masses
:
mass
=
random
.
randint
(
1
,
500
)
# print(mass)
self
.
set_bse_option
(
"
M_1
"
,
mass
)
out
=
binary_c_python_api
.
run_population
(
self
.
return_argline
(),
self
.
grid_options
[
"
custom_logging_func_memaddr
"
],
self
.
grid_options
[
"
store_memaddr
"
],
)
# parse_function(self, out)
stop_no_mp
=
time
.
time
()
print
(
"
without mp: {} systems took {}s
"
.
format
(
amt
,
stop_no_mp
-
start_no_mp
))
#########################################################
start_mp
=
time
.
time
()
self
.
set
(
base_filename
=
"
mp_{}.dat
"
.
format
(
amt
))
def
evolve_mp
(
mass
):
# print(mass)
self
.
set_bse_option
(
"
M_1
"
,
mass
)
# self.set(M_1=mass)
out
=
binary_c_python_api
.
run_population
(
self
.
return_argline
(),
self
.
grid_options
[
"
custom_logging_func_memaddr
"
],
self
.
grid_options
[
"
store_memaddr
"
],
)
# parse_function(self, out)
p
=
Pool
(
nodes
=
nodes
)
def
g
(
amt
):
# amt = 1000
masses
=
range
(
1
,
amt
+
1
)
for
i
in
masses
:
mass
=
random
.
randint
(
1
,
500
)
yield
mass
print
(
"
generator done
"
)
r
=
list
(
p
.
imap
(
evolve_mp
,
g
(
amt
)))
stop_mp
=
time
.
time
()
print
(
"
with mp: {} systems took {}s
"
.
format
(
amt
,
stop_mp
-
start_mp
))
#########################################################
duration_no_mp
=
stop_no_mp
-
start_no_mp
duration_mp
=
stop_mp
-
start_mp
ratio
=
duration_no_mp
/
duration_mp
print
(
"
Running mp versus no mp is {} times faster!
"
.
format
(
ratio
))
return
(
nodes
,
amt
,
duration_no_mp
,
duration_mp
,
ratio
)
def
evolve_population_mp
(
self
,
parse_function
,
mass_distribution
):
"""
The function that will evolve the population. This function contains many steps
"""
### Custom logging code:
self
.
set_custom_logging
()
### Load store
self
.
grid_options
[
"
store_memaddr
"
]
=
binary_c_python_api
.
return_store
(
""
)
# evolve with mp
start_mp
=
time
.
time
()
def
evolve_mp
(
mass
):
self
.
set_bse_option
(
"
M_1
"
,
mass
)
out
=
binary_c_python_api
.
run_population
(
self
.
return_argline
(),
self
.
grid_options
[
"
custom_logging_func_memaddr
"
],
self
.
grid_options
[
"
store_memaddr
"
],
)
parse_function
(
self
,
out
)
p
=
Pool
(
nodes
=
self
.
grid_options
[
"
amt_cores
"
])
def
g
(
mass_distribution
):
masses
=
mass_distribution
for
mass
in
masses
:
yield
mass
print
(
"
generator done
"
)
r
=
list
(
p
.
imap
(
evolve_mp
,
g
(
mass_distribution
)))
stop_mp
=
time
.
time
()
print
(
"
with mp: {} systems took {}s using {} cores
"
.
format
(
len
(
mass_distribution
),
stop_mp
-
start_mp
,
self
.
grid_options
[
"
amt_cores
"
],
)
)
# TODO: add functionality to unload all the stores etc
#########################################################
# print("Running mp versus no mp is {} times faster!".format((start_no_mp-stop_no_mp)/(start_mp-stop_mp)))
# return (nodes, amt, stop_no_mp-start_no_mp, stop_mp-start_mp)
###################################################
# Testing functions
###################################################
def
test_evolve_population
(
self
):
"""
The to test running a population
"""
import
time
import
multiprocessing
as
mp
from
pathos.multiprocessing
import
ProcessingPool
as
Pool
import
random
#######################
### Custom logging code:
self
.
set_custom_logging
()
### Load store
self
.
grid_options
[
"
store_memaddr
"
]
=
binary_c_python_api
.
return_store
(
""
)
#######################
# Dry run and getting starcount
self
.
grid_options
[
'
probtot
'
]
=
0
self
.
generate_grid_code
(
dry_run
=
True
)
self
.
load_grid_function
()
self
.
dry_run
()
total_starcount_run
=
self
.
grid_options
[
'
total_starcount
'
]
print
(
"
Total starcount for this run will be: {}
"
.
format
(
total_starcount_run
))
#######################
# Linear run
start_lin
=
time
.
time
()
self
.
grid_options
[
'
probtot
'
]
=
0
# To make sure that the values are reset. TODO: fix this in a cleaner way
self
.
generate_grid_code
(
dry_run
=
False
)
self
.
load_grid_function
()
for
i
,
system
in
enumerate
(
self
.
grid_options
[
"
system_generator
"
](
self
)):
full_system_dict
=
self
.
bse_options
.
copy
()
full_system_dict
.
update
(
system
)
binary_cmdline_string
=
self
.
return_argline
(
full_system_dict
)
out
=
binary_c_python_api
.
run_population
(
binary_cmdline_string
,
self
.
grid_options
[
"
custom_logging_func_memaddr
"
],
self
.
grid_options
[
"
store_memaddr
"
],
)
print
(
"
{}/{}
"
.
format
(
i
+
1
,
total_starcount_run
),
binary_cmdline_string
)
stop_lin
=
time
.
time
()
#######################
# MP run
self
.
grid_options
[
'
probtot
'
]
=
0
# To make sure that the values are reset. TODO: fix this in a cleaner way
start_mp
=
time
.
time
()
self
.
generate_grid_code
(
dry_run
=
False
)
self
.
load_grid_function
()
def
evolve_system
(
binary_cmdline_string
):
# print(binary_cmdline_string)
# pass
# print('next')
# self.set_bse_option("M_1", mass)
out
=
binary_c_python_api
.
run_population
(
binary_cmdline_string
,
self
.
grid_options
[
"
custom_logging_func_memaddr
"
],
self
.
grid_options
[
"
store_memaddr
"
],
)
# # parse_function(self, out)
def
yield_system
():
for
i
,
system
in
enumerate
(
self
.
grid_options
[
"
system_generator
"
](
self
)):
full_system_dict
=
self
.
bse_options
.
copy
()
full_system_dict
.
update
(
system
)
binary_cmdline_string
=
self
.
return_argline
(
full_system_dict
)
print
(
"
{}/{}
"
.
format
(
i
+
1
,
total_starcount_run
),
binary_cmdline_string
)
yield
binary_cmdline_string
print
(
"
generator done
"
)
# Create pool
p
=
Pool
(
nodes
=
self
.
grid_options
[
"
amt_cores
"
])
# Execute
r
=
list
(
p
.
imap
(
evolve_system
,
yield_system
()))
stop_mp
=
time
.
time
()
# Give feedback
print
(
"
Without mp: {} systems took {}s
"
.
format
(
total_starcount_run
,
stop_lin
-
start_lin
))
print
(
"
with mp: {} systems took {}s using {} cores
"
.
format
(
self
.
grid_options
[
'
total_starcount
'
],
stop_mp
-
start_mp
,
self
.
grid_options
[
"
amt_cores
"
],
)
)
def
test_evolve_population_lin
(
self
):
"""
Test function to evolve a population in a linear way.
...
...
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