1
1
from __future__ import annotations
2
2
3
- from typing import Iterable , Optional , Sequence , Type , Union
4
3
from copy import deepcopy
5
4
from numbers import Complex
5
+ from typing import Iterable , Optional , Sequence , Type , Union
6
6
7
7
import numpy as np
8
8
import numpy .typing as npt
9
+ from braket .circuits import Circuit as braket_Circuit
9
10
from matplotlib .figure import Figure
10
- from qiskit .circuit import QuantumCircuit , Operation
11
- from qiskit .circuit .quantumcircuit import CircuitInstruction
12
-
13
11
from qat .core .wrappers .circuit import Circuit as myQLM_Circuit
14
- from braket .circuits import Circuit as braket_Circuit
12
+ from qiskit .circuit import Operation , QuantumCircuit
13
+ from qiskit .circuit .quantumcircuit import CircuitInstruction
15
14
from qiskit .quantum_info import Operator
16
15
from sympy import Basic , Expr
17
- from typeguard import typechecked , TypeCheckError
16
+ from typeguard import TypeCheckError , typechecked
18
17
19
18
from mpqp .core .instruction import Instruction
20
19
from mpqp .core .instruction .barrier import Barrier
21
- from mpqp .core .instruction .gates import (
22
- ControlledGate ,
23
- Gate ,
24
- )
20
+ from mpqp .core .instruction .gates import ControlledGate , Gate , Id
25
21
from mpqp .core .instruction .gates .custom_gate import CustomGate
26
22
from mpqp .core .instruction .gates .gate_definition import UnitaryMatrix
27
23
from mpqp .core .instruction .gates .parametrized_gate import ParametrizedGate
28
- from mpqp .core .instruction .measurement import (
29
- ComputationalBasis ,
30
- BasisMeasure ,
31
- Measure ,
32
- )
24
+ from mpqp .core .instruction .measurement import BasisMeasure , ComputationalBasis , Measure
33
25
from mpqp .core .instruction .measurement .expectation_value import ExpectationMeasure
26
+ from mpqp .core .languages import Language
34
27
from mpqp .qasm import qasm2_to_myqlm_Circuit
35
28
from mpqp .qasm .open_qasm_2_and_3 import open_qasm_2_to_3
36
29
from mpqp .qasm .qasm_to_braket import qasm3_to_braket_Circuit
37
30
from mpqp .tools .errors import NumberQubitsError
38
- from mpqp .core .languages import Language
39
31
from mpqp .tools .maths import matrix_eq
40
32
41
33
@@ -646,12 +638,19 @@ def to_other_language(
646
638
qiskit_inst = instruction .to_other_language (
647
639
Language .QISKIT , qiskit_parameters
648
640
)
649
- assert isinstance (qiskit_inst , CircuitInstruction ) or isinstance (
650
- qiskit_inst , Operation ) or isinstance (qiskit_inst , Operator )
641
+ assert (
642
+ isinstance (qiskit_inst , CircuitInstruction )
643
+ or isinstance (qiskit_inst , Operation )
644
+ or isinstance (qiskit_inst , Operator )
645
+ )
651
646
cargs = []
652
647
653
648
if isinstance (instruction , CustomGate ):
654
- new_circ .unitary (instruction .to_other_language (), instruction .targets , instruction .label )
649
+ new_circ .unitary (
650
+ instruction .to_other_language (),
651
+ instruction .targets ,
652
+ instruction .label ,
653
+ )
655
654
# FIXME: minus sign appearing when it should not, seems there a phase added somewhere, check u gate
656
655
# in OpenQASM translation.
657
656
continue
@@ -662,7 +661,7 @@ def to_other_language(
662
661
elif isinstance (instruction , BasisMeasure ) and isinstance (
663
662
instruction .basis , ComputationalBasis
664
663
):
665
- #TODO muhammad/henri, for custom basis, check if something should be changed here, otherwise remove
664
+ # TODO muhammad/henri, for custom basis, check if something should be changed here, otherwise remove
666
665
# the condition to have only computational basis
667
666
assert instruction .c_targets is not None
668
667
qargs = [instruction .targets ]
@@ -685,9 +684,19 @@ def to_other_language(
685
684
return myqlm_circuit
686
685
687
686
elif language == Language .BRAKET :
688
- circuit_qasm3 = self .to_qasm3 ()
689
- brkt_circuit = qasm3_to_braket_Circuit (circuit_qasm3 )
690
- return brkt_circuit
687
+ circuit = deepcopy (self )
688
+ used_qubits = set ().union (
689
+ * (inst .connections () for inst in circuit .instructions )
690
+ )
691
+ circuit .add (
692
+ [
693
+ Id (qubit )
694
+ for qubit in range (circuit .nb_qubits )
695
+ if qubit not in used_qubits
696
+ ]
697
+ )
698
+
699
+ return qasm3_to_braket_Circuit (circuit .to_qasm3 ())
691
700
692
701
else :
693
702
raise NotImplementedError (f"Error: { language } is not supported" )
0 commit comments