Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Unlocking Quantum Potential with Cirq and Tenso...

Unlocking Quantum Potential with Cirq and TensorFlow (By: Haleema Tallat) - DevFest Lahore 2023

Workshop by Haleema Tallat (https://www.linkedin.com/in/haleema-tallat/) at DevFest Lahore 2023 by GDG Lahore.

GDG Lahore

December 23, 2023
Tweet

More Decks by GDG Lahore

Other Decks in Programming

Transcript

  1. The Qubit • Qubits are the fundamental units of quantum

    information. • Unlike classical bits (0 or 1), qubits can exist in multiple states simultaneously due to superposition. • Represented mathematically as α|0⟩ + β|1⟩, where α and β are probability amplitudes.
  2. Quantum Gates • Analogous to classical logic gates, quantum gates

    manipulate qubits. • They perform operations like rotations, flips, and entanglement generation. • They are reversible!
  3. Quantum Circuits • Combinations of quantum gates form circuits to

    perform specific tasks. • Circuits manipulate qubits through a sequence of gates to execute quantum algorithms.
  4. Quantum Machine Learning • Quantum Computing is about creating constructive

    interference for correct answers. • Quantum Machine Learning is about iterative creation of constructive interferences for correct answers.
  5. Integration of TensorFlow Quantum and Cirq a. High-Level Quantum Model

    Design b. TensorFlow's Optimization and Training c. Seamless Integration
  6. Encode the data as quantum circuits Representing each pixel with

    a qubit, with the state depending on the value of the pixel. The first step is to convert to a binary encoding.
  7. The qubits at pixel indices with values that exceed a

    threshold, are rotated through an X gate.
  8. Convert these Cirq circuits to tensors for tfq: x_train_tfcirc =

    tfq.convert_to_tensor(x_train_circ) x_test_tfcirc = tfq.convert_to_tensor(x_test_circ)
  9. Hinge Loss To use the hinge loss here you need

    to make two small adjustments. First convert the labels, y_train_nocon, from boolean to [-1,1], as expected by the hinge loss. y_train_hinge = 2.0*y_train_nocon-1.0 y_test_hinge = 2.0*y_test-1.0 Second, use a custiom hinge_accuracy metric that correctly handles [-1, 1] as the y_true labels argument. tf.losses.BinaryAccuracy(threshold=0.0) expects y_true to be a boolean, and so can't be used with hinge loss).
  10. Train the quantum model EPOCHS = 3 BATCH_SIZE = 32

    NUM_EXAMPLES = len(x_train_tfcirc) x_train_tfcirc_sub = x_train_tfcirc[:NUM_EXAMPLES] y_train_hinge_sub = y_train_hinge[:NUM_EXAMPLES]
  11. Training to convergence achieves >85% accuracy! Epoch 1/3 324/324 [==============================]

    - 64s 196ms/step - loss: 0.7855 - hinge_accuracy: 0.6745 - val_loss: 0.5021 - val_hinge_accuracy: 0.8080 324/324 [==============================] - 63s 196ms/step - loss: 0.3958 - hinge_accuracy: 0.8441 - val_loss: 0.3608 - val_hinge_accuracy: 0.9088 324/324 [==============================] - 63s 195ms/step - loss: 0.3533 - hinge_accuracy: 0.8913 - val_loss: 0.3449 - val_hinge_accuracy: 0.9062 62/62 [==============================] - 3s 43ms/step - loss: 0.3449 - hinge_accuracy: 0.9062
  12. 2. Relabeling and computing PQK features You will now prepare

    a "stilted" quantum dataset by incorporating quantum components and re-labeling the truncated fashion-MNIST dataset you've created above. In order to get the most seperation between quantum and classical methods, you will first prepare the PQK features and then relabel outputs based on their values. 2.1 Quantum encoding and PQK features You will create a new set of features, based on x_train, y_train, x_test and y_test that is defined to be the 1-RDM on all qubits of:
  13. Realistic Prospects • Enhanced Machine Learning Models • Specific Applications

    ◦ Drug Discovery and Molecular Modeling ◦ Financial Modeling Network Attacks • Quantum Neural Networks (QNNs) • Quantum Hardware Development • Algorithmic Developments