• Stars
    star
    113
  • Rank 310,115 (Top 7 %)
  • Language
    Jupyter Notebook
  • License
    Apache License 2.0
  • Created over 6 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This repository contains the source code used to produce the results presented in the paper "Machine learning method for state preparation and gate synthesis on photonic quantum computers".

Quantum state learning and gate synthesis

This repository contains the source code used to produce the results presented in "Machine learning method for state preparation and gate synthesis on photonic quantum computers" Quantum Science and Technology, 4 024004 (2019).

Contents

  • state_learner.py: a Python script to automate quantum state learning using continuous-variable (CV) variational quantum circuits. Simply specify your one- or two-mode target state, along with other hyperparameters, and this script automatically constructs and optimizes the variational quantum circuit.

  • gate_synthesis.py: a Python script to automate quantum gate synthesis using continuous-variable (CV) variational quantum circuits. Simply specify your one- or two-mode target unitary, along with other hyperparameters, and this script automatically constructs and optimizes the variational quantum circuit.

  • learner: a Python module containing the following importable Python files:

    • states.py: functions to generate the states analyzed in the paper.
    • gates.py: functions to generate the states analyzed in the paper.
    • plots.py: functions to generate the plots and visualizations in the paper.
    • circuits.py: functions to construct the one-mode and two-mode variational circuits as described in the paper Continuous-variable quantum neural networks.
  • Jupyter notebooks: two Jupyter notebooks are also provided, StateLearning.ipynb and GateSynthesis.ipynb, walking through the process of state learning and gate synthesis respectively.

  • Results and data presented in arXiv:1807.10781: contains two sub folders; gate_results and state_results, each with NumPy npz files containing the hyperparameters and circuit parameters of the synthesized gates and learnt states presented in arXiv:1807.10781. Refer to these folder for more informtion on the data contained.

Requirements

To construct and optimize the variational quantum circuits, these scripts and notebooks use the TensorFlow backend of Strawberry Fields. In addition, matplotlib is required for generating output plots, and OpenFermion is used to construct target gate unitaries.

Using the scripts

To use the scripts, simply set the hyperparameters - either by modifying the default hyperparameters in the file itself, or passing the relevant command line arguments - and then run the script using Python 3:

python3 state_learner.py

The outputs of the simulations will be saved in the directory out_dir/simulation_ID, with out_dir set by the hyperparameter dictionary, and simulation_ID determined automatically based on the simulation name.

After every optimization, plots and visualisations of the target and learnt state/gate are generated, as well as a NumPy multi-array file simulation_ID.npz. This file contains all the hyperparameters that characterize the simulation, as well as the results - including the target and learnt state/gate, and the optimized variational circuit gate parameters.

To access the saved data, the file can be loaded using NumPy:

results = np.load('simulation_ID.npz')

The individual hyperparameters and results can then be accessed via the respective key. For example, to extract the learnt state, as well as a list of the variational circuit layer squeezing magnitudes:

learnt_state = results['learnt_state']
squeezing = results['sq_r']

For a list of all available keys, simply run print(results.keys()).

State learner hyperparameters

The following hyperparameters can be set for the script state_learner.py:

Hyperparameter Command line argument Description
name -n/--name The name of the simulation
out_dir -o/--out-dir Output directory for saving the simulation results
target_state_fn n/a Function for generating the target state for optimization. This function can accept an optional list of state parameters, along with the required keyword argument cutoff which determines the Fock basis truncation. The function must return a NumPy array of length [cutoff] for single mode states, and length [cutoff^2] for two mode states.
state_params -p/--state-params Optional dictionary of state parameters to pass to the target state function, for example {"N": 3}.
cutoff -c/--cutoff The simulation Fock basis truncation.
depth -d/--depth Number of layers in the variational quantum circuit.
reps -r/--reps Number of optimization steps to perform.
active_sd n/a Standard deviation of initial photon non-preserving gate parameters in the variational quantum circuit.
passive_sd n/a Standard deviation of initial photon preserving gate parameters in the variational quantum circuit.

The target state function can be defined manually in Python and added to the hyperparameters dictionary, or imported from the file learners/states.py. After the optimization is complete, the state learning script will automatically generate the following plots:

  • Cost function vs. optimization step
  • Wigner functions of the target state and the learnt state (for one mode states only)
  • Wavefunctions of the target state and the learnt state.

Gate synthesis hyperparameters

The following hyperparameters can be set for the script gate_synthesis.py:

Hyperparameter Command line argument Description
name -n/--name The name of the simulation
out_dir -o/--out-dir Output directory for saving the simulation results
target_unitary_fn n/a Function for generating the target unitary for synthesis. This function can accept an optional list of gate parameters, along with the required keyword argument cutoff which determines the Fock basis truncation. The function must return a NumPy array of size [cutoff, cutoff] for single mode unitaries, and size [cutoff^2, cutoff^2] for two mode unitaries.
target_params -p/--target-params Optional dictionary of gate parameters to pass to the target unitary function, for example {"gamma": 0.01}.
cutoff -c/--cutoff The simulation Fock basis truncation.
gate_cutoff -g/--gate-cutoff the d-dimensional subspace in which the target unitary acts. The value of the gate cutoff must be less than or equal to the simulation cutoff.
depth -d/--depth Number of layers in the variational quantum circuit.
reps -r/--reps Number of optimization steps to perform.
active_sd n/a Standard deviation of initial photon non-preserving gate parameters in the variational quantum circuit.
passive_sd n/a Standard deviation of initial photon preserving gate parameters in the variational quantum circuit.
maps_outside n/a Set to True if the target unitary maps Fock states within the d-dimensional subspace specified by the gate cutoff to Fock states outside of the d-dimensional subspace. If unsure, set to True.

The target unitary function can be defined manually in Python and added to the hyperparameters dictionary, or imported from the file learners/gates.py. After the optimization is complete, the gate synthesis script will automatically calculate the process fidelity and average fidelity of the two unitaries, and generate the following plots:

  • Cost function vs. optimization step
  • Wigner functions of the target unitary and the learnt unitary applied to the equal superposition state (for one mode states only)
  • Wavefunctions of the target unitary and the learnt unitary applied to the equal superposition state (for two mode states only)
  • Matrix plots of the real and imaginary elements of the target unitary and learnt unitary.

Authors

Juan Miguel Arrazola, Thomas R. Bromley, Josh Izaac, Casey R. Myers, Kamil Brรกdler, and Nathan Killoran.

If you are doing any research using this source code and Strawberry Fields, please cite the following two papers:

Juan Miguel Arrazola, Thomas R. Bromley, Josh Izaac, Casey R. Myers, Kamil Brรกdler, and Nathan Killoran. Machine learning method for state preparation and gate synthesis on photonic quantum computers. Quantum Science and Technology, 4 024004 (2019).

Nathan Killoran, Josh Izaac, Nicolรกs Quesada, Ville Bergholm, Matthew Amy, and Christian Weedbrook. Strawberry Fields: A Software Platform for Photonic Quantum Computing. arXiv, 2018. Quantum, 3, 129 (2019).

License

This source code is free and open source, released under the Apache License, Version 2.0.

More Repositories

1

strawberryfields

Strawberry Fields is a full-stack Python library for designing, simulating, and optimizing continuous variable (CV) quantum optical circuits.
Python
749
star
2

quantum-neural-networks

This repository contains the source code used to produce the results presented in the paper "Continuous-variable quantum neural networks". Due to subsequent interface upgrades, these scripts will work only with Strawberry Fields version <= 0.10.0.
Python
297
star
3

QHack2021

Official repo for QHackโ€”the quantum machine learning hackathon
Python
121
star
4

Xanadu-Quantum-Codebook

Learn quantum computing interactively with PennyLane
Python
111
star
5

QMLT

The Quantum Machine Learning Toolbox (QMLT) is a Strawberry Fields application that simplifies the optimization of variational quantum circuits (also known as parametrized quantum circuits).
Python
110
star
6

thewalrus

A library for the calculation of hafnians, Hermite polynomials and Gaussian boson sampling.
Python
101
star
7

quantum-inspired-algorithms

Quantum-inspired algorithms for linear algebra applications. The repository contains all source code used to generate results presented in "Practical performance of quantum-inspired algorithms for linear algebra".
Python
97
star
8

QHack2022

QHackโ€”The one-of-a-kind quantum computing hackathon
Python
87
star
9

MrMustard

A differentiable bridge between phase space and Fock space
Python
78
star
10

quantum-transfer-learning

A transfer learning approach applied to hybrid neural networks composed of classical and quantum elements.
Jupyter Notebook
70
star
11

QHack2023

QHack 2023
69
star
12

blackbird

Blackbird is a quantum assembly language for continuous-variable quantum computation, that can be used to program Xanadu's quantum photonics hardware and Strawberry Fields simulator.
C++
67
star
13

GradDFT

GradDFT is a JAX-based library enabling the differentiable design and experimentation of exchange-correlation functionals using machine learning techniques.
Python
65
star
14

jet

Jet is a cross-platform library for simulating quantum circuits using tensor network contractions.
C++
59
star
15

qml-benchmarks

Code to benchmark quantum machine learning models
Python
49
star
16

pennylane-demo-cern

Contains material for the PennyLane tutorial at CERN on 3/4 February 2021.
Jupyter Notebook
46
star
17

expressive_power_of_quantum_models

This repository contains the source code necessary to reproduce the figures and simulation results of the url[paper](XXX) "The effect of data encoding on the expressive power of variational quantum machine learning models" by Maria Schuld, Ryan Sweke and Johannes Jakob Meyer.
Jupyter Notebook
44
star
18

flamingpy

FlamingPy is a cross-platform Python library with a variety of backends for efficient simulations of error correction in fault-tolerant quantum computers.
Python
44
star
19

qhack_2023_coding_challenges

Jupyter Notebook
35
star
20

SFOpenBoson

A plugin for Strawberry Fields and OpenFermion, providing methods of simulating bosonic Hamiltonians directly in Strawberry Fields
Python
30
star
21

QHack-2019

QHACK: The Quantum Machine Learning Hackathon
28
star
22

constrained-quantum-learning

This repository contains the source code used to produce the results presented in the paper "Near-deterministic production of universal quantum photonic gates enhanced by machine learning".
Python
19
star
23

realistic-quantum-states

This repository contains the source code used to produce the results presented in the paper "Simulating realistic non-Gaussian state preparation".
Python
13
star
24

xanadu-cloud-client

CLI and Python API for the Xanadu Cloud.
Python
12
star
25

fockgaussian

This repository contains the source code used to produce the results presented in " Franck-Condon factors by counting perfect matchings of graphs with loops " J. Chem. Phys. 150, 164113 (2019).
Jupyter Notebook
10
star
26

approximate-GKP-prep

This repository contains the source code used to produce the results presented in the paper "Progress towards practical qubit computation using approximate Gottesman-Kitaev-Preskill codes".
Jupyter Notebook
10
star
27

derivatives-of-variational-circuits

Jupyter Notebook
9
star
28

torontonian-sampling

This repository contains the source code used to produce the results presented in the paper "Classical benchmarking of Gaussian Boson Sampling on the Titan supercomputer".
Fortran
9
star
29

randomized-measurements-circuit-cutting

Jupyter Notebook
8
star
30

xanadu-qca-data

Python
8
star
31

sqtom

Tomography of squeezed modes
Python
6
star
32

pennylane-plugin-template

This template repository provides the boilerplate and file structure required to easily create your own PennyLane plugin.
Python
6
star
33

Contextual-ML

Jupyter Notebook
5
star
34

xir

XIR is an intermediate representation language for quantum circuits.
Python
5
star
35

PLC-YouTube-tutorials

This repository houses code that was used in our YouTube videos.
Jupyter Notebook
4
star
36

xanadu-sphinx-theme

The Xanadu Sphinx Theme is a Sphinx theme used for open-source Xanadu software projects.
HTML
4
star
37

hva-without-barren-plateaus

Repositoy for "Hamiltonian variational ansatz without barren plateaus"
C++
4
star
38

cloud-workshops

Materials for Xanadu's Quantum Cloud workshops
Jupyter Notebook
3
star
39

generative_qml_qchem

Repository for the generative QML for quantum chemistry project
Python
3
star
40

kerr-squeezing

Python
3
star
41

PLC-borealis-demos

Borealis demos for PennyLane Cloud
Jupyter Notebook
2
star
42

polyval2d-high-precision

CMake
2
star
43

cloud-actions

A repository of reusable GitHub actions for cloud workflows
JavaScript
2
star
44

plaas-examples

Examples PLAAS notebooks
Jupyter Notebook
1
star
45

github_test

A test repository for GitHub options.
1
star
46

plotters-solstice

A web and opengl backend for Plotters using Solstice.
Rust
1
star
47

all-you-need-is-spin

Python
1
star
48

pseudopotentials

Python
1
star
49

CFQMagnus

Numerical analysis of the Magnus Hamiltonian simulation technique
Python
1
star
50

Analytic_Pulse_Gradients

Code supporting arXiv:XXXX.XXXX "Exact gradients of pulse programs on quantum computers"
Jupyter Notebook
1
star
51

Fourier-sampling

Notes on Fourier sampling and the hidden subgroup problem.
HTML
1
star