Skip to content

Commit

Permalink
Refactor all Python code so that tests pass with new extensions location
Browse files Browse the repository at this point in the history
  • Loading branch information
rpep committed May 10, 2019
1 parent f8b6107 commit 22ceb97
Show file tree
Hide file tree
Showing 32 changed files with 108 additions and 217 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
*.pdf
*.tmp
*.so
*.o
*.dSYM
fidimag/**/*.cpp


local/
*~
*.bak
Expand Down
35 changes: 34 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,50 @@ EXTENSIONS_DIR = ${PROJECT_DIR}/fidimag/extensions
PYTHON = python3
PYTEST = ${PYTHON} -m pytest

CC=g++-8

FFTW_INC=local/include
FFTW_LIB=local/lib

SUNDIALS_INC=local/include
SUNDIALS_LIB=local/lib

CPPFLAGS = -fPIC -g -Iinclude/ \
-I${FFTW_INC} -L${FFTW_LIB} \
-I${SUNDIALS_INC} -L${SUNDIALS_LIB} \
-lm \
-lfftw3_omp -lfftw3 \
-lsundials_cvodes -lsundials_nvecserial -lsundials_nvecopenmp \
-lblas -llapack \
-fopenmp

LDFLAGS = -shared
SOURCES = $(shell echo native/src/*.cpp)
OBJECTS = $(SOURCES:.cpp=.o)
LIBRARY = local/lib/libfidimag.so

all: $(LIBRARY) build

$(LIBRARY) : $(OBJECTS)
$(CXX) $(CPPFLAGS) $(OBJECTS) -o $@ $(LDFLAGS)



#####################
# Cython Extensions #
#####################

build:
build: $(LIBRARY)
${PYTHON} setup.py build_ext --inplace




clean:
rm -rf ${EXTENSIONS_DIR}/*
touch ${EXTENSIONS_DIR}/__init__.py
rm -rf build
rm -rf $(OBJECTS) $(TARGET) *.dSYM

docker:
docker build -t fidimag -f ./docker/travis/Dockerfile .
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import numpy
cimport numpy as np
np.import_array()

cdef extern from "fidimag_random.h":
cdef extern from "a_random.h":
ctypedef struct mt19937_state:
pass

Expand All @@ -20,7 +20,7 @@ cdef extern from "time.h":
ctypedef int time_t
time_t time(time_t *timer)

cdef extern from "clib.h":
cdef extern from "a_clib.h":
void run_step_mc(mt19937_state *state, double *spin, double *new_spin,
int *ngbs, int *nngbs, int n_ngbs,
double J, double J1, double D, double D1,
Expand Down
2 changes: 1 addition & 1 deletion fidimag/atomistic/anisotropy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fidimag.extensions.clib as clib
import fidimag.extensions.a_clib as clib
import numpy as np
from .energy import Energy
import fidimag.common.helper as helper
Expand Down
2 changes: 1 addition & 1 deletion fidimag/atomistic/atomistic_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from fidimag.common.driver_base import DriverBase

import fidimag.extensions.clib as clib
import fidimag.extensions.a_clib as clib
import fidimag.extensions.cvode as cvode
from fidimag.common.vtk import VTK
import fidimag.common.constant as const
Expand Down
2 changes: 1 addition & 1 deletion fidimag/atomistic/demag_full.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fidimag.extensions.clib as clib
import fidimag.extensions.a_clib as clib
import numpy as np
from .energy import Energy

Expand Down
2 changes: 1 addition & 1 deletion fidimag/atomistic/dmi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fidimag.extensions.clib as clib
import fidimag.extensions.a_clib as clib
from .energy import Energy
import numpy as np

Expand Down
2 changes: 1 addition & 1 deletion fidimag/atomistic/exchange.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fidimag.extensions.clib as clib
import fidimag.extensions.a_clib as clib
import numpy as np
from .energy import Energy

Expand Down
2 changes: 1 addition & 1 deletion fidimag/atomistic/llg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import print_function

# Use the common C library for the LLG equation in the atomistic case
import fidimag.extensions.common_clib as clib
import fidimag.extensions.c_clib as clib

from .atomistic_driver import AtomisticDriver

Expand Down
3 changes: 1 addition & 2 deletions fidimag/atomistic/llg_stt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import division

import fidimag.extensions.common_clib as clib
import fidimag.extensions.c_clib as clib
import numpy as np

from .atomistic_driver import AtomisticDriver
Expand Down
2 changes: 1 addition & 1 deletion fidimag/atomistic/llg_stt_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import types

import fidimag.extensions.common_clib as clib
import fidimag.extensions.c_clib as clib
import numpy as np

from .atomistic_driver import AtomisticDriver
Expand Down
2 changes: 1 addition & 1 deletion fidimag/atomistic/monte_carlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import print_function
import os
import numpy as np
import fidimag.extensions.clib as clib
import fidimag.extensions.a_clib as clib
from fidimag.common.fileio import DataSaver
import fidimag.common.helper as helper
import fidimag.common.constant as const
Expand Down
2 changes: 1 addition & 1 deletion fidimag/atomistic/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import fidimag.common.skyrmion_number
import fidimag.common.helper as helper
import fidimag.extensions.clib as clib
import fidimag.extensions.a_clib as clib
import numpy as np

from fidimag.common.sim_base import SimBase
Expand Down
2 changes: 1 addition & 1 deletion fidimag/atomistic/sllg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import division
import numpy as np
import fidimag.extensions.clib as clib
import fidimag.extensions.a_clib as clib
import fidimag.common.helper as helper
import fidimag.common.constant as const

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import numpy as np

# -----------------------------------------------------------------------------

cdef extern from "common_clib.h":
cdef extern from "c_clib.h":

# From: llg.c
void llg_rhs(double * dm_dt, double * spin,
Expand Down
4 changes: 2 additions & 2 deletions fidimag/common/dipolar/dipolar.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ctypes
cimport numpy as np
np.import_array()

cdef extern from "dipolar.h":
cdef extern from "c_dipolar.h":
# used for demag
ctypedef struct fft_demag_plan:
int nx, ny, nz
Expand Down Expand Up @@ -186,7 +186,7 @@ cdef class FFTDemag(object):
&field[0], &energy[0])


cdef extern from "demagcoef.h":
cdef extern from "c_demagcoef.h":
double CalculateSDA00(double x, double y, double z, double dx,double dy,double dz)
double DemagNxxAsymptotic(double x, double y, double z, double dx,double dy,double dz)

Expand Down
2 changes: 1 addition & 1 deletion fidimag/common/gradient_descent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import division
import numpy as np
import fidimag.extensions.clib as clib
import fidimag.extensions.a_clib as a_clib
# import fidimag.common.constant as const

from .minimiser_base import MinimiserBase
Expand Down
10 changes: 5 additions & 5 deletions fidimag/common/helper.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from fidimag.extensions.common_clib import normalise
from fidimag.extensions.common_clib import init_scalar
from fidimag.extensions.common_clib import init_vector
from fidimag.extensions.common_clib import init_vector_func_fast
import fidimag.extensions.clib as clib
from fidimag.extensions.c_clib import normalise
from fidimag.extensions.c_clib import init_scalar
from fidimag.extensions.c_clib import init_vector
from fidimag.extensions.c_clib import init_vector_func_fast
import fidimag.extensions.a_clib as clib
import numpy as np


Expand Down
8 changes: 4 additions & 4 deletions fidimag/common/neb_method/nebm_clib.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# distutils: language = c++

cdef extern from "nebm_lib.h":
cdef extern from "c_nebm_lib.h":
void compute_tangents_C(double *tangents,
double *y,
double *energies,
Expand Down Expand Up @@ -59,7 +59,7 @@ cdef extern from "nebm_lib.h":
int n_images,
int n_dofs_image)

cdef extern from "nebm_integrators.h":
cdef extern from "c_nebm_integrators.h":
double step_Verlet_C(double * forces,
double * forces_prev,
double * velocities,
Expand Down Expand Up @@ -177,7 +177,7 @@ def compute_dYdt_nc(double [:] y,



cdef extern from "nebm_geodesic_lib.h":
cdef extern from "c_nebm_geodesic_lib.h":
double compute_geodesic_GreatCircle(double * A, double * B,
int n_dofs_image,
int * material,
Expand Down Expand Up @@ -230,7 +230,7 @@ def image_distances_GreatCircle(double [:] distances,
)


cdef extern from "nebm_spherical_lib.h":
cdef extern from "c_nebm_spherical_lib.h":
void normalise_spherical(double * a, int n)
void normalise_images_spherical_C(double * y, int n_images,
int n_dofs_image)
Expand Down
5 changes: 1 addition & 4 deletions fidimag/common/plt_helper.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
from __future__ import division
# import matplotlib as mpl
# mpl.use("Agg")
import fidimag.extensions.clib as clib
import fidimag.extensions.a_clib as clib
import numpy as np

import matplotlib.pyplot as plt
# from mpl_toolkits.mplot3d import Axes3D
from matplotlib.colors import colorConverter
from matplotlib.collections import PolyCollection

Expand Down
2 changes: 1 addition & 1 deletion fidimag/common/simple_minimiser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import division
import numpy as np
import fidimag.extensions.clib as clib
import fidimag.extensions.a_clib as clib
# import fidimag.common.constant as const

from .minimiser_base import MinimiserBase
Expand Down
6 changes: 3 additions & 3 deletions fidimag/common/skyrmion_number.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fidimag.extensions.clib
import fidimag.extensions.a_clib
import fidimag.extensions.micro_clib
import numpy as np

Expand Down Expand Up @@ -69,7 +69,7 @@ def skyrmion_number_slice(sim, at=None, zIndex=None):
spinSlice, sim._skx_number, sim.mesh.nx, sim.mesh.ny,
sim.mesh.nz, sim.mesh.neighbours)
else:
return fidimag.extensions.clib.compute_skyrmion_number(\
return fidimag.extensions.a_clib.compute_skyrmion_number(\
spinSlice, sim._skx_number, sim.mesh.nx, sim.mesh.ny,
sim.mesh.nz, sim.mesh.neighbours)

Expand Down Expand Up @@ -104,7 +104,7 @@ def skyrmion_number_lee(sim):
sim.mesh.ny, sim.mesh.nz,
sim.mesh.neighbours)
else:
skyrmionNumbers[zI] = fidimag.extensions.clib.compute_skyrmion_number(\
skyrmionNumbers[zI] = fidimag.extensions.a_clib.compute_skyrmion_number(\
spinSlice, sim._skx_number, sim.mesh.nx,
sim.mesh.ny, sim.mesh.nz,
sim.mesh.neighbours, 6)
Expand Down
4 changes: 2 additions & 2 deletions fidimag/common/steepest_descent.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import division
import numpy as np
import fidimag.extensions.common_clib as clib
import fidimag.extensions.c_clib as clib
# Change int he future to common clib:
import fidimag.extensions.clib as atom_clib
import fidimag.extensions.a_clib as atom_clib
import sys
from .minimiser_base import MinimiserBase

Expand Down
2 changes: 1 addition & 1 deletion fidimag/common/sundials/cvode.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ cdef extern from "sundials/sundials_iterative.h":



cdef extern from "../../atomistic/lib/clib.h":
cdef extern from "a_clib.h":
void normalise(double * m, int nxyz)


Expand Down
2 changes: 1 addition & 1 deletion fidimag/micro/lib/baryakhtar_clib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import numpy
cimport numpy as np
np.import_array()

cdef extern from "baryakhtar_clib.h":
cdef extern from "m_baryakhtar_clib.h":
void compute_laplace_m(double *m, double *field, double *Ms, double dx, double dy, double dz,
int nx, int ny, int nz)

Expand Down
2 changes: 1 addition & 1 deletion fidimag/micro/lib/micro_clib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
cimport numpy as np

cdef extern from "micro_clib.h":
cdef extern from "m_clib.h":
void compute_exch_field_micro(double *m, double *field,
double *energy, double *Ms_inv,
double A, double dx, double dy, double dz,
Expand Down
2 changes: 1 addition & 1 deletion fidimag/micro/llg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# We use the common/lib/llg.c file to calculate the LLG equation for
# the micromagnetic case
import fidimag.extensions.common_clib as clib
import fidimag.extensions.c_clib as clib

from .micro_driver import MicroDriver

Expand Down
2 changes: 1 addition & 1 deletion fidimag/micro/llg_stt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import division

import fidimag.extensions.common_clib as clib
import fidimag.extensions.c_clib as clib
import numpy as np

from .micro_driver import MicroDriver
Expand Down
2 changes: 1 addition & 1 deletion fidimag/micro/llg_stt_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .micro_driver import MicroDriver

import fidimag.extensions.common_clib as clib
import fidimag.extensions.c_clib as clib
import numpy as np

import fidimag.common.helper as helper
Expand Down
Loading

0 comments on commit 22ceb97

Please sign in to comment.