@@ -317,6 +317,7 @@ def unitary_kraus2(
317
317
* index : int ,
318
318
prob : Optional [Sequence [float ]] = None ,
319
319
status : Optional [float ] = None ,
320
+ name : Optional [str ] = None ,
320
321
) -> Tensor :
321
322
# general impl from Monte Carlo trajectory depolarizing above
322
323
# still jittable
@@ -326,7 +327,12 @@ def index2gate2(r: Tensor, kraus: Sequence[Tensor]) -> Tensor:
326
327
return backend .switch (r , [lambda _ = k : _ for k in kraus ])
327
328
328
329
return self ._unitary_kraus_template (
329
- kraus , * index , prob = prob , status = status , get_gate_from_index = index2gate2
330
+ kraus ,
331
+ * index ,
332
+ prob = prob ,
333
+ status = status ,
334
+ get_gate_from_index = index2gate2 ,
335
+ name = name ,
330
336
)
331
337
332
338
def unitary_kraus (
@@ -335,6 +341,7 @@ def unitary_kraus(
335
341
* index : int ,
336
342
prob : Optional [Sequence [float ]] = None ,
337
343
status : Optional [float ] = None ,
344
+ name : Optional [str ] = None ,
338
345
) -> Tensor :
339
346
"""
340
347
Apply unitary gates in ``kraus`` randomly based on corresponding ``prob``.
@@ -360,7 +367,12 @@ def index2gate(r: Tensor, kraus: Sequence[Tensor]) -> Tensor:
360
367
return reduce (add , [r [i ] * kraus [i ] for i in range (l )])
361
368
362
369
return self ._unitary_kraus_template (
363
- kraus , * index , prob = prob , status = status , get_gate_from_index = index2gate
370
+ kraus ,
371
+ * index ,
372
+ prob = prob ,
373
+ status = status ,
374
+ get_gate_from_index = index2gate ,
375
+ name = name ,
364
376
)
365
377
366
378
def _unitary_kraus_template (
@@ -372,6 +384,7 @@ def _unitary_kraus_template(
372
384
get_gate_from_index : Optional [
373
385
Callable [[Tensor , Sequence [Tensor ]], Tensor ]
374
386
] = None ,
387
+ name : Optional [str ] = None ,
375
388
) -> Tensor : # DRY
376
389
sites = len (index )
377
390
kraus = [k .tensor if isinstance (k , tn .Node ) else k for k in kraus ]
@@ -406,7 +419,7 @@ def step_function(x: Tensor) -> Tensor:
406
419
raise ValueError ("no `get_gate_from_index` implementation is provided" )
407
420
g = get_gate_from_index (r , kraus )
408
421
g = backend .reshape (g , [2 for _ in range (sites * 2 )])
409
- self .any (* index , unitary = g ) # type: ignore
422
+ self .any (* index , unitary = g , name = name ) # type: ignore
410
423
return r
411
424
412
425
def _general_kraus_tf (
@@ -482,6 +495,7 @@ def _general_kraus_2(
482
495
kraus : Sequence [Gate ],
483
496
* index : int ,
484
497
status : Optional [float ] = None ,
498
+ name : Optional [str ] = None ,
485
499
) -> Tensor :
486
500
# the graph building time is frustratingly slow, several minutes
487
501
# though running time is in terms of ms
@@ -528,13 +542,16 @@ def calculate_kraus_p(i: int) -> Tensor:
528
542
for w , k in zip (prob , kraus_tensor )
529
543
]
530
544
531
- return self .unitary_kraus2 (new_kraus , * index , prob = prob , status = status )
545
+ return self .unitary_kraus2 (
546
+ new_kraus , * index , prob = prob , status = status , name = name
547
+ )
532
548
533
549
def general_kraus (
534
550
self ,
535
551
kraus : Sequence [Gate ],
536
552
* index : int ,
537
553
status : Optional [float ] = None ,
554
+ name : Optional [str ] = None ,
538
555
) -> Tensor :
539
556
"""
540
557
Monte Carlo trajectory simulation of general Kraus channel whose Kraus operators cannot be
@@ -553,7 +570,7 @@ def general_kraus(
553
570
when the random number will be generated automatically
554
571
:type status: Optional[float], optional
555
572
"""
556
- return self ._general_kraus_2 (kraus , * index , status = status )
573
+ return self ._general_kraus_2 (kraus , * index , status = status , name = name )
557
574
558
575
apply_general_kraus = general_kraus
559
576
0 commit comments