-
Notifications
You must be signed in to change notification settings - Fork 0
Home
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!
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.
from qiskit import QuantumCircuit, transpile
from qiskit_aer import AerSimulator
from qiskit_class_converter import ConversionService
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 = 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:
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.
If you are interested in learning more about the project, check out the GitHub here https://github.com/KMU-quantum-classroom/qiskit-classroom-converter.