pypet 0.5.0 documentation
previous | next | modules | index

Using LinksΒΆ

Download: example_14_links.py

You can also link between different nodes of your Trajectory:

__author__ = 'Robert Meyer'

import os # To allow file paths working under Windows and Linux

from pypet import Environment, Result, Parameter

def multiply(traj):
    """Example of a sophisticated simulation that involves multiplying two values.

    :param traj:

        Trajectory containing
        the parameters in a particular combination,
        it also serves as a container for results.

    """
    z=traj.mylink1*traj.mylink2 # And again we now can also use the different names
    # due to the creation of links
    traj.f_add_result('runs.$.z', z, comment='Result of our simulation!')


# Create an environment that handles running
filename = os.path.join('hdf5','example_14.hdf5')
env = Environment(trajectory='Multiplication',
                  filename=filename,
                  file_title='Example_14_Links',
                  overwrite_file=True,
                  comment='How to use links')

# The environment has created a trajectory container for us
traj = env.trajectory

# Add both parameters
traj.par.x = Parameter('x', 1, 'I am the first dimension!')
traj.par.y = Parameter('y', 1, 'I am the second dimension!')

# Explore just two points
traj.f_explore({'x': [3, 4]})

# So far everything was as in the first example. However now we add links:
traj.f_add_link('mylink1', traj.f_get('x'))
# Note the `f_get` here to ensure to get the parameter instance, not the value 1
# This allows us now to access x differently:
print('x=' + str(traj.mylink1))
# We can try to avoid fast access as well, and recover the original parameter
print(str(traj.f_get('mylink1')))
# And also colon notation is allowed that creates new groups on the fly
traj.f_add_link('parameters.mynewgroup.mylink2', traj.f_get('y'))



# And, of course, we can also use the links during run:
env.run(multiply)

# Finally disable logging and close all log-files
env.disable_logging()

Table of Contents

  • pypet User Manual
    • What is pypet all about?
    • Getting Started
    • Tutorial
    • Cookbook (Detailed Manual)
    • Examples
    • Optimization Tips
    • FAQs and Known Issues
  • Miscellaneous
  • Library Reference

Search

previous | next | modules | index

Show Source
© Copyright 2020, Robert Meyer. Created using Sphinx 1.8.5.