link to video player demoing the result

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.

Animation showing two polarizing filters blocking light at 90 degrees

Very counterintuitively, inserting a third filter between two filters at 90 degrees allows some light shine through!

Photo showing two polarizing filters blocking light at 90 degrees with one more in the middle at 45 degrees

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:

An octagon with holes

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!

An octagon stack

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 logo

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

Looking for hackers with the skills:

quantummechanics solvers python python3 ai game games puzzle

This project is part of:

Hack Week 23

Activity

  • 6 months ago: mkoutny liked this project.
  • 6 months ago: moio added keyword "quantummechanics" to this project.
  • 6 months ago: moio added keyword "solvers" to this project.
  • 6 months ago: moio added keyword "python" to this project.
  • 6 months ago: moio added keyword "python3" to this project.
  • 6 months ago: moio added keyword "ai" to this project.
  • 6 months ago: moio added keyword "game" to this project.
  • 6 months ago: moio added keyword "games" to this project.
  • 6 months ago: moio added keyword "puzzle" to this project.
  • 6 months ago: gfilippetti liked this project.
  • 6 months ago: digitaltomm liked this project.
  • 6 months ago: RDiasMateus liked this project.
  • 6 months ago: aruiz liked this project.
  • 6 months ago: moio liked this project.
  • 6 months ago: moio started this project.
  • 6 months ago: moio originated this project.

  • Comments

    • moio
      6 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:

      Various cuts and drawings and printouts

      Then literally hammered out holes with a 10mm punch! Worked beautifully.

      One printout with punched holes

      Then, cut and tested positioning of filter film:

      Filter film cut in pieces

      All seems good from the physical realm so far.

      Next up: coding to determine per-hole filter positioning!

    • moio
      6 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). add-emoji

    • moio
      6 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...

      the author hammering on cardboard

      ...and serious gluing of filter films...

      the author gluing filters on the aforementioned hammered cardboard

      ...I've got a nice filter set! Notice how filtering of monitor light (which is polarized) changes with rotation!

      pizza rotation in front of a monitor

      Now I made four pizzas...

      four pizzas ready to play

      And, in the right order, they will display a programmed X pattern!

      four pizzas stacked to display an X

      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!

    • moio
      6 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!

      phase 1: hammering phase 2: cutting phase 3: cutting filters phase 4: cutting filters

      I am really happy with the result, here they are in all their whiteness:

      phase 5: finished

      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!

    • moio
      6 months ago by moio | Reply

      Day 5 diary: it's a wrap!

      Today I created a video to explain progress and results, enjoy!

      link to video player demoing the result

      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

    SMTGCC by fkastl

    [comment]: # (Please use the project descriptio...


    Create tool to analyze supportconfig to spot common SUSE Manager / Uyuni issues by cbosdonnat

    [comment]: # (Please use the project descriptio...


    TinyTutor - an AI chat-bot powered children's tutor by dmulder

    [comment]: # (Please use the project descriptio...


    Publish two personally productive projects (preferably on github) by dmair

    Since this will be my first real "from the star...


    Cluster-Tester for SAP HANA System Replication Cluster by fmherschel

    [comment]: # (Please use the project descriptio...


    Package MONAI Machine Learning Models for Medical Applications by jordimassaguerpla

    Project Description

    MONAI Deploy aims to ...


    Play with stable diffusion AI model to generate custom avatars by STorresi

    Project Description

    Generate a personaliz...


    AI frontend to Bugzilla by paolodepa

    Project Description

    Over the years, our b...


    Implement Generative AI for SUSE Asset management (using Amazon Bedrock) by mpiala

    [comment]: # (Please use the project descriptio...


    COOTWbot by ngetahun

    [comment]: # (Please use the project descriptio...


    Port some classic game to Linux by MDoucha

    Let's pick some old classic game, reverse engin...