How to use the anypytools.macroutils.MacroCommand function in anypytools

To help you get started, we’ve selected a few anypytools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AnyBody-Research-Group / AnyPyTools / anypytools / macroutils.py View on Github external
def __init__(self, *args, **kwargs):  # number_of_macros=1, counter_token = None ):
        super(AnyMacro, self).__init__()
        if len(args) == 0:
            self._list = list()
        else:
            if len(args) == 1 and isinstance(args[0], list):
                args = args[0]
            for arg in args:
                if not isinstance(arg, MacroCommand):
                    raise ValueError("Argument must be valid macro command classes")
            self._list = list(args)

        self.seed = kwargs.pop("seed", None)

        self.number_of_macros = kwargs.pop("number_of_macros", 1)
        self.counter_token = kwargs.pop("counter_token", None)
github AnyBody-Research-Group / AnyPyTools / anypytools / macroutils.py View on Github external
>>> SaveDesign('Main.MyStudy.Kinematics', 'c:/design.txt')
    classoperation Main.MyStudy.Kinematics "Save design" --file="c:/design.txt"

    """

    def __init__(self, operation, filename):
        self.filename = filename
        self.operation = operation

    def get_macro(self, index, **kwarg):
        return 'classoperation {} "Save design" --file="{}"'.format(
            self.operation, self.filename
        )


class LoadDesign(MacroCommand):
    """Create a Load Design classoperation macro command.

    Parameters
    ----------
    operation : str
        The AnyScript operation
    filename : str
        The file in which to load the design from

    Examples
    --------
    >>> LoadDesign('Main.MyStudy.Kinematics', 'c:/design.txt')
    classoperation Main.MyStudy.Kinematics "Load design" --file="c:/design.txt"

    """
github AnyBody-Research-Group / AnyPyTools / anypytools / macroutils.py View on Github external
Examples
    --------
    >>> LoadValues('c:/values.anyset')
    classoperation Main "Load Values" --file="c:/values.anyset"

    """

    def __init__(self, filename):
        self.filename = filename

    def get_macro(self, index, **kwarg):
        return 'classoperation Main "Load Values" --file="{}"'.format(self.filename)


class UpdateValues(MacroCommand):
    """Create an 'Update Values' classoperation macro command.

    Examples
    --------
    >>> UpdateValues()
    classoperation Main "Update Values"

    """

    def __init__(self):
        pass

    def get_macro(self, index, **kwarg):
        return 'classoperation Main "Update Values"'

github AnyBody-Research-Group / AnyPyTools / anypytools / macroutils.py View on Github external
def get_macro(self, index, lower_tail_probability=None, **kwarg):
        if lower_tail_probability is None:
            lower_tail_probability = self.default_lower_tail_probability

        if self.shape is None and isinstance(lower_tail_probability, np.ndarray):
            lower_tail_probability = lower_tail_probability[0]

        val = self.rv.ppf(lower_tail_probability).reshape(self.shape)
        # Replace any nan from ppf function with actual sampled values.
        if np.any(np.isnan(val)):
            val[np.isnan(val)] = self.rv.rvs()[np.isnan(val)]

        return self._format_macro(val)


class Dump(MacroCommand):
    """Create a Dump classoperation macro command.

    Parameters
    ----------
    var : str or list of str
        The anyscript values to create a 'Dump' macro command for
    include_in_macro: int or list of int
        Specifices in which macros [0,1,2....NumberOfMacros] to include the
        dump command.
        If None, the command is included in all macros.

    Examples
    ---------
    >>> Dump('Main.Study.myvar1')
    classoperation Main.Study.myvar1 "Dump"
github AnyBody-Research-Group / AnyPyTools / anypytools / macroutils.py View on Github external
>>> LoadDesign('Main.MyStudy.Kinematics', 'c:/design.txt')
    classoperation Main.MyStudy.Kinematics "Load design" --file="c:/design.txt"

    """

    def __init__(self, operation, filename):
        self.filename = filename
        self.operation = operation

    def get_macro(self, index, **kwarg):
        return 'classoperation {} "Load design" --file="{}"'.format(
            self.operation, self.filename
        )


class SaveValues(MacroCommand):
    """Create a Save Values classoperation macro command.

    Parameters
    ----------
    filename : str
        The anyset file to save the values to

    Examples
    --------
    >>> SaveValues('c:/values.anyset')
    classoperation Main "Save Values" --file="c:/values.anyset"

    """

    def __init__(self, filename):
        self.filename = filename
github AnyBody-Research-Group / AnyPyTools / anypytools / macroutils.py View on Github external
--------
    >>> SaveData('Main.Study', 'output.anydata.h5')
    classoperation Main.Study.Output "Save data" --type="Deep" --file="output.anydata.h5"

    """

    def __init__(self, operation, filename):
        self.filename = filename
        self.opeation = operation

    def get_macro(self, index, **kwarg):
        macro_str = 'classoperation {}.Output "Save data" --type="Deep" --file="{}"'
        return macro_str.format(self.opeation, self.filename)


class LoadValues(MacroCommand):
    """Create a Load Values classoperation macro command.

    Parameters
    ----------
    filename : str
        The anyset file to load the values from.

    Examples
    --------
    >>> LoadValues('c:/values.anyset')
    classoperation Main "Load Values" --file="c:/values.anyset"

    """

    def __init__(self, filename):
        self.filename = filename
github AnyBody-Research-Group / AnyPyTools / anypytools / macroutils.py View on Github external
Examples
    --------
    >>> SaveValues('c:/values.anyset')
    classoperation Main "Save Values" --file="c:/values.anyset"

    """

    def __init__(self, filename):
        self.filename = filename

    def get_macro(self, index, **kwarg):
        return 'classoperation Main "Save Values" --file="{}"'.format(self.filename)


class SaveData(MacroCommand):
    """Create a Save Data classoperation macro command.

    This macro operation will save all data from a study to a
    HDF5 file.

    Parameters
    ----------
    operation : str
        Operation to save the h5 from
    filename : str
        The anyset file to save the values to

    Examples
    --------
    >>> SaveData('Main.Study', 'output.anydata.h5')
    classoperation Main.Study.Output "Save data" --type="Deep" --file="output.anydata.h5"
github AnyBody-Research-Group / AnyPyTools / anypytools / macroutils.py View on Github external
----------
        index : int
            The index for the macro beeing generated. Some child classes
            use the index to generate different macros depending on the
            index.

        Returns
        -------
        string
            A string with the AnyScript macro

        """
        return "\n".join(self.cmd)


class Load(MacroCommand):
    """Create a load macro command.

    Parameters
    ----------
    filename : str
        Path of the file to load
    defs : dict
        Dictionary of defines statements to set during load
    paths : dict
        Dictionary of path staements to set during load

    Examples
    --------
    >>> Load('model.main.any')
    load "model.main.any"
github AnyBody-Research-Group / AnyPyTools / anypytools / macroutils.py View on Github external
self.paths = paths.copy()

    def get_macro(self, index, **kwarg):
        cmd = ['load "{}"'.format(self.filename)]

        for key in sorted(self.defs):
            value = self.defs[key]
            cmd.append(define2str(key, value))
        for key in sorted(self.paths):
            value = self.paths[key]
            cmd.append(path2str(key, value))

        return " ".join(cmd)


class SetValue(MacroCommand):
    """Create 'Set Value' classoperation macro command.

    Parameters
    ----------
    var : string
        An AnyScript variable.
    value : number or list of number
        A value or list of values to assign to the AnyScript variable.

    Examples
    ---------
    Set a single values:

    >>> SetValue('Main.Study.myvar1', 23.1)
    classoperation Main.Study.myvar1 "Set Value" --value="23.1"
github AnyBody-Research-Group / AnyPyTools / anypytools / macroutils.py View on Github external
Examples
    --------
    >>> UpdateValues()
    classoperation Main "Update Values"

    """

    def __init__(self):
        pass

    def get_macro(self, index, **kwarg):
        return 'classoperation Main "Update Values"'


class OperationRun(MacroCommand):
    """Create a macro command to select and run an operation.

    Examples
    --------
    >>> OperationRun('Main.MyStudy.Kinematics')
    >>> pprint( mg.generate_macros())
    operation Main.MyStudy.Kinematics
    run

    >>> mg = AnyMacro(Load('my_model.main.any'),
                   OperationRun('Main.MyStudy.Kinematics'))
    >>> mg.create_macros()
    [[u'load "my_model.main.any"', u'operation Main.MyStudy.Kinematics', u'run']]

    """