Angular Component Libraries

I’ve recently been learning to use Angular for work, building simple UI tools with it. I like the framework — different than React, but similar goal of creating re-usable components.

One neat thing with Angular 6 is the ability to create your own libraries! This was useful to me, since I was creating three similar apps with many shared UI components (i.e. a table with selectable rows). This is apparently behavior that was previously supported by a separate library, ng-packagr, and then rolled into the Angular CLI with version 6.

As of right now, though, the documentation for the feature is a bit fragmented. Most of the CLI commands to create libraries are contained in this wiki page of user stories (and otherwise briefly mentioned in various GitHub issues), and some of the details can only be found on the original ng-packagr docs. For example, I wanted to create sub-packages (or secondary entry-points), so that I could do something like:

import { MyComponent } from '@mylibrary/subpackage1';

The ability to do this is briefly mentioned in the ng-packagr docs, though not mentioned in the Angular 6 CLI page explicitly. So don’t forget to check the original documentation if there is library functionality that you’re looking for!

CLIx Wins UNESCO Award

Wow! One of my projects — the Connected Learning Initiative (CLIx) — has just won a major UNESCO prize! You can read more about it in these press releases:

It’s been amazing to watch this project grow from potential (the agreement will get signed soon) to reality (let’s start working!) to implementation (ship it to the schools) over the last five years. I’m proud to have been part of such a large ed-tech collaboration, since usually we talk about a handful of schools for a research project. Hundreds of schools and tens of thousands of students for an initial rollout boggles my mind.

Bundling macOS Applications with Platypus

So I know that Apple is pushing all app developers to the App Store, but I’ve recently been playing around with Platypus for the Connected Learning Initiative project that I’m working on. I was curious how to bundle together a macOS application, but didn’t want to go through XCode or the Apple Developer Program.

Platypus is pretty nifty because it organizes all of the files and scripts for you, into the appropriate .app folder structure. There were a couple of things that I couldn’t find in the documentation, however, that I wound up having to figure out:

Our bundle actually consists of running two executables on program launch (one that acts as an assessment engine, another as an ePub reader). However, you can only launch one script when you open the app. I wound up creating an AppleScript to open up two instances of Terminal and running one executable per instance. And apparently spaces in Terminal have to be double-forward-slash-escaped instead of single (i.e. \\ instead of the typical command line \):

echo Running ePub reader from $EPUB_READER_SCRIPT
osascript -e "tell app \"Terminal\" to do script \"$EPUB_READER_SCRIPT\""
sleep 3

echo Running assessment engine from $ASSESSMENT_ENGINE_SCRIPT
osascript -e "tell app \"Terminal\" to do script \"$ASSESSMENT_ENGINE_SCRIPT\""
sleep 3

/usr/bin/open -a "/Applications/Google" 'https://localhost:8888/'

One other challenge was finding bundled data files. I was including static files, ePubs, and JSON data files in the application bundle, since it is meant to be a standalone LMS / learning application, and I couldn’t figure out why my scripts couldn’t find the data. The Platypus documents indicate scripts in the app bundle can reference other files in the bundle relative to themselves. The directory structure inside of /Content/Resources was:

However, because I was launching new Terminal instances, the Python scripts inside of your .app bundle had the current working directory set to the user’s home directory (Terminal default). For example, in my file, os.getcwd() would return the user’s home directory (/Users/) instead of the app’s /Content/Resources directory.

I wound up having to do something like this in my

import os

ABS_PATH = os.path.dirname(os.path.abspath(__file__))

in order to find and read files relative to my main script.

Exploring Quantum Algorithms

I’ve come to realize that making the best use of quantum computing in the future requires knowledge of quantum algorithms, so I’ve been focusing the last couple of weeks on better understanding those. It’s interesting that there already exist many such quantum algorithms that take advantage of quantum mechanics. To me, it seems like quantum programming will require knowledge and experience of when to use which algorithm, like machine learning programmers need to know when it is more useful to apply different algorithms, depending on what data is available or the intended goal. I’ve been wanting to read this book by Ike, an MIT professor, so waiting for the term to end so that the library copies become available. At least I’ll make an effort to skim it…

I’ve also been reading through the IBM Jupyter notebooks on how to use their qiskit, specifically the one for optimization. In there, they talk about how you could use quantum computing to solve the traveling salesman problem, a classic one in optimization research. It’s interesting that the brute force method for N > ~20 is unsolvable on traditional computing, but if I understand the IBM notebook correctly, it could be brute-forced with (N - 1)^2 qubits — so for example, if N = 20, that would be 361 qubits. Assuming the challenges with error correction as the number of qubits increases can be overcome, that seems like it might be a year or two in the future.

Until I read the Wikipedia article on the traveling salesman problem, I also didn’t realize that people have come up with alternate algorithms that can tackle up to 85,900 cities — amazingly better than the brute force method. While using traditional computing to implement these algorithms seems CPU intensive (i.e. using a supercomputer), it also boggles my mind that to solve this on a quantum computer, you might need 84,999^2 (7.2 trillion) qubits?!?!?! Given the state of technology, that seems decades away or impossible …. it makes me wonder if there are also alternate, quantum versions of these non-brute force methods that would make the required number of qubits more realistic. Kind of like there is a quantum Fourier transform to mirror the traditional discrete Fourier transform. More reading required!

Quantum Programming Languages

So the big news today in quantum computing came from IBM — here is the MIT Technology Review’s announcement, plus Tech Crunch’s. Basically IBM has prototyped a 50-qubit machine, and they are allowing the public to use a new 20-bit machine via their QISKit library. In the past, they allowed the public to use 5-qubits and researchers to register for 17-qubit access, but now everyone will have access to 20! It will be interesting to see what additional research folks can carry out now…I recall reading that there have been ~30 papers published using the IBM system, so researchers should be able to do every more things now.

I have also been spending some time reading through the tutorial Jupyter notebooks for QISKit … wow. The library still seems to assume a strong grasp of quantum mechanics. It allows you to do things like set gates and levels in the quantum circuits, which is pretty cool. But you have to understand how to calculate the energy equation for your problem in the first place (and then, how the combination of gates defines your energy function — this, I think can be codified). I would love to see either or both of:

  • More tutorials on how to construct quantum algorithms from real-world problems. Ising what? Do I need a Ph.D. for this?
  • Libraries that abstract away the quantum weeds. So I don’t need to manipulate and set the individual gates, the possible combinations should be abstracted away by some higher-level command. I feel like this is simpler than the first bullet, honestly.

Quantum Computing — What is it?

In the last couple of weeks there have been a bunch of press releases about Microsoft’s soon-to-be-released quantum computing programming language, plus related articles from IBM, Google, and others. China is also getting press for using quantum effects to help secure satellite communication — wow!

The technology sounds fascinating, and it’s amazing that hardware and software for quantum computing is started to actually appear. I remember reading science fiction books as a child that mentioned quantum computing as a super-theoretical concept, and I never imagined it would manifest as reality so soon. I’m still trying to scratch the surface of understanding how these systems work, so my goal is to read, learn, and summarize my understanding about quantum computing in this space and how it will open opportunities for software developers. While I may never understand the mathematics fully, I don’t feel so bad — Bill Gates and Satya Nadella struggle with the concepts as well. I welcome any comments and feedback to help me improve my understanding.

My first instinct is to say that it seems like quantum computing will not completely replace classical computing — instead, they will co-exist. Classical computing is deterministic, which is wonderful. I want to know that the e-mail I send will get delivered. Quantum computing, on the other hand, seems to deal with probabilities. It seems better suited to modeling and simulation of real-world phenomenon, or areas where some fuzziness or randomness are beneficial (like cryptography). Many articles state things like “N qubits can exist in the superposition of all 2^N states at the same time“. But you don’t know which state they are in until you “see” one (or more?), at which point via entanglement you can see what states the other qubits are in. How that helps computationally, I don’t quite grasp yet, nor do I truly understand the practical implications of quantum computing (disregarding all the marketing-speak)…so more reading for me!

Tornado and Django — serving static content

I recently inherited a project for CLIx, a Django app running off of a Tornado WSGI server. Everything seemed to run fine, until we started getting reports that video and audio files were not playing correctly. It turns out that the original app was using Django to serve static files — not quite recommended for production use. This worked fine for small files like .html and .vtt, but larger files would not stream (.mp4, .mp3). You could not seek videos, and pausing / waiting / playing again would cause the video to re-play from the beginning.

In the Chrome dev tools, we could see that only part of the files were loading, but nothing else. So I decided to make Tornado serve the static content … not a lot of documentation about doing this. Luckily the Tornado-Django example application gives us a hint:

wsgi_app = tornado.wsgi.WSGIContainer(django.core.handlers.wsgi.WSGIHandler())
tornado_app = tornado.web.Application([
('/hello-tornado', HelloHandler),
('.*', tornado.web.FallbackHandler, dict(fallback=wsgi_app)),
server = tornado.httpserver.HTTPServer(tornado_app)


And a bunch of StackOverflow questions show how to configure Tornado URLs with the static URL handler:

handlers = [
  (r'/favicon.ico', tornado.web.StaticFileHandler, {'path': favicon_path}),
  (r'/static/(.*)', tornado.web.StaticFileHandler, {'path': static_path}), 
  (r'/', WebHandler)

Combining these two, you can make a Tornado WSGI server handle static files for a Django app!

sgi_app = tornado.wsgi.WSGIContainer(DJANGO_WSGI_APP)
tornado_app = tornado.web.Application([
  (r'/static/(.*)', tornado.web.StaticFileHandler, {'path': STATIC_URL}), 
  (r'/media/(.*)', tornado.web.StaticFileHandler, {'path': MEDIA_URL}), 
  (r'.*', tornado.web.FallbackHandler, dict(fallback=wsgi_app)),
server = tornado.httpserver.HTTPServer(tornado_app)