Beispiel #1
0
    def _save(self, group):
        """
        Save the state of the node into a HDF5 file.

        group can be the root
        """
        for i in range(len(self.u)):
            misc.write_to_hdf5(group, self.u[i], 'u%d' % i)
        misc.write_to_hdf5(group, self.observed, 'observed')
        return
Beispiel #2
0
    def _save(self, group):
        """
        Save the state of the node into a HDF5 file.

        group can be the root
        """
        for i in range(len(self.u)):
            misc.write_to_hdf5(group, self.u[i], 'u%d' % i)
        misc.write_to_hdf5(group, self.observed, 'observed')
        return
Beispiel #3
0
    def save(self, group):
        """
        Save the state of the node into a HDF5 file.

        group can be the root
        """
        ## if name is None:
        ##     name = self.name
        ## subgroup = group.create_group(name)

        for i in range(len(self.u)):
            misc.write_to_hdf5(group, self.u[i], 'u%d' % i)
        misc.write_to_hdf5(group, self.observed, 'observed')
Beispiel #4
0
    def save(self, group):
        """
        Save the state of the node into a HDF5 file.

        group can be the root
        """
        ## if name is None:
        ##     name = self.name
        ## subgroup = group.create_group(name)
        
        for i in range(len(self.u)):
            misc.write_to_hdf5(group, self.u[i], 'u%d' % i)
        misc.write_to_hdf5(group, self.observed, 'observed')
Beispiel #5
0
    def save(self, filename=None):

        if self.iter == 0:
            # Check HDF5 version.
            if h5py.version.hdf5_version_tuple < (1,8,7): 
                warnings.warn("WARNING! Your HDF5 version is %s. HDF5 versions "
                              "<1.8.7 are not able to save empty arrays, thus "
                              "you may experience problems if you for instance "
                              "try to save before running any iteration steps."
                              % str(h5py.version.hdf5_version_tuple))
            

        # By default, use the same file as for auto-saving
        if not filename:
            if self.filename:
                filename = self.filename
            else:
                raise Exception("Filename must be given.")

        # Open HDF5 file
        h5f = h5py.File(filename, 'w')

        try:
            # Write each node
            nodegroup = h5f.create_group('nodes')
            for node in self.model:
                if node.name == '':
                    raise Exception("In order to save nodes, they must have "
                                    "(unique) names.")
                if hasattr(node, 'save') and callable(node.save):
                    node.save(nodegroup.create_group(node.name))
            # Write iteration statistics
            misc.write_to_hdf5(h5f, self.L, 'L')
            misc.write_to_hdf5(h5f, self.iter, 'iter')
            if self.callback_output is not None:
                misc.write_to_hdf5(h5f, 
                                          self.callback_output,
                                          'callback_output')
            boundgroup = h5f.create_group('boundterms')
            for node in self.model:
                misc.write_to_hdf5(boundgroup, self.l[node], node.name)
        finally:
            # Close file
            h5f.close()
Beispiel #6
0
    def save(self, group):
        """
        Save the state of the node into a HDF5 file.

        group can be the root
        """
        ## if name is None:
        ##     name = self.name
        ## subgroup = group.create_group(name)
        
        for i in range(len(self.phi)):
            misc.write_to_hdf5(group, self.phi[i], 'phi%d' % i)
        misc.write_to_hdf5(group, self.f, 'f')
        misc.write_to_hdf5(group, self.g, 'g')
        super().save(group)
Beispiel #7
0
    def _save(self, group):
        """
        Save the state of the node into a HDF5 file.

        group can be the root
        """
        ## if name is None:
        ##     name = self.name
        ## subgroup = group.create_group(name)

        for i in range(len(self.phi)):
            misc.write_to_hdf5(group, self.phi[i], 'phi%d' % i)
        misc.write_to_hdf5(group, self.f, 'f')
        misc.write_to_hdf5(group, self.g, 'g')
        super()._save(group)
Beispiel #8
0
    def save(self, *nodes, filename=None):

        if len(nodes) == 0:
            nodes = self.model
        else:
            nodes = [self[node] for node in nodes if node is not None]

        if self.iter == 0:
            # Check HDF5 version.
            if h5py.version.hdf5_version_tuple < (1, 8, 7):
                warnings.warn(
                    "WARNING! Your HDF5 version is %s. HDF5 versions "
                    "<1.8.7 are not able to save empty arrays, thus "
                    "you may experience problems if you for instance "
                    "try to save before running any iteration steps." %
                    str(h5py.version.hdf5_version_tuple))

        # By default, use the same file as for auto-saving
        if not filename:
            if self.autosave_filename:
                filename = self.autosave_filename
            else:
                raise Exception("Filename must be given.")

        # Open HDF5 file
        h5f = h5py.File(filename, 'w')

        try:
            # Write each node
            nodegroup = h5f.create_group('nodes')
            for node in nodes:
                if node.name == '':
                    raise Exception("In order to save nodes, they must have "
                                    "(unique) names.")
                if hasattr(node, '_save') and callable(node._save):
                    node._save(nodegroup.create_group(node.name))
            # Write iteration statistics
            misc.write_to_hdf5(h5f, self.L, 'L')
            misc.write_to_hdf5(h5f, self.cputime, 'cputime')
            misc.write_to_hdf5(h5f, self.iter, 'iter')
            misc.write_to_hdf5(h5f, self.converged, 'converged')
            if self.callback_output is not None:
                misc.write_to_hdf5(h5f, self.callback_output,
                                   'callback_output')
            boundgroup = h5f.create_group('boundterms')
            for node in nodes:
                misc.write_to_hdf5(boundgroup, self.l[node], node.name)
        finally:
            # Close file
            h5f.close()
Beispiel #9
0
    def save(self, *nodes, filename=None):

        if len(nodes) == 0:
            nodes = self.model
        else:
            nodes = [self[node] for node in nodes if node is not None]

        if self.iter == 0:
            # Check HDF5 version.
            if h5py.version.hdf5_version_tuple < (1, 8, 7):
                warnings.warn(
                    "WARNING! Your HDF5 version is %s. HDF5 versions "
                    "<1.8.7 are not able to save empty arrays, thus "
                    "you may experience problems if you for instance "
                    "try to save before running any iteration steps." % str(h5py.version.hdf5_version_tuple)
                )

        # By default, use the same file as for auto-saving
        if not filename:
            if self.autosave_filename:
                filename = self.autosave_filename
            else:
                raise Exception("Filename must be given.")

        # Open HDF5 file
        h5f = h5py.File(filename, "w")

        try:
            # Write each node
            nodegroup = h5f.create_group("nodes")
            for node in nodes:
                if node.name == "":
                    raise Exception("In order to save nodes, they must have " "(unique) names.")
                if hasattr(node, "_save") and callable(node._save):
                    node._save(nodegroup.create_group(node.name))
            # Write iteration statistics
            misc.write_to_hdf5(h5f, self.L, "L")
            misc.write_to_hdf5(h5f, self.cputime, "cputime")
            misc.write_to_hdf5(h5f, self.iter, "iter")
            misc.write_to_hdf5(h5f, self.converged, "converged")
            if self.callback_output is not None:
                misc.write_to_hdf5(h5f, self.callback_output, "callback_output")
            boundgroup = h5f.create_group("boundterms")
            for node in nodes:
                misc.write_to_hdf5(boundgroup, self.l[node], node.name)
        finally:
            # Close file
            h5f.close()