Skip to content

Commit

Permalink
Merge branch 'develop' into 'main'
Browse files Browse the repository at this point in the history
Rivet v1.0.12

See merge request haiqu-ai/qml-transpiler!40
  • Loading branch information
ogorodnikov committed Oct 2, 2024
2 parents 9598b6b + 6b2b23c commit 45a89c4
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 40 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
readme = "README.md"
authors = [{ name = "Haiqu Inc.", email = "info@haiqu.ai" }]
license = { file = "LICENSE" }
version = "1.0.11"
version = "1.0.12"
requires-python = ">= 3.10"
dependencies = [
"qiskit <= 1.0.2",
Expand Down
2 changes: 1 addition & 1 deletion rivet_transpiler/topological_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def transpile_and_compress(circuit, backend, **key_arguments):

# Coupling List Check

if coupling_list is None:
if not coupling_list:

warnings.warn("Provided Backend has no topology - no compression performed")

Expand Down
67 changes: 39 additions & 28 deletions rivet_transpiler/transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,32 +104,38 @@ def transpile_chain(circuits, backend=None, **key_arguments):
QuantumCircuit: The transpiled chain circuit.
"""

full_map = None
chain_circuit = None
# Transpile

# Chain
transpiled_circuits = []

for circuit in circuits:

if full_map is not None:
transpiled_circuit = transpile(circuit, backend, **key_arguments)

initial_layout = full_map[:circuit.num_qubits]
full_map = get_full_map(transpiled_circuit)

key_arguments['initial_layout'] = initial_layout
initial_layout = full_map[:circuit.num_qubits]

transpiled_circuit = transpile(circuit, backend, **key_arguments)
key_arguments['initial_layout'] = initial_layout

if chain_circuit is None:
chain_circuit = transpiled_circuit
transpiled_circuits.append(transpiled_circuit)

else:
chain_circuit.compose(transpiled_circuit, inplace=True)
# Resulting Circuit

full_map = get_full_map(transpiled_circuit)
resulting_qubits_count = max(transpiled_circuit.num_qubits
for transpiled_circuit in transpiled_circuits)

chain_circuit._layout = transpiled_circuit.layout
resulting_circuit = qiskit.QuantumCircuit(resulting_qubits_count)

return chain_circuit
# Compose

for transpiled_circuit in transpiled_circuits:

resulting_circuit.compose(transpiled_circuit, inplace=True)

resulting_circuit._layout = transpiled_circuit.layout

return resulting_circuit


def transpile_right(central_circuit, right_circuit,
Expand Down Expand Up @@ -159,7 +165,15 @@ def transpile_right(central_circuit, right_circuit,
backend,
**key_arguments)

resulting_circuit = central_circuit.compose(transpiled_right_circuit)
# Resulting Circuit

resulting_qubits_count = max(central_circuit.num_qubits,
transpiled_right_circuit.num_qubits)

resulting_circuit = qiskit.QuantumCircuit(resulting_qubits_count)

resulting_circuit.compose(central_circuit, inplace=True)
resulting_circuit.compose(transpiled_right_circuit, inplace=True)

# No Layout

Expand Down Expand Up @@ -187,9 +201,6 @@ def transpile_right(central_circuit, right_circuit,

if transpiled_right_circuit.layout.final_layout is None:

resulting_qubits_count = max(central_circuit.num_qubits,
transpiled_right_circuit.num_qubits)

right_routing = list(range(resulting_qubits_count))

else:
Expand Down Expand Up @@ -261,8 +272,15 @@ def transpile_left(central_circuit, left_circuit,

transpiled_left_circuit._layout = transpiled_inverted_left_circuit.layout

resulting_circuit = central_circuit.compose(transpiled_left_circuit,
front=True)
# Resulting Circuit

resulting_qubits_count = max(central_circuit.num_qubits,
transpiled_left_circuit.num_qubits)

resulting_circuit = qiskit.QuantumCircuit(resulting_qubits_count)

resulting_circuit.compose(central_circuit, inplace=True, front=True)
resulting_circuit.compose(transpiled_left_circuit, inplace=True, front=True)

# No Layout

Expand All @@ -285,7 +303,7 @@ def transpile_left(central_circuit, left_circuit,
if (central_circuit.layout is None or
central_circuit.layout.final_layout is None):

central_routing = list(range(central_circuit.num_qubits))
central_routing = list(range(resulting_qubits_count))

else:
central_routing = [central_circuit.layout.final_layout[qubit]
Expand Down Expand Up @@ -321,13 +339,6 @@ def transpile_left(central_circuit, left_circuit,

resulting_circuit._layout = transpile_layout

# Printouts

# print("left_routing:", left_routing)
# print("central_routing:", central_routing)
# print("final_routing:", final_routing)
# print("final_layout:", final_layout)

return resulting_circuit


Expand Down
6 changes: 4 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from qiskit_aer import AerSimulator

from qiskit_ibm_runtime.fake_provider import fake_backend

from qiskit_ibm_runtime.fake_provider import FakeLimaV2
from qiskit_ibm_runtime.fake_provider import FakeMontrealV2

from rivet_transpiler import get_litmus_circuit
Expand All @@ -14,8 +16,8 @@

BACKENDS = [
None,
# AerSimulator,
# FakeLimaV2,
AerSimulator,
FakeLimaV2,
FakeMontrealV2
]

Expand Down
16 changes: 9 additions & 7 deletions tests/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,19 @@ def build_blocks_circuit(circuit_parts, backend, *arguments, **key_arguments):

key_arguments['initial_layout'] = initial_layout

# Compose
# Blocks Circuit

blocks_circuit = None
resulting_qubits_count = max(transpiled_circuit_part.num_qubits
for transpiled_circuit_part
in transpiled_circuit_parts)

for transpiled_circuit_part in transpiled_circuit_parts:
blocks_circuit = qiskit.QuantumCircuit(resulting_qubits_count)

# Compose

if blocks_circuit is None:
blocks_circuit = transpiled_circuit_part
for transpiled_circuit_part in transpiled_circuit_parts:

else:
blocks_circuit.compose(transpiled_circuit_part, inplace=True)
blocks_circuit.compose(transpiled_circuit_part, inplace=True)

return blocks_circuit

Expand Down
1 change: 1 addition & 0 deletions tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# 'tests/test_functions.py',
# 'tests/test_stacks.py',
# 'tests/test_metrics.py',
# 'tests/test_integration.py',
])

cov.stop()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_transpile_and_return_options(litmus_circuit, backend):

def test_transpile_chain(litmus_circuit, backend):

CHAIN = [litmus_circuit] * 2
CHAIN = [litmus_circuit] * 3

transpiled_chain_circuit = transpile_chain(
circuits=CHAIN,
Expand Down

0 comments on commit 45a89c4

Please sign in to comment.