Ejemplo n.º 1
0
 def test_divides(self):
     divisible = [(1, 1), (2, 1), (100, 1), (50, 2), (12, 3)]
     not_divisible = [(1, 0), (5, 0), (5, 4), (13, 2), (3, 6)]
     for (n, m) in divisible:
         self.assertTrue(tools.divides(n, m))
     for (n, m) in not_divisible:
         self.assertFalse(tools.divides(n, m))
    def finalize(self):
        """ Saves results from current model update iteration
        """
        system.checkpoint()

        # save new model to working dir
        src = join(PATH.OPTIMIZE, 'm_new')
        dst = PATH.MODEL
        solver.split(src, dst, '.bin')

        if divides(optimize.iter, PAR.SAVEMODEL):
            self.save_model()

        if divides(optimize.iter, PAR.SAVEGRADIENT):
            self.save_gradient()

        if divides(optimize.iter, PAR.SAVEKERNELS):
            self.save_kernels()

        if divides(optimize.iter, PAR.SAVETRACES):
            self.save_traces()
            self.save_traces(type='syn')

        if divides(optimize.iter, PAR.SAVERESIDUALS):
            self.save_residuals()
Ejemplo n.º 3
0
    def finalize(self):
        """ Saves results from most recent model update iteration
        """
        if divides(self.iter, PAR.SAVEMODEL):
            self.save_model()

        if divides(self.iter, PAR.SAVEGRADIENT):
            self.save_gradient()

        if divides(self.iter, PAR.SAVEKERNELS):
            self.save_kernels()

        if divides(self.iter, PAR.SAVETRACES):
            self.save_traces()

        if divides(self.iter, PAR.SAVERESIDUALS):
            self.save_residuals()

        # clean up directories for next iteration
        if not PATH.LOCAL:
            unix.rm(PATH.GRAD)
            unix.mv(PATH.FUNC, PATH.GRAD)
            unix.mkdir(PATH.FUNC)

            unix.rm(PATH.SOLVER)
            unix.mv(PATH.SOLVER + '_best', PATH.SOLVER)

        else:
            unix.rm(PATH.GRAD)
            unix.rm(PATH.FUNC)
            unix.mkdir(PATH.GRAD)
            unix.mkdir(PATH.FUNC)

        self.isdone = False
Ejemplo n.º 4
0
    def finalize(self):
        """ Saves results from current model update iteration
        """
        system.checkpoint()

        if divides(optimize.iter, PAR.SAVEMODEL):
            self.save_model()

        if divides(optimize.iter, PAR.SAVEGRADIENT):
            self.save_gradient()

        if divides(optimize.iter, PAR.SAVEKERNELS):
            self.save_kernels()

        if divides(optimize.iter, PAR.SAVETRACES):
            self.save_traces()

        if divides(optimize.iter, PAR.SAVERESIDUALS):
            self.save_residuals()
Ejemplo n.º 5
0
    def finalize(self):
        """ Saves results from current model update iteration
        """
        system.checkpoint()

        if divides(optimize.iter, PAR.SAVEMODEL):
            self.save_model()

        if divides(optimize.iter, PAR.SAVEGRADIENT):
            self.save_gradient()

        if divides(optimize.iter, PAR.SAVEKERNELS):
            self.save_kernels()

        if divides(optimize.iter, PAR.SAVETRACES):
            self.save_traces()

        if divides(optimize.iter, PAR.SAVERESIDUALS):
            self.save_residuals()
Ejemplo n.º 6
0
    def evaluate_gradient(self):
        """ Calls adjoint solver and runs process_kernels
        """
        # adjoint simulation
        system.run('solver', 'eval_grad',
                   hosts='all',
                   path=PATH.GRAD,
                   export_traces=divides(self.iter, PAR.SAVETRACES))

        postprocess.process_kernels(
            path=PATH.GRAD)
Ejemplo n.º 7
0
    def evaluate_gradient(self):
        """ Performs adjoint simulation to evaluate gradient
        """
        system.run('solver',
                   'eval_grad',
                   hosts='all',
                   path=PATH.GRAD,
                   export_traces=divides(optimize.iter, PAR.SAVETRACES))

        postprocess.write_gradient(path=PATH.GRAD)

        src = join(PATH.GRAD, 'gradient')
        dst = join(PATH.OPTIMIZE, 'g_new')
        savenpy(dst, solver.merge(solver.load(src, suffix='_kernel')))
Ejemplo n.º 8
0
    def evaluate_gradient(self):
        """ Performs adjoint simulation to evaluate gradient
        """
        system.run('solver', 'eval_grad',
                   hosts='all',
                   path=PATH.GRAD,
                   export_traces=divides(optimize.iter, PAR.SAVETRACES))

        postprocess.write_gradient(
            path=PATH.GRAD)

        src = join(PATH.GRAD, 'gradient')
        dst = join(PATH.OPTIMIZE, 'g_new')
        savenpy(dst, solver.merge(solver.load(src, suffix='_kernel')))