-
Notifications
You must be signed in to change notification settings - Fork 34
Better Memory Management #43
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
Conversation
* don't make a copy of every string, module and object, instead use the same object * TODO: need to make copies as needed in `setSuns()` see SunPower#34
* use copy instead of deepcopy reduce unnecessary new objects * make new strings and modules if irradiance is dictionary * make new cells if given list of cells and irradiance, if given new irradiances for all cells or new irradiances for specified cells
* fix make new cells if given all irradiance, only assign new object to a list
* remove `make_new` * add test * always copy cells even if scalar
* move comment about cells/modules back to where it was originally
…setting a whole module with one Ee.
…ell ids and Ee values.
|
additional improvements on Mark's work:
|
|
Object sizes for 20 string by 20 module system with PCT492 cells, npts=1001:
For reference, before the changes made in gh34-35 a fresh system of this size would take >10GB. Finally, nosetests ran in 5.12 seconds on my computer before the changes in this pull request. Now, they run in 3.88 sec. |
|
@mikofski So, what's the verdict? This seem good? |
mikofski
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think it great! Just 3-4 requests and it's good:
-
please remove that annoying
# gh34: ...comment everywhere -
change
set(self.pvcells)toold_pvcells.itervalues(), should be faster, IMO cleaner -
add
TODOto case where user uses one scalarEevalue to set the entire module, that this is unoptimize and will create a lot of unnecessary cells, but we can pursue it in a future PR -
add a test to show that if the user sets the sun on multiple cells to different irradiance, that extra cells are not created unnecessarily in this particular example (or something like it)
# set str X, mod Y cells 2 & 3 to 33%, and cell 17 to 99%, should create 2 new objects only pvsys.setSuns({X: {Y: {'Ee': (0.33, 0.33, 0.99), 'cells': (2, 3, 17)}}}) -
add
TODOto implement cleaner interface for case in 4 - ie: the same could be done with# possible "cleaner" alternative by grouping cells into tuples that match the set irradiance pvsys.setSuns({X: {Y: {'Ee': (0.33, 0.99), 'cells': [(2, 3), 17]}}})
| pvcells = PVcell(pvconst=self.pvconst) | ||
| if isinstance(pvcells, PVcell): | ||
| pvcells = [copy(pvcells) for _ in xrange(self.numberCells)] | ||
| # GH35: don't make copies, use same reference for all objects |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we remove these comments now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure thing
| else: | ||
| new_pvcells[cell_id] = old_pvcells[pvcell] | ||
| self.pvcells = new_pvcells | ||
| for pvc in set(self.pvcells): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, I think set(self.pvcells) is just old_pvcells.itervalues() right? I think that's better, probably faster (by a femto second) since the set is already calculated and it's an iterator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would consider set(self.pvcells) to be "cleaner" than old_pvcells.itervalues() because it makes it immediately clear that you are iterating over the current unique cells associated with the module. But I don't feel that strongly about it, and I see the point about it being marginally faster. I can change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, but I think we should still change it, in favor of a something that's already been evaluated, If the name is the issue, we can rename first to make it clearer:
pvcell_set = old_pvcells.itervalues() # iterator over new copies of unique cells
for pvc in pvcell_set:
do stuff ...
| pvc.Ee = Ee_idx | ||
| self.pvcells = copy(self.pvcells) # copy list first | ||
| for cell_idx, Ee_idx in enumerate(Ee): | ||
| # gh34: make new objects as needed from copies |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls remove these "gh34 ..." comments, thx!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and can we add a TODO comment here to optimize this later. it pvmod.setSuns(Ee=0.1) maybe seldom used, but I think it will unnecessarily add a lot of new cells, that could possibly be identical. Probably the exact same technique as used else where to catalog the unique cells and their new copies could be applied here in the future. You could put that in the TODO too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense
|
10-4, will do
|
|
did not mean to close the PR, that was an accident! |
|
@mikofski I'm not sure I understand request 3?
I thought the case where one scalar Ee value is used to set the entire module was already optimized. Are you talking about this section of |
… different irradiance, that extra cells are not created unnecessarily
|
@mikofski All done except the TODO in request three! |
|
I think it's this section in Not sure what I was thinking here. does this make extra unnecessary cells or modules? In general I don't like this section, why is this allowed as input? I think if user puts in `pvstring.setSuns([blah]) then pvmismatch should just puke. |
|
There is an issue or issues I can't resolve. If I run the example in the documentation quickstart with v2.3 I get a different answer than when I run it with this branch: v2.3bm-gh34-35about 1% difference. I don't think it's round off error, but I haven't had a chance to dig into it deeper. Should I merge this PR then open a new issue for this bug? |
|
OK, I figured it out. The "example" in the docs is wrong. It iterates over strings and modules, but it should only be changing the cell temperatures in string 0, module 0, not all of them. The version in this PR actually get's it correct, by accident though, because even though it does change the wrong cell temperatures initially, it changes them back since all of those cells refer to the exact same object, so and the so the 96th cell is the only one that get's set, except in string 0, module 0 which have an additional object for the cells that have 0.2 suns. |
|
Looks good. merging. I'll make any changes from my last comments before pushing a new release. I also want to update the docs and add a release robot. I think I'll bump it up to v3.0. Any suggestions what the release name should be - regional food alliteration with the letter "K" like Katmandu Ketchup? Karachi Kebobs? Kentucky Kiwi? |
|
Sweet!!! I like Kathmandu Ketchup |
Addressing issues #34 and #35