iqm-pulla 9.0.0__py3-none-any.whl → 9.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
iqm/pulla/utils_qir.py CHANGED
@@ -34,10 +34,11 @@ from pyqir import (
34
34
  required_num_results,
35
35
  result_id,
36
36
  )
37
+ from qiskit import QuantumCircuit
38
+ from qiskit.providers import BackendV2
37
39
 
38
40
  from iqm.cpc.compiler.compiler import Compiler
39
41
  from iqm.cpc.interface.compiler import Circuit as CPC_Circuit
40
- from iqm.pulla.pulla import Pulla
41
42
  from iqm.pulse.builder import CircuitOperation
42
43
 
43
44
  qir_logger = logging.getLogger(__name__)
@@ -147,19 +148,20 @@ def _parse_double(value: str) -> float:
147
148
 
148
149
 
149
150
  def qir_to_pulla( # noqa: PLR0915, PLR0912
150
- pulla: Pulla, qir: str | bytes, qubit_mapping: dict[int, str] | None = None
151
+ compiler: Compiler, qir: str | bytes, qubit_mapping: dict[str, str] | None = None
151
152
  ) -> tuple[list[CPC_Circuit], Compiler]:
152
153
  """Convert a QIR module to a CPC circuit.
153
154
 
154
155
  Args:
155
- pulla: The Pulla instance to get compiler from.
156
+ compiler: compiler to use
156
157
  qir: The QIR source or bitcode to convert to a circuit.
157
158
  qubit_mapping: A dictionary mapping QIR qubit indexes to physical qubit names,
158
159
  None will assume opaque pointers match physical names.
159
160
 
160
161
  Returns:
161
162
  str: The QIR program name,
162
- tuple[CircuitOperation, ...]: The circuit operations extracted from the QIR code.
163
+ tuple[list[Circuit], Compiler]:
164
+ Circuits extracted from the QIR module and the compiler with updated component_mapping
163
165
 
164
166
  Raises:
165
167
  ValueError: If the QIR program has more than one basic block.
@@ -240,14 +242,11 @@ def qir_to_pulla( # noqa: PLR0915, PLR0912
240
242
  circuits = [CPC_Circuit(name=name, instructions=circuit_instructions)]
241
243
  qir_logger.debug("Converted circuit: %s", circuits)
242
244
 
243
- # Create a compiler containing all the required station information
244
- compiler = pulla.get_standard_compiler()
245
-
246
245
  if qubit_mapping:
247
246
  # QIR programs reference to qubits as opaque pointer indexes,
248
247
  # however, for example qiskit is using logical names for qubits,
249
248
  # so we need to map these indexes to physical qubit names
250
- compiler.component_mapping = {f"{i}": qubit_mapping[i] for i in range(_required_num_qubits)}
249
+ compiler.component_mapping = {f"{i}": qubit_mapping[str(i)] for i in range(_required_num_qubits)}
251
250
  else:
252
251
  # QIR programs reference to qubits as opaque pointer indexes,
253
252
  # we expect these indexes to match physical qubit names,
@@ -256,3 +255,33 @@ def qir_to_pulla( # noqa: PLR0915, PLR0912
256
255
  compiler.component_mapping = {f"{i}": f"QB{i + 1}" for i in range(_required_num_qubits)}
257
256
 
258
257
  return circuits, compiler
258
+
259
+
260
+ def generate_qiskit_qir_qubit_mapping(qiskit_circuit: QuantumCircuit, qiskit_backend: BackendV2) -> dict[str, str]:
261
+ """qiskit-qir has a bug, which causes qubit pointers to not be generated correctly
262
+ according to the final_layout. So we replicate this logic here and generate a new mapping.
263
+ Then we assign qiskit-qir index to the qiskit logic qubit idx.
264
+
265
+ Args:
266
+ qiskit_circuit: Qiskit circuit to generate the mapping for.
267
+ qiskit_backend: Qiskit backend object to be used for qubit name generation.
268
+
269
+ Returns:
270
+ A dictionary mapping Qiskit qubit indices to QIR qubit pointers.
271
+
272
+ """
273
+ # For simplicity, reverse the mapping
274
+ layout_reverse_mapping = {bit: idx for idx, bit in qiskit_circuit.layout.final_layout.get_physical_bits().items()}
275
+ qiskit_qir_mapping: dict[int, int] = {}
276
+
277
+ # Replicate qiskit-qir logic for defining qubit pointer indices
278
+ for register in qiskit_circuit.qregs:
279
+ qiskit_qir_mapping.update(
280
+ {layout_reverse_mapping[bit]: n + len(qiskit_qir_mapping) for n, bit in enumerate(register)}
281
+ )
282
+
283
+ # In the generated QIR qubit pointers will use qiskit-qir qubit labels,
284
+ # but we already know how to map them to IQM physical qubits, through qiskit logical qubit indices.
285
+ return {
286
+ str(qiskit_qir_mapping[i]): str(qiskit_backend.index_to_qubit_name(i)) for i in range(qiskit_circuit.num_qubits)
287
+ }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: iqm-pulla
3
- Version: 9.0.0
3
+ Version: 9.1.0
4
4
  Summary: Client library for pulse-level access to an IQM quantum computer
5
5
  Author-email: IQM Finland Oy <developers@meetiqm.com>
6
6
  License: Apache License
@@ -18,11 +18,11 @@ iqm/pulla/quantum_architecture.py,sha256=mJH9e9fdkblg6LrgN7qd-Ui3Igawf-hGd2Z7Zcl
18
18
  iqm/pulla/utils.py,sha256=TTAOFhNW59VFAjnu6ZicmHXvp-GI_f66oh6IC1zFQKE,24732
19
19
  iqm/pulla/utils_cirq.py,sha256=8SBy6w7cr4AmnCgKwh7dBWwBGfGKxnoEMv9-1yfKs0A,777
20
20
  iqm/pulla/utils_dd.py,sha256=SxYAuRBgvYELKjeXpFbP4mM0xCCivDk7WUHw7oEXfMo,1695
21
- iqm/pulla/utils_qir.py,sha256=VjhUFYm71LAdcx8OUgSaKwMg_zaFQfSEIuKDP0L_8fw,10123
21
+ iqm/pulla/utils_qir.py,sha256=c4LiKdUnHZSQsI4fzc2wp59-qIH1s2sTyfBEf0MTxkk,11495
22
22
  iqm/pulla/utils_qiskit.py,sha256=SyL9zz9xZ3mEi8t5uJVLxe3ipgNf4REZURMJQRr2E-E,10108
23
- iqm_pulla-9.0.0.dist-info/AUTHORS.rst,sha256=iCStz7WP5Jk7uMnn9jRA4ybS14X4yeUW2SsWE-OTaRk,328
24
- iqm_pulla-9.0.0.dist-info/LICENSE.txt,sha256=cCj_biRA4Q8A77vxR8AuvAf-DZ5G79yxR_3lYY6TrmA,11333
25
- iqm_pulla-9.0.0.dist-info/METADATA,sha256=wsZmPqqyjRETlQueBlE2PwvYWFORj1q65YEgjpGk77c,17695
26
- iqm_pulla-9.0.0.dist-info/WHEEL,sha256=y4mX-SOX4fYIkonsAGA5N0Oy-8_gI4FXw5HNI1xqvWg,91
27
- iqm_pulla-9.0.0.dist-info/top_level.txt,sha256=NB4XRfyDS6_wG9gMsyX-9LTU7kWnTQxNvkbzIxGv3-c,4
28
- iqm_pulla-9.0.0.dist-info/RECORD,,
23
+ iqm_pulla-9.1.0.dist-info/AUTHORS.rst,sha256=iCStz7WP5Jk7uMnn9jRA4ybS14X4yeUW2SsWE-OTaRk,328
24
+ iqm_pulla-9.1.0.dist-info/LICENSE.txt,sha256=cCj_biRA4Q8A77vxR8AuvAf-DZ5G79yxR_3lYY6TrmA,11333
25
+ iqm_pulla-9.1.0.dist-info/METADATA,sha256=9sARQGBwq1vzFWWvzDTHgOFN7ek76ZXgF95q1K_FP2M,17695
26
+ iqm_pulla-9.1.0.dist-info/WHEEL,sha256=y4mX-SOX4fYIkonsAGA5N0Oy-8_gI4FXw5HNI1xqvWg,91
27
+ iqm_pulla-9.1.0.dist-info/top_level.txt,sha256=NB4XRfyDS6_wG9gMsyX-9LTU7kWnTQxNvkbzIxGv3-c,4
28
+ iqm_pulla-9.1.0.dist-info/RECORD,,