Git Product home page Git Product logo

Comments (7)

DevarshiChoudhury avatar DevarshiChoudhury commented on June 3, 2024 1

I had come up with the following redesign of the try-except-else block in Star.__init__:

try:
    assert isinstance(photospheres, list)
except AssertionError:
    try:
        assert isinstance(photospheres, Photosphere)
    except AssertionError:
        raise TypeError('Invalid type for a photosphere object')
    else:
        self._photospheres = [photospheres]
else:
    try:
        for photosphere in photospheres:
            assert isinstance(photosphere, Photosphere)
    except AssertionError:
        raise TypeError('Invalid type for a photosphere object')
    else:
        self._photospheres = photospheres

This ensures that it doesn't encounter these errors, and we won't have to modify user scripts and tutorials, etc. The only reason I hadn't pushed it is that even though this is a fix for the exact error message reported, this isn't the root cause of it. There is some issue with ParameterSubspace handling which causes it, when all the parameters are fixed. Using this fix, the code proceeds further but then gets stuck with a new error message:

AttributeError                            Traceback (most recent call last)
<ipython-input-6-fabd87490191> in <module>()
----> 1 main.photosphere.integrate(energies, threads=1)
      2 
      3 _ = plot_pulse()

/Users/dc1408/opt/anaconda3/envs/xpsi/lib/python2.7/site-packages/xpsi-0.7.10-py2.7-macosx-10.7-x86_64.egg/xpsi/Photosphere.pyc in integrate(self, energies, threads)
    326                                                    threads,
    327                                                    self._hot_atmosphere,
--> 328                                                    self._elsewhere_atmosphere)
    329 
    330                 if not isinstance(self._signal[0], tuple):

/Users/dc1408/opt/anaconda3/envs/xpsi/lib/python2.7/site-packages/xpsi-0.7.10-py2.7-macosx-10.7-x86_64.egg/xpsi/HotRegion.pyc in integrate(self, st, energies, threads, hot_atmosphere, elsewhere_atmosphere)
   1085                                        st.r_s,
   1086                                        st.i,
-> 1087                                        self._super_cellArea,
   1088                                        self._super_r,
   1089                                        self._super_r_s_over_r,

AttributeError: 'HotRegion' object has no attribute '_super_cellArea'

@yves mentioned that he had thought of some not-so-straightforward fix for the root cause which we can discuss and apply. I could still push the above fix in the meantime since it acts as an additional safety check regardless.

from xpsi.

DevarshiChoudhury avatar DevarshiChoudhury commented on June 3, 2024

Causes of all the issues:

The following line doesn't execute as intended:

for photosphere in photospheres:

The photosphere variable doesn't get assigned and the body of the for-loop doesn't get executed. The for statement doesn't raise a TypeError however, as it should if the object is non-iterable. No exception is subsequently raised as a result and the else body in line 41 is executed instead.

Thus self._photosphere has the same object as photospheres in the line above which runs into the same for-statement execution issue in the following line:

for photosphere in self._photospheres:

The loop body is then supposed to assign photosphere.spacetime which it never does, thereby causing the original error message posted.

@yves and I suspect that this is caused by iterable object handling in the ParameterSubspace.py. This issue isn't raised for other classes since assignment typically doesn't depend on iterating over the object as it does in Photosphere.py

from xpsi.

thjsal avatar thjsal commented on June 3, 2024

So looks like the solution is to have star = xpsi.Star(spacetime = spacetime, photospheres = [photosphere,])
instead of star = xpsi.Star(spacetime = spacetime, photospheres = photosphere) in your main file, right?

Perhaps this is the correct syntax we always should have used, but have been just lucky to not have problems caused by this when having at least some free parameters for the HotRegion object? In that case, we should probably anyway fix this in the example X-PSI scripts.

At least the old scripts seem to still work with this change in them.

from xpsi.

thjsal avatar thjsal commented on June 3, 2024

I still don't see that there would be other root causes for this issue than those lines that you fixed above. I don't see how ParameterSubspace would be responsible for this. Can you give more details if you still think that is the case?

For the new error, I understood that you get that if have also fixed all the space-time parameters. This happens because then the embed function of the photosphere is never called here (the update function of Star thinks nothing needs to be updated since everything is fixed):

if photosphere.needs_update or self._spacetime.needs_update:

To fix this, we could perhaps replace the line above with
if photosphere.needs_update or self._spacetime.needs_update or force_update:
where force_update would be an input argument used to force to do the full calculation:
def update(self, fast_counts=None, threads=1, force_update=False):
I checked that error is then avoided when calling star.update(force_update=True).

If we want that also calling and checking likelihood to work with parameters that are all fixed, looks like similar arguments really forcing X-PSI to calculate everything, should be also added to Likelihood.py in driver() and check() functions and change if self.needs_update: to if self.needs_update or force: in the call function.

from xpsi.

thjsal avatar thjsal commented on June 3, 2024

Alternatively, we could also modify needs_update() functions in ParameterSubspace.py and Parameter.py to return True instead of False, in case of all the parameters are fixed. But I guess having the power to force X-PSI to calculate all the relevant code blocks would be more useful anyway?

from xpsi.

DevarshiChoudhury avatar DevarshiChoudhury commented on June 3, 2024

Yea, I think I was hinting at the needs_update() function in ParameterSubspace.py to be the root issue here. I do agree however, that having the power to force X-PSI to compute the relevant code blocks is a better approach, and also having that power when computing likelihood. Have you already tried and tested modifying the likelihood.check and likelihood.driver?

from xpsi.

thjsal avatar thjsal commented on June 3, 2024

Yes, I tried and tested modifying those, and it worked. However, I did not yet add the new variables as input arguments to all these functions. The function descriptions also need to still be updated to explain these arguments. If you agree, I can add these to the next pull request.

from xpsi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.