Skip to content

Commit c24aea1

Browse files
committed
fixed dimension bug when first channel of composition is Unitary. added feature that detects if all channels in composition are Unitary.
1 parent 21591f3 commit c24aea1

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

src/QuantumChannel.m

+30-13
Original file line numberDiff line numberDiff line change
@@ -909,19 +909,36 @@
909909

910910
QuantumChannel/:Dot[chans__QuantumChannel]:=
911911
If[CheckDotDims[chans],
912-
With[{
913-
rep=ChannelRep@First@{chans},
914-
basis=Basis@First@{chans},
915-
inDim=InputDim@Last@{chans},
916-
outDim=OutputDim@First@{chans}},
917-
rep[QuantumChannel[
918-
Apply[Dot,First[Super[#,Basis->"Col"]]&/@{chans}],
919-
{ChannelRep->Super,
920-
InputDim->inDim,
921-
OutputDim->outDim,
922-
Basis->"Col"}]
923-
,Basis->basis]],
924-
Message[QuantumChannel::dot]
912+
If[Not@AllQ[ChannelRep[#]===Unitary&,{chans}],
913+
With[{
914+
(*Pick the first non-unitary channel as the rep*)
915+
rep=First@Select[ChannelRep/@{chans},#=!=Unitary&,1],
916+
basis=Basis@First@{chans},
917+
inDim=InputDim@Last@{chans},
918+
outDim=OutputDim@First@{chans}
919+
},
920+
rep[QuantumChannel[
921+
Apply[Dot,First[Super[#,Basis->"Col"]]&/@{chans}],
922+
{ChannelRep->Super,
923+
InputDim->inDim,
924+
OutputDim->outDim,
925+
Basis->"Col"}]
926+
,Basis->basis]],
927+
(*We add a special case where all of the channels are Unitary*)
928+
With[{
929+
basis=Basis@First@{chans},
930+
inDim=InputDim@Last@{chans},
931+
outDim=OutputDim@First@{chans}
932+
},
933+
Unitary[QuantumChannel[
934+
Apply[Dot,First[Unitary[#,Basis->"Col"]]&/@{chans}],
935+
{ChannelRep->Unitary,
936+
InputDim->inDim,
937+
OutputDim->outDim,
938+
Basis->"Col"}]
939+
,Basis->basis]]
940+
],
941+
Message[QuantumChannel::dot]
925942
]
926943

927944

0 commit comments

Comments
 (0)