4
4
5
5
import numpy as np
6
6
import pytest
7
- from qiskit import QuantumCircuit
7
+ from braket .circuits import Circuit as BraketCircuit
8
+ from qiskit import QuantumCircuit as QiskitCircuit
8
9
from typeguard import TypeCheckError
9
10
10
11
from mpqp import Barrier , Instruction , Language , QCircuit
11
12
from mpqp .gates import CNOT , CZ , SWAP , Gate , H , Rx , Ry , Rz , S , T , X , Y , Z
12
13
from mpqp .measures import BasisMeasure , ExpectationMeasure , Observable
14
+ from mpqp .noise .noise_model import Depolarizing
15
+ from mpqp .tools .errors import UnsupportedBraketFeaturesWarning
13
16
from mpqp .tools .generics import OneOrMany , one_lined_repr
14
17
15
18
@@ -206,7 +209,7 @@ def test_without_measurements(circuit: QCircuit, printed_result_filename: str):
206
209
(
207
210
QCircuit ([X (0 ), CNOT (0 , 1 )]),
208
211
(),
209
- QuantumCircuit ,
212
+ QiskitCircuit ,
210
213
(
211
214
"[CircuitInstruction(operation=Instruction(name='x', num_qubits=1,"
212
215
" num_clbits=0, params=[]), qubits=(Qubit(QuantumRegister(2, 'q'), 0),),"
@@ -215,14 +218,84 @@ def test_without_measurements(circuit: QCircuit, printed_result_filename: str):
215
218
" 'q'), 0), Qubit(QuantumRegister(2, 'q'), 1)), clbits=())]"
216
219
),
217
220
),
221
+ (
222
+ QCircuit ([X (0 ), CNOT (0 , 1 )]),
223
+ (Language .QISKIT ,),
224
+ QiskitCircuit ,
225
+ (
226
+ "[CircuitInstruction(operation=Instruction(name='x', num_qubits=1,"
227
+ " num_clbits=0, params=[]), qubits=(Qubit(QuantumRegister(2, 'q'), 0),),"
228
+ " clbits=()), CircuitInstruction(operation=Instruction(name='cx',"
229
+ " num_qubits=2, num_clbits=0, params=[]), qubits=(Qubit(QuantumRegister(2,"
230
+ " 'q'), 0), Qubit(QuantumRegister(2, 'q'), 1)), clbits=())]"
231
+ ),
232
+ ),
233
+ (
234
+ QCircuit ([CNOT (0 , 1 ), Depolarizing (0.5 )]),
235
+ (Language .BRAKET ,),
236
+ BraketCircuit ,
237
+ (
238
+ """\
239
+ T : │ 0 │
240
+ ┌───────────┐
241
+ q0 : ───●───┤ DEPO(0.5) ├─
242
+ │ └───────────┘
243
+ ┌─┴─┐ ┌───────────┐
244
+ q1 : ─┤ X ├─┤ DEPO(0.5) ├─
245
+ └───┘ └───────────┘
246
+ T : │ 0 │"""
247
+ ),
248
+ ),
249
+ (
250
+ QCircuit ([CNOT (0 , 1 ), Depolarizing (0.5 , dimension = 2 )]),
251
+ (Language .BRAKET ,),
252
+ BraketCircuit ,
253
+ (
254
+ """\
255
+ T : │ 0 │
256
+ ┌───────────┐
257
+ q0 : ───●───┤ DEPO(0.5) ├─
258
+ │ └─────┬─────┘
259
+ ┌─┴─┐ ┌─────┴─────┐
260
+ q1 : ─┤ X ├─┤ DEPO(0.5) ├─
261
+ └───┘ └───────────┘
262
+ T : │ 0 │"""
263
+ ),
264
+ ),
265
+ (
266
+ QCircuit ([CNOT (0 , 1 ), Depolarizing (0.5 , dimension = 2 , gates = [CNOT ])]),
267
+ (Language .BRAKET ,),
268
+ BraketCircuit ,
269
+ (
270
+ """\
271
+ T : │ 0 │
272
+ ┌───────────┐
273
+ q0 : ───●───┤ DEPO(0.5) ├─
274
+ │ └─────┬─────┘
275
+ ┌─┴─┐ ┌─────┴─────┐
276
+ q1 : ─┤ X ├─┤ DEPO(0.5) ├─
277
+ └───┘ └───────────┘
278
+ T : │ 0 │"""
279
+ ),
280
+ ),
218
281
],
219
282
)
220
283
def test_to_other_language (
221
284
circuit : QCircuit , args : tuple [Language ], result_type : type , result_repr : str
222
285
):
223
- qiskit_circuit = circuit .to_other_language (* args )
224
- assert type (qiskit_circuit ) == QuantumCircuit
225
- assert repr (qiskit_circuit .data ) == result_repr
286
+ language = Language .QISKIT if len (args ) == 0 else args [0 ]
287
+ # TODO: test other languages
288
+ if language == Language .BRAKET :
289
+ with pytest .warns (UnsupportedBraketFeaturesWarning ) as record :
290
+ converted_circuit = circuit .to_other_language (* args )
291
+ assert len (record ) == 1
292
+ else :
293
+ converted_circuit = circuit .to_other_language (* args )
294
+ assert type (converted_circuit ) == result_type
295
+ if isinstance (converted_circuit , QiskitCircuit ):
296
+ assert repr (converted_circuit .data ) == result_repr
297
+ if isinstance (converted_circuit , BraketCircuit ):
298
+ assert str (converted_circuit ) == result_repr
226
299
227
300
228
301
@pytest .mark .parametrize (
0 commit comments