Skip to content
minwook edited this page Nov 9, 2023 · 2 revisions

Introducing : Qiskit-classroom-converter, a Qiskit Ecosystem package for Converting Features

Author: minwook-shin (KMU Quantum Classroom team)

Qiskit-classroom-converter is a recent addition to the Qiskit Ecosystem Community Tier!

Read on to learn more about this new member of our open-source community and how you can use it in your quantum code!

What is Qiskit-classroom-converter?

The Qiskit classroom converter contains a Python package that can convert different expressions, such as quantum circuits, matrices, and bra-ket notation.

  • quantum circuit to bra-ket notation
  • quantum circuit to matrix
  • matrix to quantum circuit
  • string to bra-ket notation
  • Getting Started with Qiskit-classroom-converter

Examples of how to use the package to convert different expressions, such as quantum circuits to matrices, matrices to quantum circuits, and quantum circuits to bra-ket notations.

Before you start

from qiskit import QuantumCircuit, transpile
from qiskit_aer import AerSimulator
from qiskit_class_converter import ConversionService

matrix to quantum circuit

input_value = [
[1, 0, 0, 0],
[0, 0, 0, 1],
[0, 0, 1, 0],
[0, 1, 0, 0]
]

sample_converter = ConversionService(conversion_type="MATRIX_TO_QC", option={"label": "CX gate"})
result = sample_converter.convert(input_value=input_value)
quantum_circuit = QuantumCircuit(2, 2)
quantum_circuit.x(0)
quantum_circuit.append(result, [0, 1])
quantum_circuit.measure(range(2), range(2))
backend = AerSimulator()
qc_compiled = transpile(quantum_circuit, backend)
counts = backend.run(qc_compiled).result().get_counts()

You will get the variables : quantum_circuit, qc_compiled's counts

quantum_circuit : (or circuit_drawer(quantum_circuit, output= "mpl"))

     ┌───┐┌──────────┐┌─┐
q_0: ┤ X ├┤0         ├┤M├───
     └───┘│  CX gate │└╥┘┌─┐
q_1: ─────┤1         ├─╫─┤M├
          └──────────┘ ║ └╥┘
c: 2/══════════════════╩══╩═
                       0  1

qc_compiled's counts : {'11': 1024}

quantum circuit to matrix

quantum_circuit = QuantumCircuit(2, 2)
quantum_circuit.x(0)
quantum_circuit.cx(0, 1)
sample_converter = ConversionService(conversion_type="QC_TO_MATRIX")
var = sample_converter.convert(input_value=quantum_circuit)

You will get the variables : var["gate"], var["name"], var["result"]

var["gate"]: Computed the matrix list value of the gate

[array([[0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j],
       [1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],
       [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j],
       [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j]]),
 array([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],
       [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j],
       [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j],
       [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j]])]

var["name"]: Computed the name list value of the gate

[(0, ['I_{q1}', 'X_{q0}']), (1, ['CX_{q0, q1}'])]

var["result"]: final calculated matrix

array([[0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j],
       [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j],
       [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j],
       [1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j]])

See more Feature examples as Jupyter notebooks:

https://github.com/KMU-quantum-classroom/qiskit-classroom-converter/blob/main/qiskit_classroom_converter_public_demo.ipynb

Future Work

We'll be further developing conversions and adding new conversions.

As an example, we are working on the feature to complete circuits by guessing gates from the matrix.

also working on a project to visualize the converting results in a GUI application. https://github.com/KMU-quantum-classroom/qiskit-classroom

If you are interested in learning more about the project, check out the GitHub here https://github.com/KMU-quantum-classroom/qiskit-classroom-converter.