本文整理汇总了Python中pypet.Environment类的典型用法代码示例。如果您正苦于以下问题:Python Environment类的具体用法?Python Environment怎么用?Python Environment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Environment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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()
示例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()
示例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)
示例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)
示例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)
示例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()
示例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))
示例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()
示例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()
示例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()
示例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)
示例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
示例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()
示例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()