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
# Install Qiskit version 1.2.0
RUN pip install --no-cache-dir qiskit==1.2.1
RUN pip install qiskit-aer==0.15.1 qiskit-ibm-runtime==0.29.1
RUN pip install pytket==1.32.0 pytket-qiskit==0.56.0
Expected behavior
I expect the code to successfully export a Qiskit circuit to a Pytket QASM file without any errors, e.g. by renaming the registers to conform to the QASM specification. Because this would be more robust and in line with a user expects from other quantum computing platforms such as Qiskit and BQSKit.
Actual behavior
The code raises a QASMUnsupportedError when trying to export the Qiskit circuit to a Pytket QASM file. The error occurs because the platform tries to export a QASM with a register name '4' which is invalid according to the QASM specification.
Additional information
This issue occurs every time the code is run with the same register names. The error does not occur when we either use another platform (e.g. Qiskit or BQSKit) or rename the registers to conform to the QASM specification. Note that the other platforms rename the registers automatically to conform to the QASM specification.
Source code
fromqiskitimportQuantumRegister, ClassicalRegister, QuantumCircuitfromqiskitimportqasm2frompytket.extensions.qiskitimportqiskit_to_tkfrompytket.qasmimportcircuit_to_qasm_strfrompathlibimportPath# Create quantum and classical registers with valid namesqr=QuantumRegister(3, '4')
cr=ClassicalRegister(3, 'c4')
circuit=QuantumCircuit(qr, cr)
print(circuit.draw(output='text'))
# Export Qiskit circuit to QASM file using qasm2qasm_str_qiskit=qasm2.dumps(circuit)
print("Qiskit-generated QASM:")
print(qasm_str_qiskit)
# Export Qiskit circuit to Pytket QASM filetket_circ=qiskit_to_tk(circuit)
qasm_str_tket=circuit_to_qasm_str(tket_circ, header='qelib1', maxwidth=200)
file_path_pytket=Path('simple_pytket.qasm')
withopen(file_path_pytket, 'w') asf:
f.write(qasm_str_tket)
print(f'Saved the Pytket circuit to {file_path_pytket}')
# Expected output: the QASM file is successfully generated and saved
Tracebacks
---------------------------------------------------------------------------QASMUnsupportedErrorTraceback (mostrecentcalllast)
CellIn[5], line2119# Export Qiskit circuit to Pytket QASM file20tket_circ=qiskit_to_tk(circuit)
--->21qasm_str_tket=circuit_to_qasm_str(tket_circ, header='qelib1', maxwidth=200)
22file_path_pytket=Path('simple_pytket.qasm')
23withopen(file_path_pytket, 'w') asf:
File/python3.10/site-packages/pytket/qasm/qasm.py:1115, incircuit_to_qasm_str(circ, header, include_gate_defs, maxwidth)
1100"""Convert a Circuit to QASM and return the string. 1101 1102 Classical bits in the pytket circuit must be singly-indexed. (...) 1111 :return: qasm string 1112 """1114check_can_convert_circuit(circ, header, maxwidth)
->1115qasm_writer=QasmWriter(
1116circ.qubits, circ.bits, header, include_gate_defs, maxwidth1117 )
1118circ1=circ.copy()
1119DecomposeBoxes().apply(circ1)
File/python3.10/site-packages/pytket/qasm/qasm.py:1380, inQasmWriter.__init__(self, qubits, bits, header, include_gate_defs, maxwidth)
1378forreginself.qregs.values():
1379ifregname_regex.match(reg.name) isNone:
->1380raiseQASMUnsupportedError(
1381f"Invalid register name '{reg.name}'. QASM register names must "1382"begin with a lowercase letter and may only contain lowercase "1383"and uppercase letters, numbers, and underscores. "1384"Try renaming the register with `rename_units` first."1385 )
1386forbit_reginself.cregs.values():
1387ifregname_regex.match(bit_reg.name) isNone:
QASMUnsupportedError: Invalidregistername'4'. QASMregisternamesmustbeginwithalowercaseletterandmayonlycontainlowercaseanduppercaseletters, numbers, andunderscores. Tryrenamingtheregisterwith`rename_units`first.
The text was updated successfully, but these errors were encountered:
Thanks for the report. I think raising an error in this case is OK: the user is free to rename the registers (as suggested in the error message); and silently renaming them could cause more confusion than it saves.
System version
# Install Qiskit version 1.2.0 RUN pip install --no-cache-dir qiskit==1.2.1 RUN pip install qiskit-aer==0.15.1 qiskit-ibm-runtime==0.29.1 RUN pip install pytket==1.32.0 pytket-qiskit==0.56.0
Expected behavior
I expect the code to successfully export a Qiskit circuit to a Pytket QASM file without any errors, e.g. by renaming the registers to conform to the QASM specification. Because this would be more robust and in line with a user expects from other quantum computing platforms such as Qiskit and BQSKit.
Actual behavior
The code raises a QASMUnsupportedError when trying to export the Qiskit circuit to a Pytket QASM file. The error occurs because the platform tries to export a QASM with a register name '4' which is invalid according to the QASM specification.
Additional information
This issue occurs every time the code is run with the same register names. The error does not occur when we either use another platform (e.g. Qiskit or BQSKit) or rename the registers to conform to the QASM specification. Note that the other platforms rename the registers automatically to conform to the QASM specification.
Source code
Tracebacks
The text was updated successfully, but these errors were encountered: