Ejemplo n.º 1
0
    def _init_and_compile_C(
        self,
        derivatives,
        helpers=None,
        inputs=None,
        max_delay=0.0,
        callbacks=None,
        chunksize=1,
    ):
        """
        Initialise DDE system and compile to C.
        """
        logging.info("Setting up the DDE system...")
        if platform == "darwin":
            # assert clang is used on macOS
            os.environ["CC"] = "clang"
        callbacks = callbacks or ()
        self.dde_system = jitcdde_input(
            f_sym=derivatives,
            input=inputs,
            helpers=helpers,
            n=len(derivatives),
            max_delay=max_delay,
            callback_functions=callbacks,
        )

        logging.info("Compiling to C...")
        self.dde_system.compile_C(
            simplify=False,
            do_cse=False,
            extra_compile_args=self.extra_compile_args,
            omp=False,
            chunk_size=chunksize,
            verbose=False,
        )
Ejemplo n.º 2
0
 def _run_mass(self, node, duration, dt):
     coupling_variables = {k: 0.0 for k in node.required_couplings}
     noise = ZeroInput(num_iid=node.num_noise_variables).as_cubic_splines(duration, dt)
     system = jitcdde_input(node._derivatives(coupling_variables), input=noise)
     system.constant_past(np.array(node.initial_state))
     system.adjust_diff()
     times = np.arange(dt, duration + dt, dt)
     return np.vstack([system.integrate(time) for time in times])
Ejemplo n.º 3
0
    def _init_and_compile_C(
        self,
        derivatives,
        helpers=None,
        inputs=None,
        max_delay=0.0,
        callbacks=None,
        chunksize=1,
        use_open_mp=False,
    ):
        """
        Initialise DDE system and compiled to C.
        """
        logging.info("Setting up the DDE system...")
        if platform == "darwin":
            # assert clang is used on macOS
            os.environ["CC"] = "clang"
        callbacks = callbacks or ()
        self.dde_system = jitcdde_input(
            f_sym=derivatives,
            input=inputs,
            helpers=helpers,
            n=len(derivatives),
            max_delay=max_delay,
            callback_functions=callbacks,
        )
        if use_open_mp:
            logging.info("Using OpenMP parallelisation...")
            compiler_args = ["-fopenmp"]
            if platform == "darwin":
                logging.warning(
                    "MacOS detected. For openMP parallelisation the llvm and "
                    "libomp must be installed. If not, install them please "
                    "with `brew install llvm libomp` and follow steps for "
                    "prepending system path with llvm path.")
                linker_args = ["-lomp", "-L/usr/local/opt/llvm/lib"]
            else:
                linker_args = ["-lgomp"]
            omp_flags = (compiler_args, linker_args)
        else:
            omp_flags = False

        logging.info("Compiling to C...")
        self.dde_system.compile_C(
            simplify=False,
            do_cse=False,
            extra_compile_args=self.extra_compile_args,
            omp=omp_flags,
            chunk_size=chunksize,
            verbose=False,
        )
Ejemplo n.º 4
0
    def test_input(self):
        combos = [
            combo for l in range(1, n) for combo in combinations(range(n), l)
        ]

        for combo in np.random.choice(combos, 3, replace=False):
            combo = [3, 5]
            substitutions = {y(i): input(i) for i in combo}
            f_input = [expression.subs(substitutions) for expression in f]
            DDE = jitcdde_input(f, self.result)
            DDE.set_integration_parameters(**test_parameters)
            DDE.compile_C(extra_compile_args=compile_args)
            DDE.add_past_points(get_past_points())
            value = DDE.integrate(T)
            assert_allclose(value, y_10_ref)
Ejemplo n.º 5
0
 def _init_load_compiled(
     self,
     compiled_dir,
     derivatives,
     helpers=None,
     inputs=None,
     max_delay=0.0,
     callbacks=None,
 ):
     """
     Initialise DDE system and load from compiled.
     """
     logging.info("Setting up the DDE system...")
     compiled_filename = os.path.join(compiled_dir, f"{self.label}.so")
     assert os.path.exists(compiled_filename)
     self.dde_system = jitcdde_input(
         f_sym=derivatives,
         input=inputs,
         helpers=helpers,
         n=len(derivatives),
         max_delay=max_delay,
         callback_functions=callbacks,
         module_location=compiled_filename,
     )