Git Product home page Git Product logo

qiskit-ignis's Introduction

Qiskit Ignis (DEPRECATED)

LicenseBuild Status

NOTE As of the version 0.7.0 Qiskit Ignis is deprecated and has been superseded by the Qiskit Experiments project. Active development on the project has stopped and only compatibility fixes and other critical bugfixes will be accepted until the project is officially retired and archived.

Qiskit is an open-source framework for working with noisy quantum computers at the level of pulses, circuits, and algorithms.

Qiskit is made up of elements that each work together to enable quantum computing. This element is Ignis, which provides tools for quantum hardware verification, noise characterization, and error correction.

Migration Guide

As of version 0.7.0, Qiskit Ignis has been deprecated and some of its functionality was migrated into the qiskit-experiments package and into qiskit-terra.

  • Ignis characterization module

    • This module was partly migrated to qiskit-experiments and split into two different modules: qiskit_experiments.library.calibration qiskit_experiments.library.characterization
    • AmpCal is now replaced by FineAmplitude.
    • ZZFitter was not migrated yet.
  • Ignis discriminator module

  • Ignis mitigation module

  • Ignis verification module

    • Randomized benchmarking, Quantum Volume and State and Process Tomography were migrated to qiskit-experiments.
    • Migration of Gate-set tomography to qiskit-experiments is in progress.
    • topological_codes will continue development under NCCR-SPIN, while the functionality is reintegrated into Qiskit. Some additional functionality can also be found in the offshoot project qtcodes.
    • Currently the Accredition and Entanglement modules have not been migrated.
      The following table gives a more detailed breakdown that relates the function, as it existed in Ignis, to where it now lives after this move.
Old New Library
qiskit.ignis.characterization.calibrations qiskit_experiments.library.calibration qiskit-experiments
qiskit.ignis.characterization.coherence qiskit_experiments.library.characterization qiskit-experiments
qiskit.ignis.mitigation qiskit_terra.mitigation qiskit-terra
qiskit.ignis.verification.quantum_volume qiskit_experiments.library.quantum_volume qiskit-experiments
qiskit.ignis.verification.randomized_benchmarking qiskit_experiments.library.randomized_benchmarking qiskit-experiments
qiskit.ignis.verification.tomography qiskit_experiments.library.tomography qiskit-experiments

Installation

We encourage installing Qiskit via the pip tool (a python package manager). The following command installs the core Qiskit components, including Ignis.

pip install qiskit

Pip will handle all dependencies automatically for us and you will always install the latest (and well-tested) version.

To install from source, follow the instructions in the contribution guidelines.

Extra Requirements

Some functionality has extra optional requirements. If you're going to use any visualization functions for fitters you'll need to install matplotlib. You can do this with pip install matplotlib or when you install ignis with pip install qiskit-ignis[visualization]. If you're going to use a cvx fitter for running tomogography you'll need to install cvxpy. You can do this with pip install cvxpy or when you install ignis with pip install qiskit-ignis[cvx]. When performing expectation value measurement error mitigation using the CTMP method performance can be improved using just-in-time compiling if Numbda is installed. You can do this with pip install numba or when you install ignis with pip install qiskit-ignis[jit]. For using the discriminator classes in qiskit.ignis.measurement scikit-learn needs to be installed. You can do this with pip install scikit-learn or when you install ignis with pip install qiskit-ignis[iq]. If you want to install all extra requirements when you install ignis you can run pip install qiskit-ignis[visualization,cvx,jit,iq].

Creating your first quantum experiment with Qiskit Ignis

Now that you have Qiskit Ignis installed, you can start creating experiments, to reveal information about the device quality. Here is a basic example:

$ python
# Import Qiskit classes
import qiskit
from qiskit import QuantumRegister, QuantumCircuit, ClassicalRegister
from qiskit.providers.aer import noise # import AER noise model

# Measurement error mitigation functions
from qiskit.ignis.mitigation.measurement import (complete_meas_cal,
                                                 CompleteMeasFitter, 
                                                 MeasurementFilter)

# Generate a noise model for the qubits
noise_model = noise.NoiseModel()
for qi in range(5):
    read_err = noise.errors.readout_error.ReadoutError([[0.75, 0.25],[0.1, 0.9]])
    noise_model.add_readout_error(read_err, [qi])

# Generate the measurement calibration circuits
# for running measurement error mitigation
qr = QuantumRegister(5)
meas_cals, state_labels = complete_meas_cal(qubit_list=[2,3,4], qr=qr)

# Execute the calibration circuits
backend = qiskit.Aer.get_backend('qasm_simulator')
job = qiskit.execute(meas_cals, backend=backend, shots=1000, noise_model=noise_model)
cal_results = job.result()

# Make a calibration matrix
meas_fitter = CompleteMeasFitter(cal_results, state_labels)

# Make a 3Q GHZ state
cr = ClassicalRegister(3)
ghz = QuantumCircuit(qr, cr)
ghz.h(qr[2])
ghz.cx(qr[2], qr[3])
ghz.cx(qr[3], qr[4])
ghz.measure(qr[2],cr[0])
ghz.measure(qr[3],cr[1])
ghz.measure(qr[4],cr[2])

# Execute the GHZ circuit (with the same noise model)
job = qiskit.execute(ghz, backend=backend, shots=1000, noise_model=noise_model)
results = job.result()

# Results without mitigation
raw_counts = results.get_counts()
print("Results without mitigation:", raw_counts)

# Create a measurement filter from the calibration matrix
meas_filter = meas_fitter.filter
# Apply the filter to the raw counts to mitigate 
# the measurement errors
mitigated_counts = meas_filter.apply(raw_counts)
print("Results with mitigation:", {l:int(mitigated_counts[l]) for l in mitigated_counts})
Results without mitigation: {'000': 181, '001': 83, '010': 59, '011': 65, '100': 101, '101': 48, '110': 72, '111': 391}

Results with mitigation: {'000': 421, '001': 2, '011': 1, '100': 53, '110': 13, '111': 510}

Contribution Guidelines

If you'd like to contribute to Qiskit Ignis, please take a look at our contribution guidelines. This project adheres to Qiskit's code of conduct. By participating, you are expect to uphold to this code.

We use GitHub issues for tracking requests and bugs. Please use our slack for discussion and simple questions. To join our Slack community use the link. For questions that are more suited for a forum we use the Qiskit tag in the Stack Exchange.

Next Steps

Now you're set up and ready to check out some of the other examples from our Qiskit Tutorials repository.

Authors and Citation

Qiskit Ignis is the work of many people who contribute to the project at different levels. If you use Qiskit, please cite as per the included BibTeX file.

License

Apache License 2.0

qiskit-ignis's People

Contributors

1ucian0 avatar chriseclectic avatar dcmckayibm avatar dekelmeirom avatar drewrisinger avatar eggerdj avatar eliarbel avatar gadial avatar garrison avatar hodgestar avatar huangjunye avatar hushaohan avatar jaygambetta avatar kdk avatar kiszk avatar lcapelluto avatar lerongil avatar manoelmarques avatar merav-aharoni avatar mmcelaney avatar mtreinish avatar nkanazawa1989 avatar nonhermitian avatar quantumjim avatar rietesh avatar rmlarose avatar samferracin avatar sethmerkel avatar shellygarion avatar yaelbh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

qiskit-ignis's Issues

Generating the table of the 2-qubit Cliffords

The code in clifford_utils.py, lines 215-223 seems not to be the same as described in the appendix of https://arxiv.org/pdf/1210.7011.pdf (see also the jupyter notebook on the structure of the Clifford group in: https://github.ibm.com/IBMQuantum/qiskit-ignis-internal/pull/83).

In the appendix, the forth class is the "SWAP class", so I think that the code should be:

        h_gates(gatelist, 0, h0)
        h_gates(gatelist, 1, h1)

        v_gates(gatelist, 0, r0)
        v_gates(gatelist, 1, r1)

        cx_gates(gatelist, 0, 1)
        cx_gates(gatelist, 1, 0)
        cx_gates(gatelist, 0, 1)

However, the current code is (this was the original code - I didn't change it):

        h_gates(gatelist, 0, h0)
        h_gates(gatelist, 1, h1)

        cx_gates(gatelist, 0, 1)
        cx_gates(gatelist, 1, 0)
        cx_gates(gatelist, 0, 1)

        v_gates(gatelist, 0, r0)
        v_gates(gatelist, 1, r1)

I checked both options, and both of them produce 11520 elements in the Clifford group, so both options cover all the elements in the group (but using different gate representations).
I also checked test_rb and it runs OK, but test_clifford fails, since the tables (of lists of gates) are not the same.
So in order to change the code I also need to replace the file "test_tables_expected".

Adjusting text of coherence notebook

The text in examples/relaxation_and_decoherence.ipynb talks about amplitude damping and phase damping errors, however the experiments use thermal relaxation errors. We can either change the text, or leave it as it is with a comment about the usage of another error in the code.

Documentation

Currently we have a good README.md file for the project and helpful notebooks. We can improve this further.

  • Add a general description of the goals of state and process tomography.
  • Add a clear description of the algorithms used (mathematics can be written in a dedicated notebook).
  • Add precise documentation for the user-supplied parameters that can affect the tomography process.

Run time of coherence tests

The tests run with 1 or 2 qubits, so I actually wonder why they take so long.
We should profile, as @ShellyGarion did for randomized benchmarking. If compilation seems to be the problem, can we disable the transpiler?
Also related is the question of tests accuracy. The tests set the initial values for the fitter to be the correct fitting parameters. This does not mimic the reality, where the user does not know the correct parameters, so she sets as initial values her inaccurate estimates for the correct parameters.
If we stick with these accurate initial values, then we can decrease the gap (delta) that we allow between the real T1/T2/T2* and the computed one. This was indeed done in test_t2 and test_t2star, but not in test_t1. Alternatively, we can increase delta and decrease the number of shots and data points.

RB Update

  • Remove shots
  • Ability to add all the circuits or add more shots from the save seed
  • Ideally pull off the base fitter class

What is the expected behavior?

state_tomography notebook Error: No Module Named 'error_mitigation'

Informations

  • Qiskit Ignis version: 0.1.0
  • Python version: 3.7.2
  • Operating system: MacOS 10.14

What is the current behavior?

Running the first cell of code in the state_tomography tutorial notebook:

# Needed for functions
import numpy as np
import time

# Import Qiskit classes
import qiskit 
from qiskit import QuantumRegister, QuantumCircuit, ClassicalRegister, Aer
from qiskit.quantum_info import state_fidelity
from qiskit.providers.aer import noise

# Tomography functions
import sys, os
sys.path.append(os.path.abspath(os.path.join('..')))
import qiskit.ignis.verification.tomography as tomo
import qiskit.ignis.error_mitigation.measurement as mc

throws this error:
ModuleNotFoundError: No module named 'qiskit.ignis.error_mitigation'

Steps to reproduce the problem

Run the first code cell in the state_tomography notebook

What is the expected behavior?

Packages should be imported without any errors

Suggested solutions

I replaced the line: import qiskit.ignis.error_mitigation.measurement as mc with
import qiskit.ignis.mitigation.measurement as mc as I saw the folder 'qiskit/ignis/mitigation' was similar to what was being originally called. After I did this I ran through the notebook and the imports did not throw any errors. The other cells seemed to work as well.

AttributeError in randomized_benchmarking Tutorial

Informations

  • Qiskit Ignis version: 0.1.0
  • Python version: 3.7.2
  • Operating system: MacOS version 10.14

What is the current behavior?

AttributeError: 'list' object has no attribute 'split' being thrown in randomized_benchmarking tutorial

Steps to reproduce the problem

Execute all of the cells up to this cell:

backend = qiskit.Aer.get_backend('unitary_simulator')
basis_gates = ['u1', 'u2', 'u3', 'cx']
job = qiskit.execute(qc, backend=backend, basis_gates=basis_gates)
print(np.around(job.result().get_unitary(),3))

Executing this cell will throw the error.

What is the expected behavior?

This output:

[[-0.-1.j  0.+0.j  0.+0.j  0.+0.j -0.+0.j  0.+0.j  0.+0.j  0.+0.j]
 [ 0.+0.j -0.-1.j  0.+0.j  0.+0.j  0.+0.j  0.-0.j  0.+0.j  0.+0.j]
 [ 0.-0.j  0.+0.j -0.-1.j  0.+0.j  0.+0.j  0.+0.j -0.+0.j  0.+0.j]
 [ 0.+0.j  0.-0.j  0.+0.j -0.-1.j  0.+0.j  0.+0.j -0.-0.j  0.-0.j]
 [-0.+0.j  0.+0.j  0.+0.j  0.+0.j -0.-1.j  0.+0.j  0.+0.j  0.+0.j]
 [-0.+0.j  0.+0.j  0.+0.j  0.+0.j  0.+0.j -0.-1.j  0.+0.j  0.+0.j]
 [ 0.+0.j  0.+0.j -0.+0.j -0.+0.j  0.-0.j  0.+0.j -0.-1.j  0.-0.j]
 [ 0.+0.j  0.+0.j -0.+0.j  0.+0.j  0.+0.j  0.-0.j -0.+0.j -0.-1.j]]

Suggested solutions

Converting basis_gates from a list to a string, as the issue seems to be because basis_gates is a list instead of a string.

In coherence, suspected bug in the calculation of the expected state

For T1, I see that the BaseCoherenceFitter constructor is initialized with expected_state=1. Then BaseCoherenceFitter._calc_data contains the lines:

expected_state_list = [self._expected_state] * self._num_of_qubits
expected_state_str = ''.join(expected_state_list)

which generate, for two qubits, expected_state_str='11', instead of 01.

Perhaps I'm wrong, as test_t1 is supposed to fail if there really is a bug.

Fix tests to be deterministic

Right now because some of the tests use aer they are both slow and fail since they are non-deterministic. Can we copy the model of rb and pkl some results to test the fitter? We should still run the circuits through the idea simulator to make sure it doesn't fail.

Informations

  • Qiskit Ignis version:
  • Python version:
  • Operating system:

What is the current behavior?

Steps to reproduce the problem

What is the expected behavior?

Suggested solutions

test_characterization may fail by mistake

Informations

  • Qiskit Ignis version: 0.1.0
  • Python version: 3.6
  • Operating system: Linux

What is the current behavior?

@gadial showed me that test_zz failed for him with:
RuntimeError: Optimal parameters not found: The maximum number of function evaluations is exceeded.

It happened when Gadi submitted a pull request, where the change did not affect test_zz.

The tests in test_characterization.py verify that the following flow runs: circuits generation - backend execution - fitting. The goal is to identify cases where the interface of one of these three components changes, requiring updates in the other components. The error of exceeding the maximum number of evaluations has to be ignored.

Steps to reproduce the problem

What is the expected behavior?

Suggested solutions

Three things, each can be done independently from the others:

  1. Fix the random seed in characterization tests. This will hopefully ensure that such unexpected errors will not occur, in spite of the difference in the simulator's behavior in different platforms.
  2. Catch exceptions: encapsulate calls to fitters' constructors with a try-catch, which will be able to identify errors of mismatch in interfaces. This will probably require also encapsulating the call to curve_fit in the fitters' code.
  3. Consider changing Travis, such that it will run only that tests that can be affected by the change introduced in the pull request.

Characterization: seconds or micro-seconds?

Here is the documentation of t1_circuits:

    Generates circuit for T1 measurement.
    Each circuit consists of an X gate, followed by a sequence of identity
    gates.

    Args:
       num_of_gates (list of integers): the number of identity gates in each
                                        circuit. Must be in an increasing
                                        order.
       gate_time (float): time in micro-seconds of running a single gate.
       qubits (list of integers): indices of the qubits whose T1 are
       to be measured.

    Returns:
       A list of QuantumCircuit
       xdata: a list of delay times in seconds

While gate_time is in micro-seconds, the unit of delay time is xdata are said to be seconds. I assume that this is incorrect, for xdata? The implementation itself does not convert between units.

Error in RB Fitter

There's an error if one of the standard deviations is zero
eg

[{'mean': array([0.98 , 0.905, 0.815, 0.58 , 0.43 , 0.42 , 0.38 ]),
  'std': array([0.   , 0.015, 0.045, 0.04 , 0.05 , 0.03 , 0.05 ])}]

ValueError: Residuals are not finite in the initial point.

Add ZZ

What is the expected behavior?

Testing and code quality

Currently the Tomography module lacks any sort of tests, and although the code quality is good, there are still some linter errors.

  • Ensure the code is lint-error free.
  • Add unit tests to the major parts of the code (fitters, circuit generation)
  • Add tests for the full run of the workflow (similar to what is performed in the notebooks).

Interface for performing state tomography

It seems to me that currently state tomography consists of one clear entrance point - a circuit and a list of qubits - and one clear exit point, namely the density operator. Currently, it is up to the user to move data around - generate the tomography circuits, run the simulator on them, format the data for the fitter and run the fitter itself.

It will be helpful to have a wrapper function such as
def perform_state_tomography(circuit, measured_qubits, **kwargs)
that outputs the density operator after the tomography is complete. The control over the tomography process (e.g. the number of shots in the simulator runs, the simulator to use, the fitter to use etc.) will be done via keywords with sensible default values.

We can also add support for a hash, qobj-like data structure which will explicitly contain the circuits, the intended measured qubits and the additional keywords. I already have a basic implementation along these lines.

Performing state tomography for subsets of qubits fails

The following code works well:

q3 = QuantumRegister(3)
circuit = QuantumCircuit(q3)
circuit.h(q3[2])
rho = perform_state_tomography(circuit, q3)

Where perform_state_tomography is a wrapper function I wrote for the state tomography workflow. The result is the correct 8x8 density matrix.

I am also able to compute the 4x4 density matrix for the first two qubits by performing

q2 = [q3[0], q3[1]]
rho = perform_state_tomography(circuit, q2)

However, this fails for other subsets. For instance,

q2 = [q3[0], q3[2]]
rho = perform_state_tomography(circuit, q2)

Fails with the following error:

AerBackend: simulation failed
Traceback (most recent call last):
  File "C:/Users/gadia/Documents/Quantum/qiskit-ignis-internal/test.py", line 116, in <module>
    rho = perform_state_tomography(circuit, q2)
  File "C:\Users\gadia\Documents\Quantum\qiskit-ignis-internal\verification\tomography\interface.py", line 11, in perform_state_tomography
    tomography_data_results = tomography_data(job.result(), tomography_circuits)
  File "C:\Program Files\Anaconda3\lib\site-packages\qiskit_aer\backends\aerjob.py", line 37, in _wrapper
    return func(self, *args, **kwargs)
  File "C:\Program Files\Anaconda3\lib\site-packages\qiskit_aer\backends\aerjob.py", line 92, in result
    return self._future.result(timeout=timeout)
  File "C:\Program Files\Anaconda3\lib\concurrent\futures\_base.py", line 398, in result
    return self.__get_result()
  File "C:\Program Files\Anaconda3\lib\concurrent\futures\_base.py", line 357, in __get_result
    raise self._exception
  File "C:\Program Files\Anaconda3\lib\concurrent\futures\thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "C:\Program Files\Anaconda3\lib\site-packages\qiskit_aer\backends\aerbackend.py", line 161, in _run_job
    self._validate_controller_output(output)
  File "C:\Program Files\Anaconda3\lib\site-packages\qiskit_aer\backends\aerbackend.py", line 190, in _validate_controller_output
    raise AerSimulatorError(res.get("status", None))
qiskit_aer.backends.aersimulatorerror.AerSimulatorError: 'ERROR: invalid stoull argument'

I'm not sure I understand what causes this error. I can debug it myself, but maybe you have a clear idea on why this fails.

RB and Cliffords for 1&2 qubits

A lighter version of the RB & Clifford module in Ignis only for 1&2 qubits, independent of the general Clifford module that should be added in Terra.

The output Cliffords will be in the form: (H.P.V) where H is either H or I, P is the Pauli and V is the axis swap group (I, V, W).

The code will include the following files:

  • Clifford.py // Clifford object
  • clifford_utils.py // generating the Clifford tables, random Clifford, inverse Clifford
  • randomizedbenchmarking.py // RB code
  • rb_fitters.py // RB fitters

As well as Jupyter tutorial notebooks:

  • RBn.ipynb // RB for 2 qubuts
  • Clifford.ipynb // Cliffords for 1&2 qubits

Readme

We need to create a readme

Measurement Mitigation using Tensored Calibrations

Currently the measurement mitigation constructs a correction matrix by preparing all 2^N basis states. If measurement noise is independent (ie. no crosstalk) we can construct the correction matrix from 2 (or N) calibrations (each qubit in the excited state together or separately). Still need to construct a 2^N matrix although we might be able to use sparse matrix tools.

What is the expected behavior?

Tomography Fitter class

It might make sense to define a base TomographyFitter class so that additional fitters can be added that share a common interface.

At minimum it would needs to be able to read load the output from the tomography_data function and return a fitted density matrix.

With respect to the current code, this would mean the fitter_data function which converts the tomography data into the format for the least squares fitting used by the mle and cvx fit would just become an internal function called by those fitters, and the mle_fit and cvx_fit functions would be inside the classes.

Mode of work with other Qiskit repositories

As we work on Ignis, we need to understand how we cope with other repositories on whom Ignis depends, e.g. Terra and Aer. Essentially there are two options:

  1. Always try that Ignis master branch works with the master branches of the other repositories.
  2. Make Ignis master branch work with the stable branches of the other repositories.

I prefer Option (2), but I think Aer and Aqua tend to work with Option (1), so it's OK too. The reason that I prefer Option (2) is that, with Option (1), we may find ourselves too busy in adjusting to frequent changes in Terra interfaces. Also we will depend on the master branch of Aer to be updated with the master branch of Terra. I think Option (2) is cleaner.

Decision here will affect:

  • Instructions in .github/CONTRIBUTING.rst.
  • Content of requirements.txt and requirements-dev.txt.
  • A question that came up in the context of randomized benchmarking, about the representation of basis gates (as a string, e.g. 'u1,u2,u3,cx', or as a list of strings, e.g. ['u1', 'u2', 'u3', 'cx']).

Logging

Put very rough logging in

Generalize T2 Echo to CPMG

In the T2 Echo there is one pi pulse, generalize to a CPMG sequence (essentially the same sequence except the number of echo's is a parameter).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.