-
Notifications
You must be signed in to change notification settings - Fork 40
Make Hashing Algorithm Faster (but dumber) #4
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
base: main
Are you sure you want to change the base?
Conversation
implemented parallelism and threw more cores at the problem, each parallel thread is much slower, but more cores are more cores n=10 benchmark for the parallelism run: PS C:\Users\georg\orig_cubes> python.exe .\paralel.py --no-cache 10 |
Very nice :) I'm fairly happy with these kinds of optimisations, with only a few caveats right now:
|
that's fair, depending on how things go (I suspect this should calm down eventually once the obvious ideas have been had and implemented) it might be worth spinning up another repo for people to colab in which is separate to this one linked in the video, appointing some maintainers, and muting it, then you can let the community drive it and we can stop spamming you :) for now i'm going to keep working on this in my own repo, but wont be posting anything else here except for the npy files to hopefully give you a bit of peace. |
This is a great idea! I may do this tomorrow if I have time :) |
cubes.py
Outdated
data = 0 | ||
for part in pack_cube: | ||
data = (data << 8) + int(part) | ||
out = (data * 100000) + (polycube.shape[0] * 1000) + (polycube.shape[1] * 10) + (polycube.shape[2]) # add volume dimensions to lower bits of hash |
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.
Doesn't this break on dimensions above 10? for the shape[2]
component?
As this can collide with shape[] = 11, 11, 11
generating
xxxxxxxx011121
instead of
xxxxxxxx111111
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, yes, I was intending for it to be 3 digits per dimension so that there would be plenty of space, since unless theirs a breakthrough somewhere n>99 is completely infeasible, just got my math's very wrong.
in reality though the chance of collision at these very high sizes is vanishingly small in fact there where no collisions for n=12 or n=13, but I will fix in in my next run, and this definitely needs to be fixed before this ever gets merged (if it ever does).
I've created a new repo here: https://github.com/mikepound/opencubes Are you interested in helping maintain this? Github seems to have adapted their UI again - I don't use it much. I think I invite people as collaborators first, then promote to maintainer? |
happy to maintain this, though I fear my usefulness is coming to an end, the scaling memory costs are already becoming a hinderance to my changes at n=14. |
also yes once you have invited someone as a collaborator you should be able to set their permissions, though i'm used to private repos on github business and am not sure if their is some arbitrary limits on open projects. |
Oddly it doesn't seem to have any permissions at all, could simply be free vs paid features. I think you have access, so maybe worth pushing something and seeing if it works! |
I can confirm I can push, the real question will come when a pull request or issue comes up, I will see what my options are there. |
returning the array + dimensions in byte format (as opposed to shifting bits) makes this about 15% or so faster
|
development of this is now continuing over at https://github.com/mikepound/opencubes |
Hi just wanted to contribute with the first of a few optimizations I have made.
Please let me know if you actually want this kind of contribution before I raise more of these, namely I will be focusing on more runtime optimizations and parallelism than on the pure math's question of how to sort out the cube rotations.
as such this isn't a pure math optimization, in fact it technically creates more data, but it does more of the work in numpy in C and so is much quicker.
instead of hashing with your RLE, we convert the bits straight into unsigned ints with np.packbits, then we concatenate these ints into a single python int object for the hash.
finally, we add the dimensions of the array to the lowest part of the integer so we don't lose that information.
benchmark attached for n=10 (absolute time is irrelevant as hardware dependent but their is a 2x speedup from the old code)
PS C:\Users\georg\orig_cubes> python.exe .\cubes.py --no-cache 10
Generating polycubes n=3: 100%
Generating polycubes n=4: 100%
Generating polycubes n=5: 100%
Generating polycubes n=6: 100%
Generating polycubes n=7: 100%
Generating polycubes n=8: 100%
Generating polycubes n=9: 100%
Generating polycubes n=10: 100%
Found 346543 unique polycubes
Elapsed time: 450.932s
PS C:\Users\georg\orig_cubes> python.exe .\improved_hash.py --no-cache 10
Generating polycubes n=3: 100%
Generating polycubes n=4: 100%
Generating polycubes n=5: 100%
Generating polycubes n=6: 100%
Generating polycubes n=7: 100%
Generating polycubes n=8: 100%
Generating polycubes n=9: 100%
Generating polycubes n=10: 100%
Found 346543 unique polycubes
Elapsed time: 230.274s
unfortunately since this is speeding up hashing itself not the searches, it will only be a linear speed up so will only push us slightly higher on maximum N.