nifty_config.py 3.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# -*- coding: utf-8 -*-

import os

import keepers

# Setup the dependency injector
dependency_injector = keepers.DependencyInjector(
                                   [('mpi4py.MPI', 'MPI'),
                                    'h5py',
                                    'gfft',
                                    ('nifty.dummys.gfft_dummy', 'gfft_dummy'),
                                    'healpy',
                                    'libsharp_wrapper_gl'])

dependency_injector.register('pyfftw', lambda z: hasattr(z, 'FFTW_MPI'))


# Initialize the variables
variable_fft_module = keepers.Variable(
                               'fft_module',
                               ['pyfftw', 'gfft', 'gfft_dummy'],
                               lambda z: z in dependency_injector)
# gl_space needs libsharp
variable_lm2gl = keepers.Variable(
                          'lm2gl',
                          [True, False],
                          lambda z: (('libsharp_wrapper_gl' in
                                      dependency_injector)
                                     if z else True) and isinstance(z, bool),
                          genus='boolean')

variable_use_healpy = keepers.Variable(
                          'use_healpy',
                          [True, False],
                          lambda z: (('healpy' in dependency_injector)
                                     if z else True) and isinstance(z, bool),
                          genus='boolean')

variable_use_libsharp = keepers.Variable(
                                 'use_libsharp',
                                 [True, False],
                                 lambda z: (('libsharp_wrapper_gl' in
                                             dependency_injector)
                                            if z else True) and
                                            isinstance(z, bool),
                                 genus='boolean')

variable_verbosity = keepers.Variable('verbosity',
                                      [1],
                                      lambda z: z == abs(int(z)),
                                      genus='int')


nifty_configuration = keepers.get_Configuration(
                     'NIFTy',
                     [variable_fft_module,
                      variable_lm2gl,
                      variable_use_healpy,
                      variable_use_libsharp,
                      variable_verbosity,
                      ],
                     path=os.path.expanduser('~') + "/.nifty/nifty_config")
########
### Compatibility variables
########
variable_mpi_module = keepers.Variable('mpi_module',
                                       ['MPI'],
                                       lambda z: z in dependency_injector)


nifty_configuration.register(variable_mpi_module)

# register the default comm variable as the 'mpi_module' variable is now
# available
variable_default_comm = keepers.Variable(
                     'default_comm',
                     ['COMM_WORLD'],
                     lambda z: hasattr(dependency_injector[
                                       nifty_configuration['mpi_module']], z))

nifty_configuration.register(variable_default_comm)

########
########

try:
    nifty_configuration.load()
except:
    pass