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

r.core.growToFullCore() error when loading from database #582

Closed
jasonbmeng opened this issue Feb 18, 2022 · 18 comments · Fixed by #615
Closed

r.core.growToFullCore() error when loading from database #582

jasonbmeng opened this issue Feb 18, 2022 · 18 comments · Fixed by #615
Assignees
Labels
bug Something is wrong: Highest Priority

Comments

@jasonbmeng
Copy link
Contributor

jasonbmeng commented Feb 18, 2022

Discussed with @jakehader. When loading a reactor using a case settings file, mechanical team is able to grow to full core. When loading a reactor object from a database, a runtime error is thrown when growing to full core. It appears that with the latter method, the global assembly number is set incorrectly.

Works:

import armi
o = armi.init(fName='myCaseSettings.yaml')
o.r.core.growToFullCore(cs)

Throws RuntimeError:

from armi.bookkeeping.db import databaseFactory
db = databaseFactory('myDatabaseName.h5','r')
with db:
    r = db.load(5,2)
r.core.growToFullCore(cs)
@jakehader
Copy link
Member

To fix this the database3 update global assembly number function should be called on the database load function. This is automatically done on the database interface loadState but isn't called if you just want to load a reactor with .load

@john-science john-science added bug Something is wrong: Highest Priority good first issue Good for newcomers help wanted labels Mar 1, 2022
@john-science
Copy link
Member

john-science commented Mar 1, 2022

@jasonbmeng It would really help me fix this bug if you could copy/paste the actual error / stack trace below. Thanks!

@jakehader Are you saying this is a known bug, because this line is called when loading a reactor from DB, not when normally initializing a reactor?

def updateGlobalAssemblyNum(r):
assemNum = r.core.p.maxAssemNum
if assemNum is not None:
assemblies.setAssemNumCounter(int(assemNum + 1))

@jasonbmeng
Copy link
Contributor Author

Sure thing, @john-science. Here's the stack trace when running r.core.growToFullCore(cs):

In [9]: r.core.growToFullCore(cs)
[xtra] No edge assemblies to remove
[info] Expanding to full core geometry
[err ] The assembly <radial shield outer Assembly A0155 at 013-016> in the reactor already has the name A0155.
       Cannot add <radial shield outer Assembly A0155 at 013-019>. Current assemNum is 156
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-9-0b3aa91bbdb3> in <module>
----> 1 r.core.growToFullCore(cs)

~\codes\nala\framework\armi\reactor\reactors.py in growToFullCore(self, cs)
   2138
   2139         converter = gc.ThirdCoreHexToFullCoreChanger(cs)
-> 2140         converter.convert(self.r)
   2141
   2142         return converter

~\codes\nala\framework\armi\reactor\converters\geometryConverters.py in convert(self, r)
   1345                 newAssem = copy.deepcopy(a)
   1346                 newAssem.makeUnique()
-> 1347                 r.core.add(newAssem, r.core.spatialGrid[i, j, 0])
   1348                 self._newAssembliesAdded.append(newAssem)
   1349

~\codes\nala\framework\armi\reactor\reactors.py in add(self, a, spatialLocator)
    536                 )
    537             )
--> 538             raise RuntimeError("Core already contains an assembly with the same name.")
    539         self.assembliesByName[aName] = a
    540         for b in a:

RuntimeError: Core already contains an assembly with the same name.

@jakehader
Copy link
Member

@jasonbmeng It would really help me fix this bug if you could copy/paste the actual error / stack trace below. Thanks!

@jakehader Are you saying this is a known bug, because this line is called when loading a reactor from DB, not when normally initializing a reactor?

def updateGlobalAssemblyNum(r):
assemNum = r.core.p.maxAssemNum
if assemNum is not None:
assemblies.setAssemNumCounter(int(assemNum + 1))

I am saying that I worked with Jason when he was having this issue and the load function on the database3 appears to not call that update assembly numbers (if I remember correctly now).

@john-science
Copy link
Member

john-science commented Mar 11, 2022

@jakehader @jasonbmeng

I went in to fix this bug this morning, and was unable to reproduce it.

For example, please see these unit tests where I try to reproduce the bug:

john-science@dff0977

@john-science john-science removed the bug Something is wrong: Highest Priority label Mar 13, 2022
@jakehader
Copy link
Member

jakehader commented Mar 19, 2022

Dang okay. @jasonbmeng you might need pass the problem or failing case to @john-science internally. This might be a combination of things leading to the problem then.

@terrapower terrapower deleted a comment from jeffbaylor Mar 31, 2022
@john-science john-science added bug Something is wrong: Highest Priority and removed help wanted good first issue Good for newcomers labels Apr 1, 2022
@john-science john-science self-assigned this Apr 1, 2022
@john-science
Copy link
Member

Thanks to Jeff, I was able to reproduce this bug with a database he gave me.

I will take on solving the bug. Though I still can not generate a pure-ARMI unit test that reproduces this bug. And that would obviously be helpful for both debugging and as a final test in the solution PR.

@jeffbaylor
Copy link
Contributor

John,

This test demonstrates the issue. It passes as written, throwing a RuntimeError the first two attempts and then succeeding in growing to a full core on the third attempt. This should be a pure-ARMI solution.

class TestDbFactoryGrowToFullCore(unittest.TestCase):
    def _loadAndGrow(self):
        with databaseFactory('myDatabase.h5', "r") as dbo:
            r = dbo.load(0, 0, allowMissing=True)
        r.core.growToFullCore(None)

    def testDbFactoryGrowToFullCoreError(self):
        with self.assertRaises(RuntimeError):
            self._loadAndGrow()
        with self.assertRaises(RuntimeError):
            self._loadAndGrow()
        self._loadAndGrow()

@john-science
Copy link
Member

john-science commented Apr 3, 2022

This test demonstrates the issue. It passes as written, throwing a RuntimeError the first two attempts and then succeeding in growing to a full core on the third attempt. This should be a pure-ARMI solution.

Yeah, I have various versions of this, but they pass unless provided special databases:

john-science@dff0977

Interestingly, the default ARMI test data doesn't seem to reproduce this bug. This is a 1/3 core situation:

class TestDatabaseReading(unittest.TestCase):

For example, I can generate the default H5 file used in dozens of unit tests, but the test passes without generating the error:

def test_growToFullCoreFromFactory(self):
    from armi.bookkeeping.db import databaseFactory

    db = databaseFactory(self.dbName, "r")
    with db:
        r = db.load(0, 0, allowMissing=True)

    r.core.growToFullCore(None)

So, that's fun.

@jeffbaylor
Copy link
Contributor

Have you run that test method by itself? The reason all of the mech unit tests passed was because we were loading databases many times before the process got to the one that tested the full core growth. When I run the grow to full core unit test method only, it fails. I didn't try all of our test databases, but the two I tried both exhibited this problem.

@john-science
Copy link
Member

Have you run that test method by itself? The reason all of the mech unit tests passed was because we were loading databases many times before the process got to the one that tested the full core growth. When I run the grow to full core unit test method only, it fails. I didn't try all of our test databases, but the two I tried both exhibited this problem.

Yeah, as my personal workflow goes, I am only running this one test. You can easily run one test by doing:

pytest armi/bookkeeping/tests/test_databaseInterface.py::TestDatabaseReading::test_growToFullCoreFromFactory

Just to be clear:

  1. You totally proved to me this is a real bug.
  2. I can debug with the file you gave me.

I was just hoping to simplify the process in (2) with an ARMI-only test case. And I"m a little worried that I won't be able to write a decent unit test for my PR to fix this because I haven't been able to reproduce this with a pure ARMI unit test.

@john-science
Copy link
Member

john-science commented Apr 4, 2022

So, the problem appears to be around here:

newAssem.makeUnique()

Essentially, if you run a growToFullCore() without a Case Settings file, it tries to rebuild the assemblies, and it appears to work, except it fails to name the assemblies correctly.

I have no found the bug yet. I am trying to unwind the 'load a core from a database' logical flow, to find where there is a misstep.

EDIT: And, of course, makeUnique() doesn't have any unit tests.

@john-science
Copy link
Member

So, I have a solution!

https://github.com/john-science/armi/blob/d18bd7dc05de70a4484f0e374e7f0da99ae2043e/armi/bookkeeping/db/database3.py#L1104

The only problem I'm facing right now is: I can't generate a unit test that fails for this bug. So I can't really prove that my fix works. But the fix does work for certain trial databases users have given me.

@john-science
Copy link
Member

It turns out the this fix caused some errors for a downstream project, and so I am reopening this ticket.

@john-science john-science reopened this Jun 23, 2022
@jakehader
Copy link
Member

It turns out the this fix caused some errors for a downstream project, and so I am reopening this ticket.

@john-science can you elaborate on the issue/bug now?

@jasonbmeng
Copy link
Contributor Author

I believe this issue has been fixed via #615 and can be closed.

@john-science
Copy link
Member

I believe this issue has been fixed via #615 and can be closed.

Oh has it? I thought this was still outstanding.

@john-science
Copy link
Member

Based on a conversation with Jason, this ticket appears to be complete. Hurray!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is wrong: Highest Priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants