本文整理汇总了Python中pypet.Environment类的典型用法代码示例。如果您正苦于以下问题:Python Environment类的具体用法?Python Environment怎么用?Python Environment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Environment类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: main
def main():
batch = get_batch()
filename = 'saga_%s.hdf5' % str(batch)
env = Environment(trajectory='Example_22_Euler_Integration_%s' % str(batch),
filename=filename,
file_title='Example_22_Euler_Integration',
comment='Go for Euler!',
overwrite_file=True,
multiproc=True, # Yes we can use multiprocessing within each batch!
ncores=4)
traj = env.trajectory
trajectory_name = traj.v_name
# 1st a) phase parameter addition
add_parameters(traj)
# 1st b) phase preparation
# We will add the differential equation (well, its source code only) as a derived parameter
traj.f_add_derived_parameter(FunctionParameter,'diff_eq', diff_lorenz,
comment='Source code of our equation!')
# explore the trajectory
explore_batch(traj, batch)
# 2nd phase let's run the experiment
# We pass `euler_scheme` as our top-level simulation function and
# the Lorenz equation 'diff_lorenz' as an additional argument
env.run(euler_scheme, diff_lorenz)
开发者ID:SmokinCaterpillar,项目名称:pypet,代码行数:30,代码来源:the_task.py
示例2: test_maximum_overview_size
def test_maximum_overview_size(self):
filename = make_temp_dir('maxisze.hdf5')
env = Environment(trajectory='Testmigrate', filename=filename,
log_config=get_log_config())
traj = env.v_trajectory
for irun in range(pypetconstants.HDF5_MAX_OVERVIEW_TABLE_LENGTH):
traj.f_add_parameter('f%d.x' % irun, 5)
traj.f_store()
store = ptcompat.open_file(filename, mode='r+')
table = ptcompat.get_child(store.root,traj.v_name).overview.parameters_overview
self.assertEquals(table.nrows, pypetconstants.HDF5_MAX_OVERVIEW_TABLE_LENGTH)
store.close()
for irun in range(pypetconstants.HDF5_MAX_OVERVIEW_TABLE_LENGTH,
2*pypetconstants.HDF5_MAX_OVERVIEW_TABLE_LENGTH):
traj.f_add_parameter('f%d.x' % irun, 5)
traj.f_store()
store = ptcompat.open_file(filename, mode='r+')
table = ptcompat.get_child(store.root,traj.v_name).overview.parameters_overview
self.assertEquals(table.nrows, pypetconstants.HDF5_MAX_OVERVIEW_TABLE_LENGTH)
store.close()
env.f_disable_logging()
开发者ID:henribunting,项目名称:pypet,代码行数:32,代码来源:storage_test.py
示例3: main
def main():
filename = os.path.join('hdf5', 'Clustered_Network.hdf5')
# If we pass a filename to the trajectory a new HDF5StorageService will
# be automatically created
traj = Trajectory(filename=filename,
dynamically_imported_classes=[BrianMonitorResult,
BrianParameter])
# Let's create and fake environment to enable logging:
env = Environment(traj, do_single_runs=False)
# Load the trajectory, but onyl laod the skeleton of the results
traj.f_load(index=-1, load_parameters=2, load_derived_parameters=2, load_results=1)
# Find the result instances related to the fano factor
fano_dict = traj.f_get_from_runs('mean_fano_factor', fast_access=False)
# Load the data of the fano factor results
ffs = fano_dict.values()
traj.f_load_items(ffs)
# Extract all values and R_ee values for each run
ffs_values = [x.f_get() for x in ffs]
Rees = traj.f_get('R_ee').f_get_range()
# Plot average fano factor as a function of R_ee
plt.plot(Rees, ffs_values)
plt.xlabel('R_ee')
plt.ylabel('Avg. Fano Factor')
plt.show()
# Finally disable logging and close all log-files
env.disable_logging()
开发者ID:MehmetTimur,项目名称:pypet,代码行数:35,代码来源:plotff.py
示例4: test_logging_stdout
def test_logging_stdout(self):
filename = 'teststdoutlog.hdf5'
filename = make_temp_dir(filename)
folder = make_temp_dir('logs')
env = Environment(trajectory=make_trajectory_name(self),
filename=filename, log_config=get_log_config(),
# log_levels=logging.CRITICAL, # needed for the test
log_stdout=('STDOUT', 50), #log_folder=folder
)
env.f_run(log_error)
traj = env.v_traj
path = get_log_path(traj)
mainstr = 'sTdOuTLoGGinG'
print(mainstr)
env.f_disable_logging()
mainfilename = os.path.join(path, 'LOG.txt')
with open(mainfilename, mode='r') as mainf:
full_text = mainf.read()
self.assertTrue(mainstr in full_text)
self.assertTrue('4444444' not in full_text)
self.assertTrue('DEBUG' not in full_text)
开发者ID:MehmetTimur,项目名称:pypet,代码行数:25,代码来源:logging_test.py
示例5: test_without_pre_run
def test_without_pre_run(self):
runner = NetworkRunner()
components = [TheNeurons(), TheConnection(), TheSimulation()]
analyser = [TheMonitors()]
nm = NetworkManager(network_runner=runner, component_list=components,
analyser_list=analyser)
env = Environment(trajectory='Test_'+repr(time.time()).replace('.','_'),
filename=make_temp_dir(os.path.join(
'experiments',
'tests',
'briantests',
'HDF5',
'briantest.hdf5')),
file_title='test',
log_config=get_log_config(),
dynamic_imports=['pypet.brian2.parameter.BrianParameter',
BrianMonitorResult, BrianResult],
multiproc=True,
ncores=2)
traj = env.v_traj
nm.add_parameters(traj)
traj.f_explore({'v01': [11*mV, 13*mV]})
env.f_run(nm.run_network)
self.check_data(traj)
开发者ID:femtotrader,项目名称:pypet,代码行数:26,代码来源:network_test.py
示例6: main
def main():
env = Environment(trajectory='FiringRate',
comment='Experiment to measure the firing rate '
'of a leaky integrate and fire neuron. '
'Exploring different input currents, '
'as well as refractory periods',
add_time=False, # We don't want to add the current time to the name,
log_folder='./logs/',
log_level=logging.INFO,
log_stdout=True,
multiproc=True,
ncores=2, #My laptop has 2 cores ;-)
wrap_mode='QUEUE',
filename='./hdf5/', # We only pass a folder here, so the name is chosen
# automatically to be the same as the Trajectory
)
traj = env.v_trajectory
# Add parameters
add_parameters(traj)
# Let's explore
add_exploration(traj)
# Ad the postprocessing function
env.f_add_postprocessing(neuron_postproc)
# Run the experiment
env.f_run(run_neuron)
开发者ID:lsolanka,项目名称:pypet,代码行数:31,代码来源:main.py
示例7: main
def main():
""" Main *boilerplate* function to start simulation """
# Now let's make use of logging
logger = logging.getLogger()
# Create folders for data and plots
folder = os.path.join(os.getcwd(), 'experiments', 'ca_patterns_pypet')
if not os.path.isdir(folder):
os.makedirs(folder)
filename = os.path.join(folder, 'all_patterns.hdf5')
# Create an environment
env = Environment(trajectory='cellular_automata',
multiproc=True,
ncores=4,
wrap_mode='QUEUE',
filename=filename,
overwrite_file=True)
# extract the trajectory
traj = env.traj
traj.v_lazy_adding = True
traj.par.ncells = 400, 'Number of cells'
traj.par.steps = 250, 'Number of timesteps'
traj.par.rule_number = 30, 'The ca rule'
traj.par.initial_name = 'random', 'The type of initial state'
traj.par.seed = 100042, 'RNG Seed'
# Explore
exp_dict = {'rule_number' : [10, 30, 90, 110, 184],
'initial_name' : ['single', 'random'],}
# # You can uncomment the ``exp_dict`` below to see that changing the
# # exploration scheme is now really easy:
# exp_dict = {'rule_number' : [10, 30, 90, 110, 184],
# 'ncells' : [100, 200, 300],
# 'seed': [333444555, 123456]}
exp_dict = cartesian_product(exp_dict)
traj.f_explore(exp_dict)
# Run the simulation
logger.info('Starting Simulation')
env.run(wrap_automaton)
# Load all data
traj.f_load(load_data=2)
logger.info('Printing data')
for idx, run_name in enumerate(traj.f_iter_runs()):
# Plot all patterns
filename = os.path.join(folder, make_filename(traj))
plot_pattern(traj.crun.pattern, traj.rule_number, filename)
progressbar(idx, len(traj), logger=logger)
# Finally disable logging and close all log-files
env.disable_logging()
开发者ID:MehmetTimur,项目名称:pypet,代码行数:57,代码来源:pypetwrap.py
示例8: test_run
def test_run():
global filename
np.random.seed()
trajname = 'profiling'
filename = make_temp_dir(os.path.join('hdf5', 'test%s.hdf5' % trajname))
env = Environment(trajectory=trajname, filename=filename,
file_title=trajname,
log_stdout=False,
results_per_run=5,
derived_parameters_per_run=5,
multiproc=False,
ncores=1,
wrap_mode='LOCK',
use_pool=False,
overwrite_file=True)
traj = env.v_trajectory
traj.v_standard_parameter=Parameter
## Create some parameters
param_dict={}
create_param_dict(param_dict)
### Add some parameter:
add_params(traj,param_dict)
#remember the trajectory and the environment
traj = traj
env = env
traj.f_add_parameter('TEST', 'test_run')
###Explore
explore(traj)
### Make a test run
simple_arg = -13
simple_kwarg= 13.0
env.f_run(simple_calculations,simple_arg,simple_kwarg=simple_kwarg)
size=os.path.getsize(filename)
size_in_mb = size/1000000.
print('Size is %sMB' % str(size_in_mb))
开发者ID:MehmetTimur,项目名称:pypet,代码行数:46,代码来源:profiling.py
示例9: test_parsing
def test_parsing(self):
filename = make_temp_dir('config_test.hdf5')
env = Environment(filename=filename, config=self.parser)
traj = env.v_traj
self.assertTrue(traj.v_auto_load)
self.assertEqual(traj.v_storage_service.filename, filename)
self.assertEqual(traj.x, 42)
self.assertEqual(traj.f_get('y').v_comment, 'This is the second variable')
self.assertTrue(traj.testconfig)
self.assertTrue(env._logging_manager.log_config is not None)
self.assertTrue(env._logging_manager._sp_config is not None)
env.f_disable_logging()
开发者ID:SmokinCaterpillar,项目名称:pypet,代码行数:17,代码来源:configparse_test.py
示例10: main
def main():
"""Main function to protect the *entry point* of the program.
If you want to use multiprocessing under Windows you need to wrap your
main code creating an environment into a function. Otherwise
the newly started child processes will re-execute the code and throw
errors (also see https://docs.python.org/2/library/multiprocessing.html#windows).
"""
# Create an environment that handles running.
# Let's enable multiprocessing with 2 workers.
filename = os.path.join('hdf5', 'example_04.hdf5')
env = Environment(trajectory='Example_04_MP',
filename=filename,
file_title='Example_04_MP',
log_stdout=True,
comment='Multiprocessing example!',
multiproc=True,
ncores=4,
use_pool=True, # Our runs are inexpensive we can get rid of overhead
# by using a pool
freeze_input=True, # We can avoid some
# overhead by freezing the input to the pool
wrap_mode=pypetconstants.WRAP_MODE_QUEUE,
graceful_exit=True, # We want to exit in a data friendly way
# that safes all results after hitting CTRL+C, try it ;-)
overwrite_file=True)
# Get the trajectory from the environment
traj = env.trajectory
# Add both parameters
traj.f_add_parameter('x', 1.0, comment='I am the first dimension!')
traj.f_add_parameter('y', 1.0, comment='I am the second dimension!')
# Explore the parameters with a cartesian product, but we want to explore a bit more
traj.f_explore(cartesian_product({'x':[float(x) for x in range(20)],
'y':[float(y) for y in range(20)]}))
# Run the simulation
env.run(multiply)
# Finally disable logging and close all log-files
env.disable_logging()
开发者ID:SmokinCaterpillar,项目名称:pypet,代码行数:45,代码来源:example_04_multiprocessing.py
示例11: main
def main():
filename = os.path.join('hdf5', 'FiringRate.hdf5')
env = Environment(trajectory='FiringRate',
comment='Experiment to measure the firing rate '
'of a leaky integrate and fire neuron. '
'Exploring different input currents, '
'as well as refractory periods',
add_time=False, # We don't want to add the current time to the name,
log_stdout=True,
log_config='DEFAULT',
multiproc=True,
ncores=2, #My laptop has 2 cores ;-)
wrap_mode='QUEUE',
filename=filename,
overwrite_file=True)
traj = env.trajectory
# Add parameters
add_parameters(traj)
# Let's explore
add_exploration(traj)
# Ad the postprocessing function
env.add_postprocessing(neuron_postproc)
# Run the experiment
env.run(run_neuron)
# Finally disable logging and close all log-files
env.disable_logging()
开发者ID:MehmetTimur,项目名称:pypet,代码行数:33,代码来源:main.py
示例12: main
def main():
env = Environment(trajectory='FiringRatePipeline',
comment='Experiment to measure the firing rate '
'of a leaky integrate and fire neuron. '
'Exploring different input currents, '
'as well as refractory periods',
add_time=False, # We don't want to add the current time to the name,
log_folder='./logs/',
log_level=logging.INFO,
log_stdout=True,
multiproc=True,
ncores=2, #My laptop has 2 cores ;-)
filename='./hdf5/', # We only pass a folder here, so the name is chosen
# automatically to be the same as the Trajectory
)
env.f_pipeline(mypipeline)
开发者ID:lsolanka,项目名称:pypet,代码行数:18,代码来源:pipeline.py
示例13: make_env
def make_env(self, **kwargs):
self.mode.__dict__.update(kwargs)
filename = 'log_testing.hdf5'
self.filename = make_temp_dir(filename)
self.traj_name = make_trajectory_name(self)
self.env = Environment(trajectory=self.traj_name,
filename=self.filename, **self.mode.__dict__)
self.traj = self.env.v_traj
开发者ID:MehmetTimur,项目名称:pypet,代码行数:9,代码来源:logging_test.py
示例14: main
def main():
filename = os.path.join('hdf5', 'FiringRate.hdf5')
env = Environment(trajectory='FiringRatePipeline',
comment='Experiment to measure the firing rate '
'of a leaky integrate and fire neuron. '
'Exploring different input currents, '
'as well as refractory periods',
add_time=False, # We don't want to add the current time to the name,
log_stdout=True,
multiproc=True,
ncores=2, #My laptop has 2 cores ;-)
filename=filename,
overwrite_file=True)
env.pipeline(mypipeline)
# Finally disable logging and close all log-files
env.disable_logging()
开发者ID:MehmetTimur,项目名称:pypet,代码行数:18,代码来源:pipeline.py
示例15: main
def main():
"""Main function to protect the *entry point* of the program.
If you want to use multiprocessing with SCOOP you need to wrap your
main code creating an environment into a function. Otherwise
the newly started child processes will re-execute the code and throw
errors (also see http://scoop.readthedocs.org/en/latest/usage.html#pitfalls).
"""
# Create an environment that handles running.
# Let's enable multiprocessing with scoop:
filename = os.path.join('hdf5', 'example_21.hdf5')
env = Environment(trajectory='Example_21_SCOOP',
filename=filename,
file_title='Example_21_SCOOP',
log_stdout=True,
comment='Multiprocessing example using SCOOP!',
multiproc=True,
freeze_input=True, # We want to save overhead and freeze input
use_scoop=True, # Yes we want SCOOP!
wrap_mode=pypetconstants.WRAP_MODE_LOCAL, # SCOOP only works with 'LOCAL'
# or 'NETLOCK' wrapping
overwrite_file=True)
# Get the trajectory from the environment
traj = env.trajectory
# Add both parameters
traj.f_add_parameter('x', 1.0, comment='I am the first dimension!')
traj.f_add_parameter('y', 1.0, comment='I am the second dimension!')
# Explore the parameters with a cartesian product, but we want to explore a bit more
traj.f_explore(cartesian_product({'x':[float(x) for x in range(20)],
'y':[float(y) for y in range(20)]}))
# Run the simulation
env.run(multiply)
# Let's check that all runs are completed!
assert traj.f_is_completed()
# Finally disable logging and close all log-files
env.disable_logging()
开发者ID:MehmetTimur,项目名称:pypet,代码行数:43,代码来源:example_21_scoop_multiprocessing.py
示例16: test_net
def test_net(self):
env = Environment(trajectory='Test_'+repr(time.time()).replace('.','_'),
filename=make_temp_dir(os.path.join(
'experiments',
'tests',
'briantests',
'HDF5',
'briantest.hdf5')),
file_title='test',
log_config=get_log_config(),
dynamic_imports=['pypet.brian2.parameter.Brian2Parameter',
Brian2MonitorResult],
multiproc=False)
traj = env.v_traj
traj.f_add_parameter(Brian2Parameter, 'v0', 0.0*mV,
comment='Input bias')
traj.f_explore({'v0': [11*mV, 13*mV, 15*mV]})
env.f_run(run_network)
self.get_data(traj)
开发者ID:SmokinCaterpillar,项目名称:pypet,代码行数:19,代码来源:another_network_test.py
示例17: main
def main():
# Create an environment that handles running
filename = os.path.join('hdf5','example_18.hdf5')
env = Environment(trajectory='Multiplication',
filename=filename,
file_title='Example_18_Many_Runs',
overwrite_file=True,
comment='Contains many runs',
multiproc=True,
use_pool=True,
freeze_input=True,
ncores=2,
wrap_mode='QUEUE')
# The environment has created a trajectory container for us
traj = env.trajectory
# Add both parameters
traj.f_add_parameter('x', 1, comment='I am the first dimension!')
traj.f_add_parameter('y', 1, comment='I am the second dimension!')
# Explore the parameters with a cartesian product, yielding 2500 runs
traj.f_explore(cartesian_product({'x': range(50), 'y': range(50)}))
# Run the simulation
env.run(multiply)
# Disable logging
env.disable_logging()
# turn auto loading on, since results have not been loaded, yet
traj.v_auto_load = True
# Use the `v_idx` functionality
traj.v_idx = 2042
print('The result of run %d is: ' % traj.v_idx)
# Now we can rely on the wildcards
print(traj.res.crunset.crun.z)
traj.v_idx = -1
# Or we can use the shortcuts `rts_X` (run to set) and `r_X` to get particular results
print('The result of run %d is: ' % 2044)
print(traj.res.rts_2044.r_2044.z)
开发者ID:SmokinCaterpillar,项目名称:pypet,代码行数:41,代码来源:example_18_many_runs.py
示例18: test_overwrite_annotations_and_results
def test_overwrite_annotations_and_results(self):
filename = make_temp_dir('overwrite.hdf5')
env = Environment(trajectory='testoverwrite', filename=filename,
log_config=get_log_config())
traj = env.v_traj
traj.f_add_parameter('grp.x', 5, comment='hi')
traj.grp.v_comment='hi'
traj.grp.v_annotations['a'] = 'b'
traj.f_store()
traj.f_remove_child('parameters', recursive=True)
traj.f_load(load_data=2)
self.assertTrue(traj.x == 5)
self.assertTrue(traj.grp.v_comment == 'hi')
self.assertTrue(traj.grp.v_annotations['a'] == 'b')
traj.f_get('x').f_unlock()
traj.grp.x = 22
traj.f_get('x').v_comment='hu'
traj.grp.v_annotations['a'] = 'c'
traj.grp.v_comment = 'hu'
traj.f_store_item(traj.f_get('x'), store_data=3)
traj.f_store_item(traj.grp, store_data=3)
traj.f_remove_child('parameters', recursive=True)
traj.f_load(load_data=2)
self.assertTrue(traj.x == 22)
self.assertTrue(traj.grp.v_comment == 'hu')
self.assertTrue(traj.grp.v_annotations['a'] == 'c')
env.f_disable_logging()
开发者ID:henribunting,项目名称:pypet,代码行数:41,代码来源:storage_test.py
示例19: test_throw_warning_if_old_kw_is_used
def test_throw_warning_if_old_kw_is_used(self):
pass
filename = make_temp_dir('hdfwarning.hdf5')
with warnings.catch_warnings(record=True) as w:
env = Environment(trajectory='test', filename=filename,
dynamically_imported_classes=[],
log_config=get_log_config())
with warnings.catch_warnings(record=True) as w:
traj = Trajectory(dynamically_imported_classes=[])
traj = env.v_trajectory
traj.f_store()
with warnings.catch_warnings(record=True) as w:
traj.f_load(dynamically_imported_classes=[])
env.f_disable_logging()
开发者ID:henribunting,项目名称:pypet,代码行数:21,代码来源:storage_test.py
示例20: main
def main():
# Create an environment that handles running
filename = os.path.join('hdf5', 'example_12.hdf5')
env = Environment(trajectory='Multiplication',
filename=filename,
file_title='Example_12_Sharing_Data',
overwrite_file=True,
comment='The first example!',
continuable=False, # We have shared data in terms of a multiprocessing list,
# so we CANNOT use the continue feature.
multiproc=True,
ncores=2)
# The environment has created a trajectory container for us
traj = env.trajectory
# Add both parameters
traj.f_add_parameter('x', 1, comment='I am the first dimension!')
traj.f_add_parameter('y', 1, comment='I am the second dimension!')
# Explore the parameters with a cartesian product
traj.f_explore(cartesian_product({'x':[1,2,3,4], 'y':[6,7,8]}))
# We want a shared list where we can put all out results in. We use a manager for this:
result_list = mp.Manager().list()
# Let's make some space for potential results
result_list[:] =[0 for _dummy in range(len(traj))]
# Run the simulation
env.run(multiply, result_list)
# Now we want to store the final list as numpy array
traj.f_add_result('z', np.array(result_list))
# Finally let's print the result to see that it worked
print(traj.z)
#Disable logging and close all log-files
env.disable_logging()
开发者ID:MehmetTimur,项目名称:pypet,代码行数:39,代码来源:example_12_sharing_data_between_processes.py
注:本文中的pypet.Environment类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论