DEV Community

Cover image for Born from the Quantization of Generative AI: I Released a Python Library That Quantizes Progress Bars [Zero Practicality]
FlatBone
FlatBone

Posted on

Born from the Quantization of Generative AI: I Released a Python Library That Quantizes Progress Bars [Zero Practicality]

Hey there! Quick question—do you know what quantization is?

In the world of generative AI, quantization means shrinking the size of an AI model without tanking its accuracy. Pretty neat, right?

quantization

So, while pondering quantization, a wild thought hit me:

This model quantization… the progress isn’t moving at all

Modern heavyweight models are absolute chonkers—they act like users have infinite resources or something!

never ending

Progress that never ends

When the progress bar refuses to budge, it stops being fun.

If AI gets to enjoy quantization, shouldn’t the progress bar get quantized too during the wait?

And in a fancier way, no less.

A Fancier Way?

The best way to tackle a confusing concept is to throw an even more confusing concept at it.

Speaking of confusing quantum stuff…

Quantum Mechanics, Anyone?

What’s Quantum Mechanics?

Quantum mechanics can describe many systems that classical physics cannot. Classical physics can describe many aspects of nature at an ordinary (macroscopic and (optical) microscopic) scale, but is not sufficient for describing them at very small submicroscopic (atomic and subatomic) scales. Most theories in classical physics can be derived from quantum mechanics as an approximation, valid at large (macroscopic/microscopic) scale.

Features common across versions of the Copenhagen interpretation include the idea that quantum mechanics is intrinsically indeterministic, with probabilities calculated using the Born rule, and the principle of complementarity, which states that objects have certain pairs of complementary properties that cannot all be observed or measured simultaneously. Moreover, the act of "observing" or "measuring" an object is irreversible, and no truth can be attributed to an object except according to the results of its measurement (that is, the Copenhagen interpretation rejects counterfactual definiteness).

Yup, I’m already lost.

But for those of us staring at progress bars like hawks, it’s perfect.

Quantumizing the Progress Bar (quantum-progress-bar)

So, I went ahead and released a Python library: quantum-progress-bar.

https://github.com/FlatBone/quantum-progress-bar

Now you can use a progress bar that changes every time you look at it!

gif

quantum-progress-bar4

Installation

Install it in a Python-ready environment:

pip install quantum-progress-bar
Enter fullscreen mode Exit fullscreen mode

Basic Usage

Check out the details in README.md.

Here’s the basic gist:

from quantum_progress_bar import quantum_progress

quantum_progress(total=100, width=50, delay=0.2)
Enter fullscreen mode Exit fullscreen mode

The output’s random every time. It might look like this (and yes, it actually finishes):

[▓▒░█▄▌        ] 42%  # First peek
[█▄▌▓▒         ] 38%  # Time reversal, oops
[█▓▒░█▄▌▓█....█] 100%  # Miraculous collapse
Enter fullscreen mode Exit fullscreen mode

For a more serious vibe, use the class-based approach:

from quantum_progress_bar import QuantumProgressBar

pb = QuantumProgressBar(total_steps=100)
for _ in range(10):
    pb.quantum_progress()
    print(f" Time remaining: {pb.uncertainty_estimate()}")
Enter fullscreen mode Exit fullscreen mode

The remaining time might say stuff like “5 minutes (probably between 3 minutes - 12 minutes)” or, occasionally, “42 light years ± uncertainty principle”.

Quantum entanglement

Quantum entanglement can also be eobserved

from quantum_progress_bar import QuantumProgressBar, quantum_progress, quantum_loading, qqdm
import time

# Entangle with another progress bar
pb = QuantumProgressBar(total_steps=100)
for _ in range(10):
    pb.quantum_progress()
    print(f" Time remaining: {pb.uncertainty_estimate()}")

pb2 = QuantumProgressBar(total_steps=100)
pb.entangle(pb2)
pb.update(steps=10)  # Affects both bars due to entanglement
pb.quantum_progress(width=50)
print()
pb2.quantum_progress(width=50)
print()
Enter fullscreen mode Exit fullscreen mode

Using It Like tqdm

Want a tqdm-style iterator? Import qqdm:

from quantum_progress_bar import qqdm

for i in qqdm(range(200)):
    time.sleep(0.01)
Enter fullscreen mode Exit fullscreen mode

qqdm

Quick Play Code

from quantum_progress_bar import QuantumProgressBar, quantum_progress, quantum_loading, qqdm
import time

print("🔬 Quantum Progress Bar Demo 🔬")
print("=" * 50)

print("\n1. Basic usage of quantum progress bar")
print("-" * 30)
# Display a quantum progress bar
quantum_progress(total=100, width=50, delay=0.1)

print("\n2. Direct usage of QuantumProgressBar class")
print("-" * 30)
# Initialize a quantum progress bar
pb = QuantumProgressBar(total_steps=1000, collapse_factor=0.7, uncertainty_level=0.9)

# Display progress
for _ in range(5):
    progress = pb.quantum_progress(width=50)
    print(f" Estimated time: {pb.uncertainty_estimate()}")
    time.sleep(0.1)

print("\n3. Quantum entanglement")
print("-" * 30)
# Entangle with another progress bar
pb2 = QuantumProgressBar(total_steps=100)
pb.entangle(pb2)
pb.update(steps=10)  # Affects both bars due to entanglement
pb.quantum_progress(width=50)
print()
pb2.quantum_progress(width=50)
print()

print("\n4. Quantum loading animation")
print("-" * 30)
quantum_loading(message="Loading quantum state", duration=10, width=50)

print("\n5. Usage of qqdm function like tqdm")
print("-" * 30)
print("Example of wrapping an iterator:")
for i in qqdm(range(200)):
    # Some processing
    time.sleep(0.05)

print("\nExample of using as a context manager:")
with qqdm(total_steps=20) as qbar:
    for i in range(20):
        # Some processing
        time.sleep(0.05)
        qbar.update(1)

print("\nThank you for enjoying the quantum progress display!")
Enter fullscreen mode Exit fullscreen mode

Cline

I leaned heavily on Cline for the implementation—Claude 3.7 Sonnet, to be exact. Cost me about a buck. Writing the README first might’ve been the smart move.

Practicality

It’s great for processes where you want the progress to stay vague.

Or maybe use it to show non-engineers that “Whoa, this program is working super hard!!”

References

Some legendary references:

Links

The README’s just as goofy, so give it a peek!

https://github.com/FlatBone/quantum-progress-bar

API Trace View

How I Cut 22.3 Seconds Off an API Call with Sentry

Struggling with slow API calls? Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay