Skip to content

Demonstration of Envariance and Parity Learning on IBM Quantum Experience

License

Notifications You must be signed in to change notification settings

DavideFrr/ibmqx_experiments

Repository files navigation

DISCONTINUED

This repository will no longer be updated, go to https://github.com/qis-unipr/QuantumComputing for an updated version.

IBMQX Experiments

The purpose of this repository is to demonstrate entanglement assisted invariance, also known as envariance, and parity learning by querying a uniform quantum example oracle, using IBM QX series quantum computers.

Requirements

In order to run the experiments or just work with this repository you'll need to setup the QISKit sdk, detailed instructions cn be found here.

You'll also need to register on IBM Quantum Experience in order to receive your API Token (a key to grant you access to IBM QX quantum computers) and have at least 5 credits on that account.

Utility

The core of the problem is to find the qubit that is most connected; by most connected we mean that it can be connected (directly or not) by means of cnot gates to as many other qubits as possible.

utility.py contains all the functions needed to find the most connected qubit, given coupling-map, and than proceed to create the circuits for envariance demonstration and parity learning respectivly.

We have designed an algorithm that, given the map and the number of qubits to be used in the experiment, finds the most connected qubit and start building the GHZ circuit from that qubit. By most connected, we mean that the qubit can be reached by as many other qubits as possible through directed paths in the coupling map.

The objective is to assign every node x a rank, defined as the number of nodes that can reach x along the directed edges of the coupling map. The node with the highest rank is then selected as the starting point for building the circuit.

All of the above is done by the explore(), whose objective is to assign a rank (the counter incremented when a node is reached) to every node based on how many nodes can reach it. The node with the higher rank will be selected as the start point for building our circuit.

As soon as the most connected qubit has been found, the create_path() function is executed, in order to obtain a path connecting all the qubits that must be involved in the GHZ circuit.

The place_cx() function walks the aforementioned path and uses the cx() function to put across each node pair either a CNOT or an inverse-CNOT gate, depending on the direction of the link dictated by the coupling map. Parameter k in place_cx() allows to reuse the function to build other circuits than GHZ. More specifically, k=11 corresponds to the GHZ circuit.

Before launching an experiment on a specific device, you'll have to create a new Utility() object, the constructor takes the device coupling-map as a parameter; when you're done experimenting with that device you'll then need to close() the Utility object.

In order to launch an exepriment, utility.py defines two methods (envariance_exec() and parity_exec()) which use will be discussed later on.

ibmqx5 coupling-map graphic rapresentation:

qx5_coupling-map

coupling-map python rapresentation:

coupling_map_qx5 = {
    0: [],
    1: [0, 2],
    2: [3],
    3: [4, 14],
    4: [],
    5: [4],
    6: [5, 7, 11],
    7: [10],
    8: [7],
    9: [8, 10],
    10: [],
    11: [10],
    12: [5, 11, 13],
    13: [4, 14],
    14: [],
    15: [0, 2, 14],
}

Couplings between qubits in the resulting circuits, for QX4 and QX5 respectively:

qx4_circ_mapqx5_circ_map

Red arrows means the use of inverse cnot

Envariance

envariance.py is were you'll launch envariance experiments; all you need to do is to create utility object (the constructor takes the device coupling-map as its only parameter, coupling-maps can be imported from coupling_maps.py) and then use the envariance_exec() method to launch the experiment. This methods needs several parameter:

  • execution, the number of the execution in case you're running the experiment multiple times
  • device, the device on wich yuo want to run the experiment (you can import device name from devices.py)
  • utility, the utility object created before
  • n_qubits, the number of qubits to be used
  • num_shots, number of shots fro the execution (default to 1024)
  • directory, the directory to store experiments results (default to 'Data_Envariance/')

All results of the executions will be stored in txt files for later use. More info in the code.

qx4_5-qubits_env_circ

qx5_16-qubits_env_circ

Envariance circuits with 5 qubits and 16 qubits, on QX4 and QX5 respectively

Fidelity

You can use fidelity.py to estimate the classical fidelity of every execution and average them together. It is also possible to use envariance_values_base2.py and envariance_values_base10.py to se an overall distribution of all the strings values measured during all executions (encoded in base 2 and 10 respectively).

Parity

In parity.py you will run parity learning experiments; as for envariance experiments there's a method to launch this kind of experiment, parity_exec().

The only difference is that it takes an extra parameter to set the string that the oracle will learn:

  • oracle, can either be '11' for '11..11' like strings, '10' for '10..10' strings or '00' for '00..00' strings

All results of the executions will be stored (by default in 'Data_Parity', you can change it with the directory parameter)in txt files for later use. More info in the code.

qx5_16-qubits_par-00_circ

qx5_16-qubits_par-10_circ

qx5_16-qubits_par-11_circ

Parity circuits with 15 qubits on QX5, for k='00', k='10' and k='11' respectively

Bit-Wise Error

For the parity learning experiment, provided the noise isn’t too large, each bit of the output is still correct more than half the time. What we do is:

  • select only the results where the result qubit is 1
  • keep track of the results for each bit separately
  • use whichever result (0 or 1) is most common for each bit (in case they are equal, select randomly)

Every time the resulting string is correct we have a success, dividing the number of successes by the number of executions we obtain the success probability and also the error probability.

All of it can be done by running bit_wise_error.py, which will store the results in a txt file.

About

Demonstration of Envariance and Parity Learning on IBM Quantum Experience

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages