You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The output of Pytket when reading the QASM and exporting it again should preserve the semantics, maintaining the original register positions. This behavior is consistent with other platforms like Qiskit, PennyLane, and BQSKit.
Actual behavior
Pytket reorders the register positions (probably in alphabetical order), causing the program to change when compared to the imported one. This reordering affects the semantics of the circuit.
Additional information
This issue is reproducible 100% of the time. It is crucial to maintain the original order of registers for the composability of circuits expressed in QASM. Arbitrary reordering of registers can create problems when integrating subcircuits.
Below a possible end-user usage of this function where the difference could be observed:
# add one X gate at the register in position 1fromqiskitimportQuantumCircuitfromqiskit.qasm2importloadsqc_input=QuantumCircuit(5)
qc_input.x(1)
# original circuitcircuit_a=loads(qasm_str)
# imported via pytket - registers reorderedcircuit_b=loads(qasm_str_reordered_by_pytket)
# original circuitqc_w_input_original=circuit_a.compose(
qc_input, front=True)
print(qc_w_input_original)
# imported circuitqc_w_input_buggy=circuit_b.compose(
qc_input, front=True)
print(qc_w_input_buggy)
# compare the statevectorssv_w_input_original=Statevector.from_instruction(qc_w_input_original)
probabilities_w_input_original=sv_w_input_original.probabilities_dict()
print("Probabilities W Input Original: ", probabilities_w_input_original)
sv_w_input_buggy=Statevector.from_instruction(qc_w_input_buggy)
probabilities_w_input_buggy=sv_w_input_buggy.probabilities_dict()
print("Probabilities W Input - After PyTket Reordering: ", probabilities_w_input_buggy)
Output:
cin: ──────────
┌───┐
a_0: ┤ X ├──■──
└───┘ │
a_1: ───────┼──
┌─┴─┐
b_0: ─────┤ X ├
└───┘
b_1: ──────────
a_0: ───────■──
┌───┐ │
a_1: ┤ X ├──┼──
└───┘┌─┴─┐
b_0: ─────┤ X ├
└───┘
b_1: ──────────
cin: ──────────
Probabilities W Input Original: {'01010': 1.0}
Probabilities W Input - After PyTket Reordering: {'00010': 1.0}
As observed, the probabilities are different, indicating that the circuit has changed after being imported and exported by Pytket. This is common when a user wants to optimize a circuit using Pytket and then export it back to QASM.
Hi @MattePalte ,
Thank you for reporting this.
It is a bit tricky for us to solve this at the moment and it will probably take some time for us to address this.
Expected behavior
The output of Pytket when reading the QASM and exporting it again should preserve the semantics, maintaining the original register positions. This behavior is consistent with other platforms like Qiskit, PennyLane, and BQSKit.
Actual behavior
Pytket reorders the register positions (probably in alphabetical order), causing the program to change when compared to the imported one. This reordering affects the semantics of the circuit.
Additional information
This issue is reproducible 100% of the time. It is crucial to maintain the original order of registers for the composability of circuits expressed in QASM. Arbitrary reordering of registers can create problems when integrating subcircuits.
Source code
Run the following code to reproduce the issue:
Below a possible end-user usage of this function where the difference could be observed:
Output:
As observed, the probabilities are different, indicating that the circuit has changed after being imported and exported by Pytket. This is common when a user wants to optimize a circuit using Pytket and then export it back to QASM.
System
Output:
The text was updated successfully, but these errors were encountered: