Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3D generation in broken #373

Closed
Falfat opened this issue Jan 27, 2025 · 4 comments
Closed

3D generation in broken #373

Falfat opened this issue Jan 27, 2025 · 4 comments
Assignees
Labels
bug Something isn't working duplicate This issue or pull request already exists question Further information is requested

Comments

@Falfat
Copy link

Falfat commented Jan 27, 2025

I have tried to run all the examples provided for generating 3D random samples, and they all returned same error below

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[48], line 2
      1 model = Gaussian(dim=3, var=3, len_scale=1.5)
----> 2 srf = SRF(model, mean=(0.5, 0, 0), generator="VectorField", seed=198412031)

File ~\AppData\Local\Programs\Python\Python38\lib\site-packages\gstools\field\srf.py:100, in SRF.__init__(self, model, mean, normalizer, trend, upscaling, generator, **generator_kwargs)
     98 # initialize attributes
     99 self.upscaling = upscaling
--> 100 self.set_generator(generator, **generator_kwargs)

File ~\AppData\Local\Programs\Python\Python38\lib\site-packages\gstools\field\srf.py:161, in SRF.set_generator(self, generator, **generator_kwargs)
    159 if generator in GENERATOR:
    160     gen = GENERATOR[generator]
--> 161     self._generator = gen(self.model, **generator_kwargs)
    162     self.value_type = self._generator.value_type
    163 else:

File ~\AppData\Local\Programs\Python\Python38\lib\site-packages\gstools\field\generator.py:395, in IncomprRandMeth.__init__(self, model, mean_velocity, mode_no, seed, verbose, sampling, **kwargs)
    391 if model.dim < 2 or model.dim > 3:
    392     raise ValueError(
    393         "Only 2D and 3D incompressible fields can be generated."
    394     )
--> 395 super().__init__(model, mode_no, seed, verbose, sampling, **kwargs)
    397 self.mean_u = mean_velocity
    398 self._value_type = "vector"

File ~\AppData\Local\Programs\Python\Python38\lib\site-packages\gstools\field\generator.py:108, in RandMeth.__init__(self, model, mode_no, seed, verbose, sampling, **kwargs)
    106 self.sampling = sampling
    107 # set model and seed
--> 108 self.update(model, seed)

File ~\AppData\Local\Programs\Python\Python38\lib\site-packages\gstools\field\generator.py:174, in RandMeth.update(self, model, seed)
    172 self._model = dcp(model)
    173 if seed is None or not np.isnan(seed):
--> 174     self.reset_seed(seed)
    175 else:
    176     self.reset_seed(self._seed)

File ~\AppData\Local\Programs\Python\Python38\lib\site-packages\gstools\field\generator.py:242, in RandMeth.reset_seed(self, seed)
    238     rad = self._rng.sample_dist(
    239         size=self._mode_no, pdf=pdf, cdf=cdf, ppf=ppf, a=0
    240     )
    241 else:
--> 242     rad = self._rng.sample_ln_pdf(
    243         ln_pdf=self.model.ln_spectral_rad_pdf,
    244         size=self._mode_no,
    245         sample_around=1.0 / self.model.len_rescaled,
    246     )
    247 # get fully spatial samples by multiplying sphere samples and radii
    248 self._cov_sample = rad * sphere_coord

File ~\AppData\Local\Programs\Python\Python38\lib\site-packages\gstools\random\rng.py:98, in RNG.sample_ln_pdf(self, ln_pdf, size, sample_around, nwalkers, burn_in, oversampling_factor)
     96 initial_state = State(burn_in_state, copy=True)
     97 initial_state.random_state = self.random.get_state()
---> 98 sampler.run_mcmc(initial_state=initial_state, nsteps=sample_size)
     99 samples = sampler.get_chain(flat=True)[:, 0]
    101 # choose samples according to size

File ~\AppData\Local\Programs\Python\Python38\lib\site-packages\emcee\ensemble.py:450, in EnsembleSampler.run_mcmc(self, initial_state, nsteps, **kwargs)
    447     initial_state = self._previous_state
    449 results = None
--> 450 for results in self.sample(initial_state, iterations=nsteps, **kwargs):
    451     pass
    453 # Store so that the ``initial_state=None`` case will work

File ~\AppData\Local\Programs\Python\Python38\lib\site-packages\emcee\ensemble.py:386, in EnsembleSampler.sample(self, initial_state, log_prob0, rstate0, blobs0, iterations, tune, skip_initial_state_check, thin_by, thin, store, progress, progress_kwargs)
    384     checkpoint_step = thin_by
    385     if store:
--> 386         self.backend.grow(iterations, state.blobs)
    388 # Set up a wrapper around the relevant model functions
    389 if self.pool is not None:

File ~\AppData\Local\Programs\Python\Python38\lib\site-packages\emcee\backends\backend.py:175, in Backend.grow(self, ngrow, blobs)
    173 self._check_blobs(blobs)
    174 i = ngrow - (len(self.chain) - self.iteration)
--> 175 a = np.empty((i, self.nwalkers, self.ndim), dtype=self.dtype)
    176 self.chain = np.concatenate((self.chain, a), axis=0)
    177 a = np.empty((i, self.nwalkers), dtype=self.dtype)

TypeError: 'float' object cannot be interpreted as an integer
@Falfat
Copy link
Author

Falfat commented Jan 27, 2025

Image

@MuellerSeb
Copy link
Member

This is the exact same issue as this: #183
Which was solved in GSTools v1.3.2 here: #184

Do you use an old version of GSTools? If this is intended, use emcee with a version <3.1.

@MuellerSeb MuellerSeb self-assigned this Jan 27, 2025
@MuellerSeb MuellerSeb added bug Something isn't working duplicate This issue or pull request already exists question Further information is requested labels Jan 27, 2025
@LSchueler
Copy link
Member

@Falfat could you solve your problem?

@Falfat
Copy link
Author

Falfat commented Jan 29, 2025

Yes, I did. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants