Skip to content

Commit

Permalink
Correct integer widths in Rust/Python hand-off
Browse files Browse the repository at this point in the history
Various locations in the Rust API take a `usize` as input.  For the most
part, Python integers will successfully be passed in at the correct size
if they fit.  Numpy `np.uint64` types, however, will fail conversion if
running on a 32-bit machine.  This is particularly relevant when the
values are being passed as an array.
  • Loading branch information
jakelishman committed Mar 31, 2022
1 parent afb9c9e commit 7404e66
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions qiskit/transpiler/passes/routing/stochastic_swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ def _layer_permutation(self, layer_partition, layout, qubit_subset, coupling, tr
cdist2 = coupling._dist_matrix**2
int_qubit_subset = np.fromiter(
(self._qubit_indices[bit] for bit in qubit_subset),
dtype=np.uint64,
dtype=np.uintp,
count=len(qubit_subset),
)

int_gates = np.fromiter(
(self._qubit_indices[bit] for gate in gates for bit in gate),
dtype=np.uint64,
dtype=np.uintp,
count=2 * len(gates),
)

Expand All @@ -184,7 +184,7 @@ def _layer_permutation(self, layer_partition, layout, qubit_subset, coupling, tr
trial_circuit = DAGCircuit() # SWAP circuit for slice of swaps in this trial
trial_circuit.add_qubits(layout.get_virtual_bits())

edges = np.asarray(coupling.get_edges(), dtype=np.uint64).ravel()
edges = np.asarray(coupling.get_edges(), dtype=np.uintp).ravel()
cdist = coupling._dist_matrix
best_edges, best_layout, best_depth = stochastic_swap_rs.swap_trials(
trials,
Expand Down

0 comments on commit 7404e66

Please sign in to comment.