Skip to content

Commit

Permalink
fix of dit compiler edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinMTO committed Sep 8, 2024
1 parent 28bff4d commit f62929d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/mqt/qudits/compiler/dit_compiler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import typing
from typing import Optional

from ..core.lanes import Lanes
from ..quantum_circuit.components.extensions.gate_types import GateTypes
Expand Down Expand Up @@ -47,9 +48,12 @@ def compile(self, backend: Backend, circuit: QuantumCircuit, passes_names: list[
elif "Multi" in str(compiler_pass):
passes_dict[GateTypes.MULTI] = decomposition
for gate in circuit.instructions:
decomposer = typing.cast(CompilerPass, passes_dict.get(gate.gate_type))
new_instructions = decomposer.transpile_gate(gate)
new_instr.extend(new_instructions)
decomposer = typing.cast(Optional[CompilerPass], passes_dict.get(gate.gate_type))
if decomposer is not None:
new_instructions = decomposer.transpile_gate(gate)
new_instr.extend(new_instructions)
else:
new_instr.append(gate)

circuit.set_instructions(new_instr)
circuit.set_mapping([graph.log_phy_map for graph in backend.energy_level_graphs])
Expand Down
30 changes: 30 additions & 0 deletions test/python/compiler/twodit/entangled_qr/test_entangled_qr.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,33 @@ def test_entangling_qr(self):
target /= target[0][0]
res = (abs(target - np.identity(15, dtype="complex")) < 10e-5).all()
assert res

@staticmethod
def test_entangling_qr_2():
# Create the original circuit
circuit = QuantumCircuit(2, [3, 3], 0)
circuit.x(0)
circuit.csum([0, 1])

# Simulate the original circuit
original_state = circuit.simulate()
print("Original circuit simulation result:")
print(original_state.round(3))

# Set up the provider and backend
provider = MQTQuditProvider()
backend_ion = provider.get_backend("faketraps2trits")

# Compile the circuit
qudit_compiler = QuditCompiler()
passes = ["LogEntQRCEXPass"]
new_circuit = qudit_compiler.compile(backend_ion, circuit, passes)

# Simulate the compiled circuit
compiled_state = new_circuit.simulate()
print("\nCompiled circuit simulation result:")
print(compiled_state.round(3))

# Compare the results
is_close = np.allclose(original_state, compiled_state)
print(f"\nAre the simulation results close? {is_close}")

0 comments on commit f62929d

Please sign in to comment.