Does anyone know of a library to convert a parametrized qiskit circuit drawn as 'text' back to a QuantumCircuit
or similar?
I have see [this] 1 question, but unfortunately I cannot determine in which format the circuit has been saved. I need to start of a file in which the drawn circuit has been saved as text like this:
┌────┐ ┌────────┐ ┌──────────┐┌───┐ ░ ┌─┐
q_0 -> 1 ──┤ √X ├────┤ Rz(3π) ├─┤ Rz(p[2]) ├┤ X ├─░─┤M├─────────
┌─┴────┴─┐ ┌┴────────┴┐└──────────┘└─┬─┘ ░ └╥┘ ┌─┐
...
meas: 4/════════════════════════════════════════════╩══╩══╩══╩═
In more detail the saved file in my case is a text file looking like this: It is a dictionary converted to a string using json. The values of the dictionary are lists of the ascii-art strings of the circuits generated by QuantumCircuit.draw():
{'ansatz 1':"[' ┌───┐ ┌──────────┐ ┌──────────┐┌──────────┐┌───┐ ░ ┌─┐ »\n q_0: ───┤ X ├─────┤ Rz(p[0]) ├─┤ Ry(p[1]) ├┤ Rz(p[2]) ├┤ X ├──────░─┤M├───»\n ├───┤ ├──────────┤ ├──────────┤├──────────┤└─┬─┘┌───┐ ░ └╥┘┌─┐»\n q_1: ───┤ X ├─────┤ Rz(p[3]) ├─┤ Ry(p[4]) ├┤ Rz(p[5]) ├──┼──┤ X ├─░──╫─┤M├»\n ┌──┴───┴───┐ ├──────────┤ ├──────────┤└──────────┘ │ └─┬─┘ ░ ║ └╥┘»\n q_2: ┤ Rz(p[6]) ├─┤ Ry(p[7]) ├─┤ Rz(p[8]) ├─────■────────■────┼───░──╫──╫─»\n ├──────────┤┌┴──────────┤┌┴──────────┤ ┌─┴─┐ │ ░ ║ ║ »\n q_3: ┤ Rz(p[9]) ├┤ Ry(p[10]) ├┤ Rz(p[11]) ├───┤ X ├───────────■───░──╫──╫─»\n └──────────┘└───────────┘└───────────┘ └───┘ ░ ║ ║ »\nmeas: 4/════════════════════════════════════════════════════════════════╩══╩═»\n 0 1 »\n« \n« q_0: ──────\n« \n« q_1: ──────\n« ┌─┐ \n« q_2: ┤M├───\n« └╥┘┌─┐\n« q_3: ─╫─┤M├\n« ║ └╥┘\n«meas: 4/═╩══╩═\n« 2 3 ', '...}
QuantumCircuit.qasm()
method and load it usingQuantumCircuit.from_qasm_str()
method orQuantumCircuit.from_qasm_file()
method. I can write a detailed answer if this is what you want. $\endgroup$qasm()
: qiskit.org/documentation/stubs/… ,from_qasm_str()
: qiskit.org/documentation/stubs/… $\endgroup$