```python
import sys
!{sys.executable} -m pip install -U turicreate matplotlib opencv-python
import turicreate as tc
import numpy as np
import os
import glob
```

    Requirement already satisfied: turicreate in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (6.4.1)
    Requirement already satisfied: matplotlib in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (3.3.4)
    Requirement already satisfied: opencv-python in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (4.5.1.48)
    Collecting matplotlib
      Downloading matplotlib-3.4.1-cp38-cp38-macosx_10_9_x86_64.whl (7.2 MB)
         |████████████████████████████████| 7.2 MB 3.4 MB/s eta 0:00:01     |▌                               | 112 kB 3.4 MB/s eta 0:00:03     |█████████▉                      | 2.2 MB 3.4 MB/s eta 0:00:02
    Requirement already satisfied: kiwisolver>=1.0.1 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from matplotlib) (1.3.1)
    Requirement already satisfied: pyparsing>=2.2.1 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from matplotlib) (2.4.7)
    Requirement already satisfied: cycler>=0.10 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from matplotlib) (0.10.0)
    Requirement already satisfied: python-dateutil>=2.7 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from matplotlib) (2.8.1)
    Requirement already satisfied: pillow>=6.2.0 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from matplotlib) (8.1.0)
    Requirement already satisfied: numpy>=1.16 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from matplotlib) (1.19.5)
    Requirement already satisfied: six in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from cycler>=0.10->matplotlib) (1.15.0)
    Requirement already satisfied: requests>=2.9.1 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from turicreate) (2.25.1)
    Requirement already satisfied: scipy>=1.1.0 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from turicreate) (1.6.0)
    Requirement already satisfied: resampy==0.2.1 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from turicreate) (0.2.1)
    Requirement already satisfied: tensorflow>=2.0.0 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from turicreate) (2.4.1)
    Requirement already satisfied: pandas>=0.23.2 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from turicreate) (1.2.2)
    Requirement already satisfied: prettytable==0.7.2 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from turicreate) (0.7.2)
    Requirement already satisfied: decorator>=4.0.9 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from turicreate) (4.4.2)
    Requirement already satisfied: coremltools==4.0b3 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from turicreate) (4.0b3)
    Requirement already satisfied: sympy in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from coremltools==4.0b3->turicreate) (1.7.1)
    Requirement already satisfied: attrs in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from coremltools==4.0b3->turicreate) (20.3.0)
    Requirement already satisfied: protobuf>=3.1.0 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from coremltools==4.0b3->turicreate) (3.14.0)
    Requirement already satisfied: attr in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from coremltools==4.0b3->turicreate) (0.3.1)
    Requirement already satisfied: tqdm in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from coremltools==4.0b3->turicreate) (4.56.2)
    Requirement already satisfied: numba>=0.32 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from resampy==0.2.1->turicreate) (0.52.0)
    Requirement already satisfied: setuptools in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from numba>=0.32->resampy==0.2.1->turicreate) (52.0.0.post20210125)
    Requirement already satisfied: llvmlite<0.36,>=0.35.0 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from numba>=0.32->resampy==0.2.1->turicreate) (0.35.0)
    Requirement already satisfied: pytz>=2017.3 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from pandas>=0.23.2->turicreate) (2021.1)
    Requirement already satisfied: certifi>=2017.4.17 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from requests>=2.9.1->turicreate) (2020.12.5)
    Requirement already satisfied: urllib3<1.27,>=1.21.1 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from requests>=2.9.1->turicreate) (1.26.3)
    Requirement already satisfied: chardet<5,>=3.0.2 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from requests>=2.9.1->turicreate) (4.0.0)
    Requirement already satisfied: idna<3,>=2.5 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from requests>=2.9.1->turicreate) (2.10)
    Requirement already satisfied: keras-preprocessing~=1.1.2 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from tensorflow>=2.0.0->turicreate) (1.1.2)
    Requirement already satisfied: termcolor~=1.1.0 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from tensorflow>=2.0.0->turicreate) (1.1.0)
    Requirement already satisfied: gast==0.3.3 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from tensorflow>=2.0.0->turicreate) (0.3.3)
    Requirement already satisfied: absl-py~=0.10 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from tensorflow>=2.0.0->turicreate) (0.11.0)
    Requirement already satisfied: wheel~=0.35 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from tensorflow>=2.0.0->turicreate) (0.36.2)
    Requirement already satisfied: wrapt~=1.12.1 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from tensorflow>=2.0.0->turicreate) (1.12.1)
    Requirement already satisfied: google-pasta~=0.2 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from tensorflow>=2.0.0->turicreate) (0.2.0)
    Requirement already satisfied: opt-einsum~=3.3.0 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from tensorflow>=2.0.0->turicreate) (3.3.0)
    Requirement already satisfied: grpcio~=1.32.0 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from tensorflow>=2.0.0->turicreate) (1.32.0)
    Requirement already satisfied: typing-extensions~=3.7.4 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from tensorflow>=2.0.0->turicreate) (3.7.4.3)
    Requirement already satisfied: h5py~=2.10.0 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from tensorflow>=2.0.0->turicreate) (2.10.0)
    Requirement already satisfied: tensorflow-estimator<2.5.0,>=2.4.0 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from tensorflow>=2.0.0->turicreate) (2.4.0)
    Requirement already satisfied: astunparse~=1.6.3 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from tensorflow>=2.0.0->turicreate) (1.6.3)
    Requirement already satisfied: tensorboard~=2.4 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from tensorflow>=2.0.0->turicreate) (2.4.1)
    Requirement already satisfied: flatbuffers~=1.12.0 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from tensorflow>=2.0.0->turicreate) (1.12)
    Requirement already satisfied: markdown>=2.6.8 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from tensorboard~=2.4->tensorflow>=2.0.0->turicreate) (3.3.3)
    Requirement already satisfied: werkzeug>=0.11.15 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from tensorboard~=2.4->tensorflow>=2.0.0->turicreate) (1.0.1)
    Requirement already satisfied: google-auth-oauthlib<0.5,>=0.4.1 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from tensorboard~=2.4->tensorflow>=2.0.0->turicreate) (0.4.2)
    Requirement already satisfied: google-auth<2,>=1.6.3 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from tensorboard~=2.4->tensorflow>=2.0.0->turicreate) (1.26.1)
    Requirement already satisfied: tensorboard-plugin-wit>=1.6.0 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from tensorboard~=2.4->tensorflow>=2.0.0->turicreate) (1.8.0)
    Requirement already satisfied: rsa<5,>=3.1.4 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from google-auth<2,>=1.6.3->tensorboard~=2.4->tensorflow>=2.0.0->turicreate) (4.7.1)
    Requirement already satisfied: cachetools<5.0,>=2.0.0 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from google-auth<2,>=1.6.3->tensorboard~=2.4->tensorflow>=2.0.0->turicreate) (4.2.1)
    Requirement already satisfied: pyasn1-modules>=0.2.1 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from google-auth<2,>=1.6.3->tensorboard~=2.4->tensorflow>=2.0.0->turicreate) (0.2.8)
    Requirement already satisfied: requests-oauthlib>=0.7.0 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from google-auth-oauthlib<0.5,>=0.4.1->tensorboard~=2.4->tensorflow>=2.0.0->turicreate) (1.3.0)
    Requirement already satisfied: pyasn1<0.5.0,>=0.4.6 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from pyasn1-modules>=0.2.1->google-auth<2,>=1.6.3->tensorboard~=2.4->tensorflow>=2.0.0->turicreate) (0.4.8)
    Requirement already satisfied: oauthlib>=3.0.0 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tensorboard~=2.4->tensorflow>=2.0.0->turicreate) (3.1.0)
    Requirement already satisfied: mpmath>=0.19 in /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages (from sympy->coremltools==4.0b3->turicreate) (1.2.1)
    Installing collected packages: matplotlib
      Attempting uninstall: matplotlib
        Found existing installation: matplotlib 3.3.4
        Uninstalling matplotlib-3.3.4:
          Successfully uninstalled matplotlib-3.3.4
    Successfully installed matplotlib-3.4.1

```python
from PIL import Image
from matplotlib import pyplot as plt
import cv2
classes = ["arrow", "circle", "cycle"]
for ml_class in classes:
    images = []
    image_labels = []
    files = glob.glob (f"data/images/{ml_class}/*")
    for image_file in files:
        im = Image.open(image_file)
        im = np.array(im)
        images.append(im)

    images = np.array(images)
    np.save(f'data/bitmaps/{ml_class}.npy', images)
```

```python
# mostly taken from: https://github.com/apple/turicreate/blob/master/userguide/drawing_classifier/data-preparation.md

random_state = np.random.RandomState(100)

# Change if applicable
data_dir = 'data'
bitmaps_dir = os.path.join(data_dir, 'bitmaps')
sframes_dir = os.path.join(data_dir, 'sframes')
npy_ext = '.npy'
num_examples_per_class = 200
num_classes = len(classes)

def build_bitmap_sframe():
    bitmaps_list, labels_list = [], []
    for class_name in classes:
        class_data = np.load(os.path.join(bitmaps_dir, class_name + npy_ext))
        random_state.shuffle(class_data)
        class_data_selected = class_data[:num_examples_per_class]
        for np_pixel_data in class_data_selected:
            FORMAT_RAW = 2
            bitmap = tc.Image(_image_data = np_pixel_data.tobytes(),
                              _width = np_pixel_data.shape[1],
                              _height = np_pixel_data.shape[0],
                              _channels = 1,
                              _format_enum = FORMAT_RAW,
                              _image_data_size = np_pixel_data.size)
            bitmaps_list.append(bitmap)
            labels_list.append(class_name)

    sf = tc.SFrame({"drawing": bitmaps_list, "label": labels_list})
    sf.save(os.path.join(sframes_dir, "bitmap_data.sframe"))
    return sf

sf = build_bitmap_sframe()
```

```python
sf.explore()
```

    /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages/turicreate/visualization/_plot.py:461: UserWarning: Displaying only the first 100 rows.
      warnings.warn("Displaying only the first {} rows.".format(maximum_rows))

      drawing
      label

      0

      arrow

      1

      arrow

      2

      arrow

      3

      arrow

      4

      arrow

      5

      arrow

      6

      arrow

      7

      arrow

      8

      arrow

      9

      arrow

      10

      arrow

      11

      arrow

      12

      arrow

      13

      arrow

      14

      arrow

      15

      arrow

      16

      arrow

      17

      arrow

      18

      arrow

      19

      arrow

      20

      arrow

      21

      arrow

      22

      arrow

      23

      arrow

      24

      arrow

      25

      arrow

      26

      arrow

      27

      arrow

      28

      arrow

      29

      arrow

      30

      arrow

      31

      arrow

      32

      arrow

      33

      arrow

      34

      arrow

      35

      arrow

      36

      arrow

      37

      arrow

      38

      arrow

      39

      arrow

      40

      arrow

      41

      arrow

      42

      arrow

      43

      arrow

      44

      arrow

      45

      arrow

      46

      arrow

      47

      arrow

      48

      arrow

      49

      arrow

      50

      arrow

      51

      arrow

      52

      arrow

      53

      arrow

      54

      arrow

      55

      arrow

      56

      arrow

      57

      arrow

      58

      arrow

      59

      arrow

      60

      arrow

      61

      arrow

      62

      arrow

      63

      arrow

      64

      arrow

      65

      arrow

      66

      arrow

      67

      arrow

      68

      arrow

      69

      arrow

      70

      arrow

      71

      arrow

      72

      arrow

      73

      arrow

      74

      arrow

      75

      arrow

      76

      arrow

      77

      arrow

      78

      arrow

      79

      arrow

      80

      arrow

      81

      arrow

      82

      arrow

      83

      arrow

      84

      arrow

      85

      arrow

      86

      arrow

      87

      arrow

      88

      arrow

      89

      arrow

      90

      arrow

      91

      arrow

      92

      arrow

      93

      arrow

      94

      arrow

      95

      arrow

      96

      arrow

      97

      arrow

      98

      arrow

      99

      arrow

```python
SFRAME_PATH = "data/sframes/bitmap_data.sframe"
data =  tc.SFrame(SFRAME_PATH)
```

```python
data.explore()
```

    /Users/marekfort/opt/miniconda3/envs/automata-editor/lib/python3.8/site-packages/turicreate/visualization/_plot.py:461: UserWarning: Displaying only the first 100 rows.
      warnings.warn("Displaying only the first {} rows.".format(maximum_rows))

      drawing
      label

      0

      arrow

      1

      arrow

      2

      arrow

      3

      arrow

      4

      arrow

      5

      arrow

      6

      arrow

      7

      arrow

      8

      arrow

      9

      arrow

      10

      arrow

      11

      arrow

      12

      arrow

      13

      arrow

      14

      arrow

      15

      arrow

      16

      arrow

      17

      arrow

      18

      arrow

      19

      arrow

      20

      arrow

      21

      arrow

      22

      arrow

      23

      arrow

      24

      arrow

      25

      arrow

      26

      arrow

      27

      arrow

      28

      arrow

      29

      arrow

      30

      arrow

      31

      arrow

      32

      arrow

      33

      arrow

      34

      arrow

      35

      arrow

      36

      arrow

      37

      arrow

      38

      arrow

      39

      arrow

      40

      arrow

      41

      arrow

      42

      arrow

      43

      arrow

      44

      arrow

      45

      arrow

      46

      arrow

      47

      arrow

      48

      arrow

      49

      arrow

      50

      arrow

      51

      arrow

      52

      arrow

      53

      arrow

      54

      arrow

      55

      arrow

      56

      arrow

      57

      arrow

      58

      arrow

      59

      arrow

      60

      arrow

      61

      arrow

      62

      arrow

      63

      arrow

      64

      arrow

      65

      arrow

      66

      arrow

      67

      arrow

      68

      arrow

      69

      arrow

      70

      arrow

      71

      arrow

      72

      arrow

      73

      arrow

      74

      arrow

      75

      arrow

      76

      arrow

      77

      arrow

      78

      arrow

      79

      arrow

      80

      arrow

      81

      arrow

      82

      arrow

      83

      arrow

      84

      arrow

      85

      arrow

      86

      arrow

      87

      arrow

      88

      arrow

      89

      arrow

      90

      arrow

      91

      arrow

      92

      arrow

      93

      arrow

      94

      arrow

      95

      arrow

      96

      arrow

      97

      arrow

      98

      arrow

      99

      arrow

```python
train_data, test_data = data.random_split(0.7)
```

```python
model = tc.drawing_classifier.create(train_data, 'label', max_iterations=20)
```

    Downloading https://docs-assets.developer.apple.com/turicreate/models/drawing_classifier_pre_trained_model_245_classes_v0.mlmodel
    Download completed: /var/folders/yc/57fqwfv971x9d3wwlvgllqsh0000gn/T/model_cache/drawing_classifier_pre_trained_model_245_classes_v0.mlmodel

Automatically generating validation set from 5% of the data.

Using CPU to create model.

+--------------+----------------+---------------------+--------------+

| Iteration    | Train Accuracy | Validation Accuracy | Elapsed Time |

+--------------+----------------+---------------------+--------------+

| 1            | 0.535714       | 0.636364            | 477.516ms    |

| 2            | 0.668367       | 0.681818            | 712.089ms    |

| 3            | 0.69898        | 0.727273            | 1.04s        |

| 4            | 0.721939       | 0.818182            | 1.26s        |

| 5            | 0.770408       | 0.909091            | 1.48s        |

| 6            | 0.816327       | 0.954545            | 1.70s        |

| 11           | 0.969388       | 1                   | 3.08s        |

| 20           | 0.992347       | 1                   | 5.34s        |

+--------------+----------------+---------------------+--------------+

```python
model
```

    Class                                    : DrawingClassifier

    Schema
    ------
    Number of classes                        : 3
    Feature column                           : drawing
    Target column                            : label

    Training summary
    ----------------
    Training Iterations                      : 20
    Training Accuracy                        : 1.0
    Validation Accuracy                      : 0.8824
    Training Time                            : 13.7598
    Number of Examples                       : 153

```python
predictions = model.predict(test_data)
```

```python
metrics = model.evaluate(test_data)
metrics.explore()
```

    Resizing image data... Done.

```python
model.save("automata-editor.model")
```

```python
model.export_coreml("AutomataClassifier.mlmodel")
```


```python
!pip install qiskit==0.7.1
!pip install qiskit_aer==0.1.1
!cp /usr/local/lib/python3.6/site-packages/*.so /usr/local/lib/python3.6/dist-packages/
```

    Requirement already satisfied: qiskit==0.7.1 in /usr/local/lib/python3.6/dist-packages (0.7.1)
    Requirement already satisfied: qiskit-terra<0.8,>=0.7 in /usr/local/lib/python3.6/dist-packages (from qiskit==0.7.1) (0.7.0)
    Requirement already satisfied: qiskit-aer<0.2,>=0.1 in /usr/local/lib/python3.6/dist-packages (from qiskit==0.7.1) (0.1.1)
    Requirement already satisfied: ply>=3.10 in /usr/local/lib/python3.6/dist-packages (from qiskit-terra<0.8,>=0.7->qiskit==0.7.1) (3.11)
    Requirement already satisfied: jsonschema<2.7,>=2.6 in /usr/local/lib/python3.6/dist-packages (from qiskit-terra<0.8,>=0.7->qiskit==0.7.1) (2.6.0)
    Requirement already satisfied: numpy>=1.13 in /usr/local/lib/python3.6/dist-packages (from qiskit-terra<0.8,>=0.7->qiskit==0.7.1) (1.14.6)
    Requirement already satisfied: pillow>=4.2.1 in /usr/local/lib/python3.6/dist-packages (from qiskit-terra<0.8,>=0.7->qiskit==0.7.1) (5.4.1)
    Requirement already satisfied: marshmallow<3,>=2.16.3 in /usr/local/lib/python3.6/dist-packages (from qiskit-terra<0.8,>=0.7->qiskit==0.7.1) (2.18.1)
    Requirement already satisfied: scipy!=0.19.1,>=0.19 in /usr/local/lib/python3.6/dist-packages (from qiskit-terra<0.8,>=0.7->qiskit==0.7.1) (1.1.0)
    Requirement already satisfied: requests-ntlm>=1.1.0 in /usr/local/lib/python3.6/dist-packages (from qiskit-terra<0.8,>=0.7->qiskit==0.7.1) (1.1.0)
    Requirement already satisfied: marshmallow-polyfield<4,>=3.2 in /usr/local/lib/python3.6/dist-packages (from qiskit-terra<0.8,>=0.7->qiskit==0.7.1) (3.2)
    Requirement already satisfied: psutil>=5 in /usr/local/lib/python3.6/dist-packages (from qiskit-terra<0.8,>=0.7->qiskit==0.7.1) (5.4.8)
    Requirement already satisfied: requests>=2.19 in /usr/local/lib/python3.6/dist-packages (from qiskit-terra<0.8,>=0.7->qiskit==0.7.1) (2.21.0)
    Requirement already satisfied: networkx>=2.2 in /usr/local/lib/python3.6/dist-packages (from qiskit-terra<0.8,>=0.7->qiskit==0.7.1) (2.2)
    Requirement already satisfied: sympy>=1.3 in /usr/local/lib/python3.6/dist-packages (from qiskit-terra<0.8,>=0.7->qiskit==0.7.1) (1.3)
    Requirement already satisfied: cryptography>=1.3 in /usr/local/lib/python3.6/dist-packages (from requests-ntlm>=1.1.0->qiskit-terra<0.8,>=0.7->qiskit==0.7.1) (2.6)
    Requirement already satisfied: ntlm-auth>=1.0.2 in /usr/local/lib/python3.6/dist-packages (from requests-ntlm>=1.1.0->qiskit-terra<0.8,>=0.7->qiskit==0.7.1) (1.2.0)
    Requirement already satisfied: urllib3<1.25,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests>=2.19->qiskit-terra<0.8,>=0.7->qiskit==0.7.1) (1.22)
    Requirement already satisfied: idna<2.9,>=2.5 in /usr/local/lib/python3.6/dist-packages (from requests>=2.19->qiskit-terra<0.8,>=0.7->qiskit==0.7.1) (2.6)
    Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from requests>=2.19->qiskit-terra<0.8,>=0.7->qiskit==0.7.1) (2018.11.29)
    Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from requests>=2.19->qiskit-terra<0.8,>=0.7->qiskit==0.7.1) (3.0.4)
    Requirement already satisfied: decorator>=4.3.0 in /usr/local/lib/python3.6/dist-packages (from networkx>=2.2->qiskit-terra<0.8,>=0.7->qiskit==0.7.1) (4.3.2)
    Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.6/dist-packages (from sympy>=1.3->qiskit-terra<0.8,>=0.7->qiskit==0.7.1) (1.1.0)
    Requirement already satisfied: cffi!=1.11.3,>=1.8 in /usr/local/lib/python3.6/dist-packages (from cryptography>=1.3->requests-ntlm>=1.1.0->qiskit-terra<0.8,>=0.7->qiskit==0.7.1) (1.12.2)
    Requirement already satisfied: six>=1.4.1 in /usr/local/lib/python3.6/dist-packages (from cryptography>=1.3->requests-ntlm>=1.1.0->qiskit-terra<0.8,>=0.7->qiskit==0.7.1) (1.11.0)
    Requirement already satisfied: asn1crypto>=0.21.0 in /usr/local/lib/python3.6/dist-packages (from cryptography>=1.3->requests-ntlm>=1.1.0->qiskit-terra<0.8,>=0.7->qiskit==0.7.1) (0.24.0)
    Requirement already satisfied: pycparser in /usr/local/lib/python3.6/dist-packages (from cffi!=1.11.3,>=1.8->cryptography>=1.3->requests-ntlm>=1.1.0->qiskit-terra<0.8,>=0.7->qiskit==0.7.1) (2.19)
    Requirement already satisfied: qiskit_aer==0.1.1 in /usr/local/lib/python3.6/dist-packages (0.1.1)
    Requirement already satisfied: numpy>=1.13 in /usr/local/lib/python3.6/dist-packages (from qiskit_aer==0.1.1) (1.14.6)

```python
import numpy as np
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister
from qiskit import execute
from qiskit.tools.visualization import plot_histogram

import numpy as np

from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit import BasicAer, execute, LegacySimulators, Aer

n=3
```

```python
#IN/DECREMENT GATES FOR N=3

def increment_gate(qwc,q,subnode):

  qwc.ccx(q[2], q[1], q[0])
  qwc.cx(q[2], q[1])
  qwc.x(q[2])

  for node in q:
    qwc.cx(subnode,node)

  qwc.barrier()
  return qwc

def decrement_gate(qwc,q,subnode):

  qwc.x(q[2])
  qwc.x(q[1])
  qwc.ccx(q[2], q[1], q[0])
  qwc.x(q[1])

  qwc.cx(q[2], q[1])

  qwc.x(subnode[0])
  for node in q:
    qwc.cx(subnode, node)
  qwc.x(subnode[0])

  return qwc

def stateVectorGenerator(circ):
  # Select the StatevectorSimulator from the Aer provider
  simulator = Aer.get_backend('statevector_simulator')

  # Execute and get counts
  return execute(circ, simulator).result().get_statevector(circ)

```

```python
def runQWC():
  qwc.h(subnodes[0])
  increment_gate(qwc,qnodes,subnodes[0])

  return qwc
```

```python
qnodes = QuantumRegister(n,'qc')
qsubnodes = QuantumRegister(1,'qanc')
csubnodes = ClassicalRegister(1,'canc')
cnodes = ClassicalRegister(n,'cr')

qwc = QuantumCircuit(qnodes,subnodes,cnodes,csubnodes)

runQWC()
qwc.draw(output='mpl')

```

```python
sv = stateVectorGenerator(qwc)
plot_state_city(sv, title='Bell state')

```

```python
qwc.measure(qnodes, cnodes)
sv = stateVectorGenerator(qwc)
plot_state_city(sv, title='state post-measurement')

# 471071fc24f40345e8d90c5a1041ea2ce1c1368439dfcf7a6abd11dbf317e11fae69b7461038d2600771ce24057b5545ea3366db352dd2904aea970464916264
```

n-qubit toffoli

```python
def cnx(qc,*qubits):
    if len(qubits) >= 3:
        last = qubits[-1]
        #A matrix: (made up of a  and Y rotation, lemma4.3)
        qc.crz(np.pi/2,qubits[-2],qubits[-1])
        #cry
        qc.cu3(pi/2, 0, 0, qubits[-2],qubits[-1])

        #Control not gate
        cnx(qc,*qubits[:-2],qubits[-1])

        #B matrix (cry again, but opposite angle)
        qc.cu3(-pi/2, 0, 0, qubits[-2], qubits[-1])

        #Control
        cnx(qc,*qubits[:-2],qubits[-1])

        #C matrix (final rotation)
        qc.crz(-np.pi/2,qubits[-2],qubits[-1])
    elif len(qubits)==3:
        qc.ccx(*qubits)
    elif len(qubits)==2:
        qc.cx(*qubits)
```

```python

```