A quantum physics effect to teach, a puzzle to build, a problem to solve, a tool to learn!
Polarizing filters are plastic films that let light shine through only in a particular direction (angle). Combining two at 90 degrees completely blocks light.
Very counterintuitively, inserting a third filter between two filters at 90 degrees allows some light shine through!
This interesting effect can only be explained with quantum physics, as brilliantly explained in this 3Blue1Brown video.
Polarizing filter films are cheap... So I wanted to create a carboard toy to demo this effect in a suprising way to my kids!
A puzzle to build
Idea is to build a puzzle around this weird effect.
I want to build a cardboard octagon with many "windows" (holes), each window covered with one polarizing filter at a certain angle, like this:
Stacking multiple such octagons on top of one another will block light in some combination of filters and not others, depending on the individual filter angles. Moreover, rotating octagons in the stack will make the "displayed pattern" change!
A problem to solve
One a set of "patterns" to display is decided, is it possible to write a program to determine the assignment of filter angles, for each "window" in each octagon, that is able to produce them all?
In principle, yes! In practice, there's an explosion in the number of possible combinations! Eg. 8 angles × 10 windows × 8 slices × 5 octagons × 8⁴ rotation combinations × 5! orderings × 5 upside-down flips is about 8 billion.
...a bit too much for simple for loops! I need a smarter approach.
A tool to learn
Google OR-Tools CP-SAT is a powerful constraint programming solver. It can be used to quickly find solutions to huge combinatorial problems - where one has to find one valid assignment to thousands of variables under thousands of constraints within billions of possible combinations (not all of which valid or optimal)!
Solvers are applicable to many problems and are not new in SUSE's tradition - eg. the zypper package manager uses libsolv to compute valid package dependency combinations, and Uyuni uses Optaplanner to compute valid subscription assignments.
CP-SAT is open source, very efficient (actually close to the state of the art in the field) and easily scriptable from Python... a very interesting target to experiment with!
Now I have an excuse to play with this!
Scope of HackWeek
Find a combination that works for a decent example, and actually cut it in cardboard and filters to try it out!
https://github.com/moio/octaopticon
This project is part of:
Hack Week 23
Activity
Comments
-
11 months ago by moio | Reply
Day 1 diary - the physical prototyping day
Spent a bit of time into producing good SVGs with Python, then printed them and tried to find dimensions that worked (one big and one small for testing).
After few iterations decided to go with octagonal stars rather than plain octagons:
Then literally hammered out holes with a 10mm punch! Worked beautifully.
Then, cut and tested positioning of filter film:
All seems good from the physical realm so far.
Next up: coding to determine per-hole filter positioning!
-
11 months ago by moio | Reply
Day 2 diary: mostly coding
CP-SAT
Learnt a lot about CP-SAT, evolved some code I had around to handle:
- a variable number of "pizzas" ("stars with filter windows")
- a variable number of "slices" ("sectors" of stars)
- a variable number of "windows" per "slice"
- a variable number of "angles" filters can be glued on
- a variable number of "images"
Difficult part today is the reordering of "pizzas" in the "pizza stack". Giving that ability makes more combinations possible, but indirection has to be dealt with in code.
Testing
The good part about this problem is that tests can trivially be randomized, so it's easy to see if produced solutions work or not.
The bad part is not all randomized problem instances have a solutions. For those who do not, CP-SAT will happily burn CPUs for hours. I added a pretty arbitrary time limit.
ChatGPT
I used ChatGPT for the scaffolding work - and was quite happy with it:
Set up a new Python 3.9 based project according to current best practices.
The project must use the ortools library from Google (note that is a wrapper around a C++ library)
Include support for: linting, dependency management, github codespace, tests, a Dockerfile, github actions on push and PR including and tests and lint, github actions for release of source archive and docker container on ghcr.io
Also include a scaffolded README and LICENSE (AGPL)
The project must compile and work cross platform, including Linux x86 and Mac arm.
Explain every file created step by step and why
Not a perfect result, but a good result to learn from - faster than stitching together 10 blog posts (for someone not daily into an ecosystem).
-
11 months ago by moio | Reply
Day 3 diary: 3 failures, 1 success
Failure 1: adding the possibility of re-ordering the stack
I thought that allowing to re-ordering pizzas in the stack could help with storing more "images" - found out that as not the case. On a large set of pseudorandom tests, only an extra 4 out of 186 could be solved by changing the order. Not worth it, commit reverted.
Failure 2: going from a SAT problem to an optimization problem
CP-SAT has the cool ability of allowing to specify an objective function to minimize or maximise - making it simple to reformulate a satisfiability problem in an optimization one. I tried this approach to make the assignments more flexible but failed: I could not find a good way to mix it with the Automaton constraints which I am using to simulate light traveling through a series of filters. Path abandoned for now.
Failure 3: allowing brighter-than-specified pixels
This seemed an easy way to enlarge the solution space - interestingly, almost no effect was visible in tests. Sticking for the simpler approach (to match pixel values exactly) for now.
Success! First small four-pizza prototype works!
I am happy to report that after some serious hammering and cutting...
...and serious gluing of filter films...
...I've got a nice filter set! Notice how filtering of monitor light (which is polarized) changes with rotation!
Now I made four pizzas...
And, in the right order, they will display a programmed X pattern!
I was able to "store" 7 patterns in the four pizzas (a "Y", a "q", the "X" above, an "o", an "I", a "c" and a "K").
Next step: the bigger brother pizza with bigger patterns!
-
11 months ago by moio | Reply
Day 4 diary: scale up!
Today I dealt with the bigger version of the puzzle. Software scaled just fine!
About hardware I was lucky enough to get help from my son across all phases!
I am really happy with the result, here they are in all their whiteness:
What message did we hid in there? Stay tuned tomorrow for the last demo!
PS. Thanks to colleague AR about having kids do some of the job - that worked great!
-
11 months ago by moio | Reply
Day 5 diary: it's a wrap!
Today I created a video to explain progress and results, enjoy!
Tricky part was to get light right - so that it was clearly visible on video. Ended up with an inverted laptop screen covered with an opaque film - otherwise light comes polarized and all behavior is totally different!
Similar Projects