Q needs you
Itâs time for Q to grow. But itâs also 2020âweâre right in the middle of the COVID-19 global pandemic. Are you in need of a project to take your mind off current events? Do you love JavaScript, CSS, and the free Web? How about breaking down complex subjects into simple bite-sized chunks of copywriting and minimalist diagrams? Are you a graphic designer or copywriter? Are you excited about quantum computing? Join our Q.js project on GitHub, create or resolve some issues, and help us make quantum accessible!
Read the following sections to familiarize yourself with Qâs objectives, inspirations, and plans for the future.
Roadmap
Thursday, 30 April 2020, is our one-year anniversary. From conception 12 months ago to now weâve built a functioning code API and a drag-and-drop circuit editor. While there are still many exciting features to add, and a list of issues to resolve, this anniversary is a milestone worth celebrating. As initial work on the circuit editor interface winds down our focus will shift back to optimization of the simulator itself. During Summer 2020 our primary focus will be wrangling multiple execution threads and hardware acceleration via WebGPU. On the back burner weâll be adding new import and export utilities to make hopping between Q and other quantum suites a breeze.
Documentation style
Concepts included
For most people anything âquantumâ is brand new. Even the simpler mathematics are things that most folks probably havenât seen since high school. (Whenâs the last time the average person actually had to think about complex numbers?) If weâre going to make quantum accessible we need to include simple / legible / digestible concept primers for these topics right in the documentation, and also provide links to learning resources.
To this end documentation for Q classesâsuch as Q.Matrix, Q.Qubit, and so onâinclude brief explanations of the mathematics that the class represents before diving into the code and usage specifics. We also provide a separate Resources page with links to learn more about quantum computing in general.
Interface
This collection of HTML files serve as Qâs interactive
documentation.
Its design objectives are tidiness, shareability, and consistency.
When possible the general UI features,
such as the main navigation
or body modules,
are visually flat.
Buttons intended to be âpushedâ
or circuit operations intended to be âdragged and droppedâ
may be represented as dimensional.
JavaScript style
Programs must be written for people to read, and only incidentally for machines to execute.
Structure and Interpretation of Computer Programs,
Preface to the first edition
Qâs source code is verbose, heavily commented, and thereâs great empathy for fellow learners. Visual hierarchy is key when facing a brick of monospace code gibberish. White space helps; white space around variables, between conceptually different blocks of code. (Youâve got to let code breathe.) Semicolons as line-enders are avoided unless absolutely necessary. (Theyâre just visual clutter otherwise; typographic noise in the signal.) Q is meant to be flexible and expressive to adapt to your style. âFluent interfaceâ method chaining is prized, but Q often uses static class methods as a foundation for instance methods, so youâre free to use either approach.
Low barrier to entry
Not everyoneâs a grizzled software engineerânor should they be. If youâre reading this on any desktop or laptop, you already have all the tools you need to start playing with Q. And âgetting startedâ shouldnât require installing new applications, signing up for new accounts, or spinning up a server thread from the command line just to load a website and play. (Thatâs one reason Q does not use JavaScript modules.) Just drag and drop any HTML file from Qâs code repository onto your browser window and youâre up and running. This is the beauty of Sir Timâs World Wide Web and every single person who has ever contributed to the art of the browser. In general you can always add more layers to somethingâinstall what you will, tweak how you like. But removing layers is damn near impossible. Q aims to ship with few layers.
Hackable by design
Q places heavy emphasis on the ability to inspect anything right from your own browser console in realtime. This is one of the reasons Q shuns JavaScript modules, is sensitive to the use of closures, and hangs all of its functionality off of the Q object which sits in the global scope For us âhackabilityâ is importantâparticularly for teaching and learning. By âhackableâ we mean heavily inspectable and customizable by the curiousânovice and expert alike. We do not not mean âhackableâ as in âcontaining security flaws.â
Less Java, more JavaScript
Some ES6 syntax is preferred, but the bits that disfigure JavaScript to look more like Java, C++, C#, etc. are weeded out, bagged, and tossed in the river.
There is nothing wrong with
prototypal inheritance
and itâs in fact
more powerful than classical inheritance.
JavaScript is uniquely beautiful in its flexibility
and to paper over that with
âclassâ,
or ignore the power of
closures,
or pretend private variables werenât possible prior to 2015
is like confusing an aptitude for Rock Band
with actual musicianship.
While Qâs internal code uses let and const when declaring variables,
the examples here use var instead;
redeclare and overwrite example variables to your heartâs content.
Destructive vs non-destructive methods
Q pays particular attention to destructive versus non-destructive instance methods.
For example, the archetypal non-destructive method is .clone()
which returns a new sibling instance of the object it was called from
and by its nature makes no alterations to that original object.
In contrast, .copy$( sibling ) is the archetypal destructive method
which causes an instance to alter itself by overwriting its own propertiesâ values with values from a sibling instance, then returns itself.
The dollar sign suffix is similar to
Rubyâs
exclamation point suffix and is a reminder that the operation is destructive; will alter the instance.
var
cat = new Q.ComplexNumber( 1, 2 ),
dog = new Q.ComplexNumber( 3, -4 )
cat.toText() // Returns '1 + 2i'
dog.toText() // Returns '3 - 4i'
cat.add( dog ) // Non-destructive.
cat.toText() // Still returns '1 + 2i'
cat.add$( dog )// Destructive. Note the â$â suffix.
cat.toText() // Now returns '4 - 2i'
The notable exception to this is the âPython-inspiredâ circuit editing syntax which uses convenience functions not suffixed with a dollar sign. This allows creating a circuit in Q to more closely resemble editing a Python script for Amazon Braket, IBM Qiskit, and so on:
Q( 2, 2 )
.h( 1, 1 )
.x( 2, [ 1, 2 ])
CSS style
Similar to our JavaScript style,
our CSS eschews modules and shadow DOM containers
in favor of carefully named global variables.
We feel it should be easy for you, the developer,
to be able to remix and reconfigure Q with ease.
Reuse the Q classes, customize them, or leave them be.
(Any box is a
âblack boxâ if you donât look inside it.)
Our CSS variables are prefixed with â--Qâ
and several categories, such as color palette values,
are exposed for your convenience.