Vuelcome to the front-end side

A fast intro to the front-end development, why we chose Vue and how we use it in IBM Q Experience

The Front-end world

What's front-end development

+

Bundlers (webpack, parcel...)

CSS pre/post processor (SASS, Less... CSS-in-JS?)

API calls (Rest, Graphql...)

Server-side rendering

Testing (test runners, headless browsers...)

Browser compatibility (Polyfills)

Typescript

Front-end app frameworks

  • Custom elements
  • HTML Templates
  • Shadow DOM
  • ES Modules

Front-end app frameworks

Why we choose Vue

Easier to learn for beginners

Just that!

How Vue works

Basic Vue intro

Progressive framework (router, vuex, ssr...)

SFC components:

  • HTML template (directives, slots, html, pug)
  • JS (props, mixins, data, computed, methods, life cycle, events)
  • CSS (scoped, language)

Reactivity

Components

Props

Events

Single File Components

<template>
<div>
  <!-- HTML is here -->
</div>
</template>

<script>
export default {
  // definition
  name: '',
  mixins: [],
  components: [],
  // data
  props: {},
  data() {},
  computed: {},
  watch: {},
  // life cycle
  created() {},
  mounted() {},
  destroyed() {},
  // methods
  methods: {}

}
</script>

<style>
div {
  background-color: blue;
}
</style>

<docs>
// Hey! I'm a custom block
</docs>

Single File Components

<template>
  <div>
    <p v-if="seen">Now you see me</p>
    <a :href="url" @click="doSomething"> 
      {{ linkMessage | capitalize }}
    </a>
    <ul id="example-1">
      <li v-for="item in items" :key="item.id">
        {{ item.message }}
      </li>
    </ul>
    <i-am-a-component :prop="value">
        <slot name="title">
            <h1>Title!</h1>
        </slot>
    </i-am-a-component>
  </div>
</template>

Single File Components

<script>
import BaseInputText from './BaseInputText.vue'
import TodoListItem from './TodoListItem.vue'

let nextTodoId = 1

export default {
  components: {
    BaseInputText, TodoListItem
  },
  data () {
    return {
      newTodoText: '',
      todos: [
        {
          id: nextTodoId++,
          text: 'Learn Vue'
        }
      ]
    }
  },
  methods: {
    addTodo () {
      // content not here !
    },
    removeTodo (idToRemove) {
      this.todos = this.todos.filter(todo => {
        return todo.id !== idToRemove
      })
    }
  }
}
</script>

Single File Components

<style lang="scss" scoped>
@import '../variables.scss';

.input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid $vue-blue;
}
</style>

Reactivity

Reactivity

Router

const User = {
  template: `
    <div class="user">
      <h2>User {{ $route.params.id }}</h2>
      <router-view></router-view>
    </div>
  `
};

const router = new VueRouter({
  routes: [
    { path: '/user/:id', component: User,
      children: [
        {
          // UserProfile will be rendered inside User's <router-view>
          // when /user/:id/profile is matched
          path: 'profile',
          component: UserProfile
        },
        {
          // UserPosts will be rendered inside User's <router-view>
          // when /user/:id/posts is matched
          path: 'posts',
          component: UserPosts
        }
      ]
    }
  ]
});

Vuex

CLI & Dev tools

Advanced Vue topics

How we built the Composer

  1. QASM Parsing
  2. Circuit object
  3. Visualization
OPENQASM 2.0;
include "qelib1.inc";

qreg q[2];
creg c[2];

h q[0];
cx q[0],q[1];
measure q[0] -> c[0];
measure q[1] -> c[1];
class Circuit {
  constructor() {
    this.classicalRegisters = [],
    this.qubitsRegisters = [];
    this.gates = [];
  }
}

Parser

Based on qiskit-vscode using ANTLR4

Lexic & semantic analyzer

Circuit Object

class Circuit {
  constructor() {
    this.classicalRegisters = [],
    this.qubitsRegisters = [];
    this.gates = [];
  }
}

Visualization

Visualizer

SVG Drawer

  • registers (classical, quantum)
  • gates array
  • gates-definition
  • editable
  • gatesCatalog
  • registers (classical, quantum)
  • gates array with positions & gate hash

SVG Circuit Drawer

Gates

Dynamic

Z

H

  • @update

  • @subroutineAdded

  • @error

Drag & Drop

Gates Drop Area

Visualizer

SVG Drawer

Gates order vs QASM

The future

  • Making it a shareable component
  • Embedding in Notebook
  • Other displayers rather than SVG

Thanks!

😄

Made with Slides.com