Skip to content

Commit

Permalink
switch input order for map_wires (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
albi3ro authored Apr 17, 2021
1 parent a500dbf commit aad1863
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pennylane_qiskit/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ def _check_circuit_and_bind_parameters(
return quantum_circuit.bind_parameters(params)


def map_wires(wires: list, qc_wires: list) -> dict:
def map_wires(qc_wires: list, wires: list) -> dict:
"""Utility function mapping the wires specified in a quantum circuit with the wires
specified by the user for the template.
Args:
wires (list): wires specified for the template
qc_wires (list): wires from the converted quantum circuit
wires (list): wires specified for the template
Returns:
dict[int, int]: map from quantum circuit wires to the user defined wires
Expand Down Expand Up @@ -173,7 +173,7 @@ def _function(params: dict = None, wires: list = None):
# Wires from a qiskit circuit have unique IDs, so their hashes are unique too
qc_wires = [hash(q) for q in qc.qubits]

wire_map = map_wires(wires, qc_wires)
wire_map = map_wires(qc_wires, wires)

# Processing the dictionary of parameters passed
for op in qc.data:
Expand Down
8 changes: 4 additions & 4 deletions tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ def test_map_wires(self, recorder):
qc = QuantumCircuit(1)
qc_wires = [hash(q) for q in qc.qubits]

assert map_wires(qc_wires, wires) == {0: hash(qc.qubits[0])}
assert map_wires(wires, qc_wires) == {0: hash(qc.qubits[0])}

def test_map_wires_instantiate_quantum_circuit_with_registers(self, recorder):
"""Tests the map_wires function for wires of a quantum circuit instantiated
Expand All @@ -718,7 +718,7 @@ def test_map_wires_instantiate_quantum_circuit_with_registers(self, recorder):
qc = QuantumCircuit(qr1, qr2, qr3)
qc_wires = [hash(q) for q in qc.qubits]

mapped_wires = map_wires(qc_wires, wires)
mapped_wires = map_wires(wires, qc_wires)

assert len(mapped_wires) == len(wires)
assert list(mapped_wires.keys()) == wires
Expand All @@ -732,7 +732,7 @@ def test_map_wires_provided_non_standard_order(self, recorder):
qc = QuantumCircuit(3)
qc_wires = [hash(q) for q in qc.qubits]

mapped_wires = map_wires(qc_wires, wires)
mapped_wires = map_wires(wires, qc_wires)

for q in qc.qubits:
assert hash(q) in mapped_wires.values()
Expand All @@ -756,7 +756,7 @@ def test_map_wires_exception_mismatch_in_number_of_wires(self, recorder):
match="The specified number of wires - {} - does not match "
"the number of wires the loaded quantum circuit acts on.".format(len(wires)),
):
map_wires(wires, qc_wires)
map_wires(qc_wires, wires)


class TestConverterWarnings:
Expand Down

0 comments on commit aad1863

Please sign in to comment.