Skip to content
This repository has been archived by the owner on Jun 12, 2023. It is now read-only.

Refactor RB code to use the new Clifford operator class #392

Closed
ShellyGarion opened this issue Apr 19, 2020 · 5 comments · Fixed by #407
Closed

Refactor RB code to use the new Clifford operator class #392

ShellyGarion opened this issue Apr 19, 2020 · 5 comments · Fixed by #407
Labels
enhancement New feature or request

Comments

@ShellyGarion
Copy link
Contributor

ShellyGarion commented Apr 19, 2020

What is the expected behavior?

Refactor RB code to use the new Clifford operator class from Terra (Qiskit/qiskit#3938) and the new CNOT-Dihedral class (#391).

This will allow:

  • More efficient RB.
  • Not need to use per-generated tables (pkl files) for the 2-qubit groups.
  • RB on the Clifford group for more than 2 qubits.

The files that should be updated in https://github.com/Qiskit/qiskit-ignis/tree/master/qiskit/ignis/verification/randomized_benchmarking:

  • basic_utils.py
  • circuits.py
  • clifford_utils.py
  • dihedral_utils.py
  • Clifford.py should be deleted

The following tests should be updated in https://github.com/Qiskit/qiskit-ignis/tree/master/test/rb:

  • test_clifford.py should be deleted
  • test_rb.py should include tests for RB on the Clifford group with more than 2 qubits

Depends on #391.

@ShellyGarion ShellyGarion added the enhancement New feature or request label Apr 19, 2020
@ShellyGarion
Copy link
Contributor Author

The refactor will be done in the following steps:

  1. update the code of circuits.py and clifford_utils.py to use the new Clifford operator class from Terra. Remove from RB code the files: Clifford.py and test_clifford.py.
    At this step, we will keep the utils functions for generating the 1 & 2 qubit Clifford group tables
    (and saving them in pkl file), to keep the API consistent with dihedral_utils.py.

  2. Depends on the merge of Update the CNOT-Dihedral class for RB #391.
    update the code for:
    basic_utils.py, circuits.py, clifford_utils.py, dihedral_utils.py ,
    so that it will not require generating the group tables (and saving them in pkl file) anymore.

  3. Add tests to test_rb.py for RB on the Clifford group with more than 2 qubits.

@ShellyGarion
Copy link
Contributor Author

Another approach will be to do the refactor in the following steps:

  1. refactor the code of circuits.py to use the new Clifford operator class from Terra, and remove clifford.py from RB code.
    In this case, do we still need the code for clifford_utils.py (which was mainly used to generate the 1&2 Clifford group tables) or can it be removed?

  2. refactor the code of dihedral.py and the CNOTDihedral class, so that it will include all the functionality for RB that appears in the Clifford operator class.
    Again, do we still need the code for dihedral_utils.py (which was mainly used to generate the 1&2 group tables) or can it be removed?

  3. Add tests to test_rb.py for RB on the Clifford group with more than 2 qubits.

@ShellyGarion
Copy link
Contributor Author

ShellyGarion commented May 11, 2020

  1. Here is a list of functions used in circuits.py and appear in basic_utils.py for which the Clifford operator class in Terra has similar methods:
  • compose_gates --> compose
    should compose two Clifford / CNOTDihedral elements instead of adding gates to an element.

  • gatelist --> to_circuit
    should be implemented using the decompose methods and return a QuantumCircuit (instead of a list of strings).

  • find_inverse_gates - should be replaced by to_circuit to decompose the Clifford / CNOTDihedral element to return the QuantumCircuit and then do inverse.

  • get_quantum_circuit --> to_circuit
    should decompose a random Clifford / CNOTDihedral element (or interleaved element) into a QuantumCircuit

  1. The following functions are used in circuits.py but are not methods in the Clifford operator class:
  • initialization from num_qubits (current code in circuits.py is: g_group(rb_q_num) )

  • random_gates --> random
    should return a Clifford / CNOTDihedral element and not a list of gates.
    This is not a method in the Clifford operator class, but there is a function called random_clifford How can we have the same API for using random_clifford or random_cnotdihedral according to the group (e.g. g_group.random)?

  1. The following functions used in circuits.py and appear in basic_utils.py should be removed (since we don't need to use tables):
  • load_tables
  • find_key

@ShellyGarion
Copy link
Contributor Author

ShellyGarion commented May 12, 2020

Summary of questions:

  1. Should we keep the classes in basic_utils.py, clifford_utils.py and dihedral_utils.py ?
    (since they mainly handled the 1&2 qubit group tables)
    Another option is to replace these 3 classes by only one class that will hold the group methods needed for RB (and choose between the Clifford and CNOTDihedral group operations)

  2. How to perform a general initialization by num_qubits, e.g. elem = g_group(rb_q_num)?
    (since the Clifford operator class does not have such method)

  3. How to perform a general random method, e.g. elem = g_group.random ?
    (since the Clifford operator class does not have a random method, but there is a function random_clifford)

  4. Should there be an inverse function that returns the inverse QuantumCircuit,
    and if so - where to put it?
    Alternatively, we can use the to_circuit method and then do inverse of the QuantumCircuit.

  5. We should update the API for interleaved RB:
    instead of:
    interleaved_gates: A list of lists of gates that will be interleaved (Optional[List[List[str]]]),
    the input will be:
    interleaved_elmnt: A list of group elements (Cliffords / CNOTDihedral).

  6. Can we remove the function: replace_q_indices - is there a function in Terra with the same functionality?
    https://github.com/Qiskit/qiskit-ignis/blob/03008653163937ea53ad7ba1cd0546aeba47fb3c/qiskit/ignis/verification/randomized_benchmarking/circuits.py#L567

@ShellyGarion
Copy link
Contributor Author

ShellyGarion commented May 12, 2020

It seems that the best solution will be to have one class (g_utils or GroupUtils or rb_groups) that will be used in circuits.py and will handle the group methods, like the initialization and random (choose between random_clifford and random_cnotdihedral).
In this case, all group methods will be done in this class, the code in circuits.py will be agnostic to it.

@ShellyGarion ShellyGarion changed the title Refactor RB code to use the new Clifford operator class [WIP] Refactor RB code to use the new Clifford operator class May 17, 2020
@ShellyGarion ShellyGarion changed the title [WIP] Refactor RB code to use the new Clifford operator class Refactor RB code to use the new Clifford operator class May 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
1 participant