-
Notifications
You must be signed in to change notification settings - Fork 197
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
Model objects returned in inconsistent order #4007
Comments
May #2010 from 2015 is related to this, although it is about specific object type. |
Without checking deep in the bowels of Workspace, I would speculate that model keeps a kind of map (multimap if I recall anything...) of objects, the key being the handle, and that's why adding objects and retrieving them will produce different results: the handle is generated at object creating in a pseudo random fashion. I would not like to suffer any performance penalty just to make this consistent. If you care about it, then just do your own sort when you retrieve, similar to what I've done for the OpenStudio-resources tests generally speaking (adding an HVAC System to the first zone encountered is very problematic there since adding it to the core zone versus one of the perimiter obviously produces different EUI results...) # In order to produce more consistent results between different runs,
# we sort the zones by names
zones = model.getThermalZones.sort_by{|z| z.name.to_s} |
@jmarrec I see your point about performance hit. I also confirmed if I use a non empty model and loop through it I get the objects in the same order. SO maybe this is just a documentation task for measure writing guide, as well as supporting gems like extension gem and openstudio standards. @asparke2 and @mdahlhausen, @kflemin looked at this in much of extension gem, and I'm going to work on some additional files. May want do this in OS standards for next release if it isn't already done. |
Most of the time I have found that sorting doesn't matter inside measures. However, for openstudio-standards, there were issues with the tests being nondeterministic. My solution was to just always call |
@asparke2 good to know that is already done in standards, we are working on extension gem. now. |
I'm just going to add link to PAT issue with non-deterministic failures on ZEDG K12 PAT project. I need to test more to see if it is just on one computer, or all windows. Doesn't happen to me on mac. This may be unrelated to this but just wanted to reference it as different case from URBANopt. |
OpenStudio/src/utilities/idf/Workspace_Impl.hpp Lines 515 to 527 in 8acc938
OpenStudio/src/utilities/idf/Workspace.cpp Lines 369 to 388 in 8acc938
|
OpenStudio/src/utilities/idf/Workspace.cpp Lines 235 to 268 in 8acc938
|
OpenStudio/src/model/Model.hpp Lines 280 to 315 in 8acc938
OpenStudio/src/model/Model_Common_Include.i Line 221 in 8acc938
I suppose we could have An alternative is to just call std::sort within getConcreteModelObjects
|
… Hoping to be able to quickly do benchmarks in ruby.
@asparke2 @DavidGoldwasser I opened #4010 after finally getting the tweaks right. I left the possibility of doing it as usual or provide a bool argument to sort, as When CI is done building, we'll have an installer ready to benchmark the impact of sorting on large models, as which point we could decide to make the sorted version default (or the unique option for that matter). Could you do some benchs/testing @DavidGoldwasser please? |
@jmarrec Thanks for looking into this. If there is an installer I can do test on a large model with maybe 2-3k surfaces and 400 zones. I can test maybe 3 different ways. Let me know if I'm missing anything
Would we default the argument to |
Yeah I think the performance is critical in deciding either/or. CI is done for mac, if you don't have access to Jenkins to find the link, here is the binary link https://openstudio-ci-builds.s3-us-west-2.amazonaws.com/incremental/develop/4010/OpenStudio-3.0.1-beta+a00998ed6e-Darwin.dmg If you can actually start by testing whether it does fix the order consistency issue that'd be great, as I'm not 100% sure. |
If it actually preserved the order that objects were added to the model, I could see that being a useful default. But it looks like it's simply using a somewhat arbitrary sorting order ( |
I am doubtful the performance impact will be extremely small. There is a reason we went to |
I was initially planning on running a measure test on large (400 zone 3k surface) model that reports out time before and after sorting operation. Maybe in the measure I'll make it get and sort objects 10x-20x times to make it easier to evaluate the time? I'm sure there is a more robust way with profiling software. Can anyone else download the mac installer in @jmarrec's link. I'm getting an error when I try to download it. |
@jmarrec sorry for confusion on the download. The "+" in the URL has to be replaced with "%2B". If I run the same ruby code in the measure test as before, it doesn't sort. How do I add the bool, I tried to use
|
@DavidGoldwasser That's probably an indication that I failed at tweaking the SWIG stuff... I tested with |
I just rebuilt #4010 and it appears to work as expected...
|
Here's a stupid benchmark:
Running with a debug build (which is what I have handy right now... I will be building Release next), there is a significant difference
|
Wow. Take the same 1000 zones and 1000 spaces model. Now do this
|
my current solution will not produce the order of the object as they were added. That would require doing something similar to this:
As seen above, the call to the sorted method will incur a huge penalty cost though. I'll wait for the Release build to be done before I do more tests |
#4007 - Model objects returned in inconsistent order
Revert "#4007 - Model objects returned in inconsistent order"
#4007 - Try to expose the `sorted` argument in ruby. Not working yet. Hoping to be able to quickly do benchmarks in ruby. Still not working ok I think I finally got it. the optional arg is on the ruby side, defined in the block for the define_method
Issue overview
When same measure is run multiple times output various if all calls for model objects are not explicitly sorted. While oder of IDF file does not matter, complex measures can have different behavior based on order changes which in turn changes the IDF and simulation results. This results in results in non deterministic results from CI.
Current Behavior
Below is the output from two measure test runs that makes and then returns 10 spaces.
https://github.com/DavidGoldwasser/measure_sandbox/tree/osm_object_return_order/create_and_report_model_objects
Run A:
The building finished with 10 spaces.
INFO MESSAGES
Space 1 was added.
Space 2 was added.
Space 3 was added.
Space 4 was added.
Space 5 was added.
Space 6 was added.
Space 7 was added.
Space 8 was added.
Space 9 was added.
Space 10 was added.
Space 9 is in the model.
Space 6 is in the model.
Space 5 is in the model.
Space 4 is in the model.
Space 7 is in the model.
Space 3 is in the model.
Space 10 is in the model.
Space 8 is in the model.
Space 2 is in the model.
Space 1 is in the model.
Run B:
INFO MESSAGES
Space 1 was added.
Space 2 was added.
Space 3 was added.
Space 4 was added.
Space 5 was added.
Space 6 was added.
Space 7 was added.
Space 8 was added.
Space 9 was added.
Space 10 was added.
Space 9 is in the model.
Space 8 is in the model.
Space 6 is in the model.
Space 4 is in the model.
Space 5 is in the model.
Space 10 is in the model.
Space 7 is in the model.
Space 3 is in the model.
Space 2 is in the model.
Space 1 is in the model.
Expected Behavior
I don't necessarily expect the spaces to be returned in order 1-10 but it would be nice if they were returned in the same order in multiple runs. Without this it may be necessary to always sort when requesting any objects to avoid non-deterministic testing and simulation results. I demonstrated this with spaces but I believe happens with any object type. I have not but can test seed model that already has spaces instead of adding them in the measure.
Steps to Reproduce
Run measure test
https://github.com/DavidGoldwasser/measure_sandbox/blob/osm_object_return_order/create_and_report_model_objects/tests/create_and_report_model_objects_test.rb
Possible Solution
Always sort when object is requested, or find another way to assure order is deterministic. For example using UUID of object would not be good as that isn't deterministic.
Details
Environment
Some additional details about your environment for this issue (if relevant):
Context
Creating complications in variation of simulation results and complications in CI.
The text was updated successfully, but these errors were encountered: