quantum-viz.js icon indicating copy to clipboard operation
quantum-viz.js copied to clipboard

Improve API

Open theRoughCode opened this issue 4 years ago • 1 comments

Our current API for the package looks like this:

const sampleCircuit = {
    qubits: [
        // ...
    ],
    operations: [
        // ...
    ],
};
const sampleDiv = document.getElementById('sample');
qviz.draw(sampleCircuit, sampleDiv, qviz.STYLES['Default']);

A few things that would make for a good interface are:

  1. Easy to use
  2. Customizable (i.e. style, interactivity, custom augmentations)
  3. Easy to read

A good example of an interface that we can draw inspiration from is d3.js:

d3.select("body")
  .selectAll("p")
  .data([4, 8, 15, 16, 23, 42])
  .enter().append("p")
    .text(function(d) { return "I’m number " + d + "!"; });

We can select a DOM element, add data to it, and customize it. A similar API for Sqore would work really well.

theRoughCode avatar Jun 01 '21 18:06 theRoughCode

A couple more things the API should allow:

  • It should be easy to add custom visualizations of gates. Right now the logic to select a gate formatter (say X) is hardcoded, should be easier to register a new formatter that takes precedence over the built-in ones.
  • It should be easy to change the state of the circuit/sqore programmatically. For example, we should be able to easily change what operations are expanded/collapsed.
  • The data-schema should be cleaned-up/simplified. For example:
    • having numChildren to indicate classical bits it's really odd
    • the way we define Measure gates is very complicated
    • it should be possible to specify initial qubit states other than |0>

anpaz avatar Jun 04 '21 21:06 anpaz