# Path: fastpm/state.py
# class StateVector(object):
#     def __init__(self, cosmology, species, comm):
#         """ A state vector is a dict of Species """
#         self.cosmology = cosmology
#         self.species = OrderedDict(sorted(species.items(), key=lambda t: t[0]))
#         self.comm = comm
#         self.a = dict(S=None, P=None, F=None)
# 
#     def __getitem__(self, spname):
#         return self.species[spname]
# 
#     def __iter__(self):
#         return iter(self.species)
# 
#     def __contains__(self, name):
#         return name in self.species
# 
#     def copy(self):
#         vc = {}
#         for k, v in self.species.items():
#             vc[k] = v.copy()
#         return StateVector(self.cosmology, vc, self.comm)
# 
#     def to_catalog(self, **kwargs):
#         from nbodykit.lab import MultipleSpeciesCatalog
#         names = []
#         sources = []
# 
#         for spname, sp in self.species.items():
#             sources.append(sp.to_catalog())
#             names.append(spname)
# 
#         cat = MultipleSpeciesCatalog(names, *sources, **kwargs)
#         return cat
# 
#     def save(self, filename, attrs={}):
#         from bigfile import FileMPI
#         a = self.a['S']
#         with FileMPI(self.comm, filename, create=True) as ff:
#             with ff.create('Header') as bb:
#                 keylist = ['Om0', 'Tcmb0', 'Neff', 'Ob0', 'Ode0']
#                 if getattr(self.cosmology, 'm_nu', None) is not None:
#                     keylist.insert(3,'m_nu')
#                 for key in keylist:
#                     bb.attrs[key] = getattr(self.cosmology, key)
#                 bb.attrs['Time'] = a
#                 bb.attrs['h'] = self.cosmology.H0 / H0 # relative h
#                 bb.attrs['RSDFactor'] = 1.0 / (H0 * a * self.cosmology.efunc(1.0 / a - 1))
#                 for key in attrs:
#                     try:
#                         #best effort
#                         bb.attrs[key] = attrs[key]
#                     except:
#                         pass
# 
#             for k, v in sorted(self.species.items()):
#                 v.save(filename, k)
# 
# class Matter(Species):
#     def Omega(self, a):
#         return self.cosmology.Om(z=1. / a - 1)
# 
# class Baryon(Species):
#     def Omega(self, a):
#         return self.cosmology.Ob(z=1. / a - 1)
# 
# class CDM(Species):
#     def Omega(self, a):
#         return self.cosmology.Odm(z=1. / a - 1)
# 
# class NCDM(Species):
#     def Omega(self, a):
#         # FIXME: using Omega_ncdm after switching to new nbodykit cosmology.
#         return self.cosmology.Onu(z=1. / a - 1)


from fastpm.state import StateVector, Matter, Baryon, CDM, NCDM
from runtests.mpi import MPITest
from nbodykit.cosmology import Planck15 as cosmo
import numpy


BoxSize = 100.
Q = numpy.zeros((100, 3))

@MPITest([1, 4])
def test_create(comm):


# Path: fastpm/state.py
# class StateVector(object):
#     def __init__(self, cosmology, species, comm):
#         """ A state vector is a dict of Species """
#         self.cosmology = cosmology
#         self.species = OrderedDict(sorted(species.items(), key=lambda t: t[0]))
#         self.comm = comm
#         self.a = dict(S=None, P=None, F=None)
# 
#     def __getitem__(self, spname):
#         return self.species[spname]
# 
#     def __iter__(self):
#         return iter(self.species)
# 
#     def __contains__(self, name):
#         return name in self.species
# 
#     def copy(self):
#         vc = {}
#         for k, v in self.species.items():
#             vc[k] = v.copy()
#         return StateVector(self.cosmology, vc, self.comm)
# 
#     def to_catalog(self, **kwargs):
#         from nbodykit.lab import MultipleSpeciesCatalog
#         names = []
#         sources = []
# 
#         for spname, sp in self.species.items():
#             sources.append(sp.to_catalog())
#             names.append(spname)
# 
#         cat = MultipleSpeciesCatalog(names, *sources, **kwargs)
#         return cat
# 
#     def save(self, filename, attrs={}):
#         from bigfile import FileMPI
#         a = self.a['S']
#         with FileMPI(self.comm, filename, create=True) as ff:
#             with ff.create('Header') as bb:
#                 keylist = ['Om0', 'Tcmb0', 'Neff', 'Ob0', 'Ode0']
#                 if getattr(self.cosmology, 'm_nu', None) is not None:
#                     keylist.insert(3,'m_nu')
#                 for key in keylist:
#                     bb.attrs[key] = getattr(self.cosmology, key)
#                 bb.attrs['Time'] = a
#                 bb.attrs['h'] = self.cosmology.H0 / H0 # relative h
#                 bb.attrs['RSDFactor'] = 1.0 / (H0 * a * self.cosmology.efunc(1.0 / a - 1))
#                 for key in attrs:
#                     try:
#                         #best effort
#                         bb.attrs[key] = attrs[key]
#                     except:
#                         pass
# 
#             for k, v in sorted(self.species.items()):
#                 v.save(filename, k)
# 
# class Matter(Species):
#     def Omega(self, a):
#         return self.cosmology.Om(z=1. / a - 1)
# 
# class Baryon(Species):
#     def Omega(self, a):
#         return self.cosmology.Ob(z=1. / a - 1)
# 
# class CDM(Species):
#     def Omega(self, a):
#         return self.cosmology.Odm(z=1. / a - 1)
# 
# class NCDM(Species):
#     def Omega(self, a):
#         # FIXME: using Omega_ncdm after switching to new nbodykit cosmology.
#         return self.cosmology.Onu(z=1. / a - 1)


# Path: fastpm/tests/test_state.py
from fastpm.state import StateVector, Matter, Baryon, CDM, NCDM
from runtests.mpi import MPITest
from nbodykit.cosmology import Planck15 as cosmo
import numpy



BoxSize = 100.
Q = numpy.zeros((100, 3))

@MPITest([1, 4])
def test_create(comm):


    matter = Matter(cosmo, BoxSize, Q, comm)