7
$\begingroup$

I have the following code:

Animate[
   Graphics[{EdgeForm[{Thick,Black}],FaceForm[White],Rectangle[{0,0}],
     Circle[{a,0.5},0.1],
     Black,Text["|0>",{a,0.5}],Large,Text["X",{0.5,0.5}]}],{a,-2,-0.1,0.15}]

I am trying to create a program where the circle, labeled |0$\rangle$ goes to the box, labeled X (points if you can make the X a decent size), disappears as it goes through, and comes out labeled |1$\rangle$. The current animation has it going up right to the edge of the box, but I can't figure out how to make it disappear and switch labels as it goes through it. I'd like to end up exporting this (though I can put it into Table format myself) as an animated gif that I can put into a video.

Any help would be appreciated. Thanks!

$\endgroup$
  • 1
    $\begingroup$ Regarding ⟩: esc+>+esc $\endgroup$ – corey979 Oct 2 '16 at 21:21
  • $\begingroup$ @corey979, I see, thanks! That worked. $\endgroup$ – heather Oct 2 '16 at 21:22
12
$\begingroup$

Perhaps something like this?

Animate[
  Graphics[
    { FaceForm[White]
    , EdgeForm[{Thick, Black}]
    , {Gray, Line[{{-12, 0}, {12, 0}}]}
    , Disk[{t, 0}, 2]
    , Text[Style[If[t < 0, "|0〉", "|1〉"], 32], {t, 0}]
    , Rectangle[{-3, -3}, {3, 3}]
    , Text[Style["X", 64], {0, 0}]
    }
  , PlotRange -> {{-12, 12}, Automatic}
  ]
, {t, -10, 10}
]

animated qubit

The key to making the qubit disappear behind the gate is to ensure that the Rectangle is opaque and drawn after the Disk is drawn (i.e. the rectangle appears later in the list of Graphics directives than the disk). The label change is accomplished by the If expression which evaluates to |0〉 prior to time zero and |1〉 thereafter. Finally, the unsightly resizing of the graphic is prevented by explicitly specifying the left and right edges of the plot range.

$\endgroup$
  • 2
    $\begingroup$ I'll leave here another way to implement the transitioning qubit: Text[Style[StringForm["|`1`〉", Boole[t >= 0]], 32], {t, 0}]. $\endgroup$ – J. M. will be back soon Oct 3 '16 at 4:03
8
$\begingroup$

Going off WReach's clever transition, here are a couple of alternative transitions. These transitions all have a sort of "sharpness" parameter, so I've put them in a Manipulate and you can let the time play and adjust the parameter as you wish. Mix and match them as you please (and remember that the order in which the Graphics elements are drawn matters)!

Fade

Manipulate[
 Graphics[{
   Thick, Opacity[Abs[opacityfactor*t]], Circle[{t, 0}, 2],
   Text[Style[
     If[t < 0, "|0〉", "|1〉"], 
     32], {t, 0}],
   Opacity[1], EdgeForm[Thick], FaceForm[White], 
   Rectangle[{-3, -3}, {3, 3}], Text[Style["X", 64]]
   }, PlotRange -> {{-12, 12}, Automatic}]
 , {t, -10, 10}, {{opacityfactor, .1}, .05, .3}]

fade transition

Highlight

Manipulate[
 Graphics[{
   Thick, Circle[{t, 0}, 2], 
   Style[Circle[{t, 0}, Max[Abs[1.5*t], 2]], Red, Thick, 
    Opacity[If[Abs[t] < cutoff, 1, 0]]],
   Text[Style[
     If[t < 0, "|0〉", "|1〉"], 
     32], {t, 0}],
   Opacity[1], EdgeForm[Thick], FaceForm[White], 
   Rectangle[{-3, -3}, {3, 3}], Text[Style["X", 64]]
   }, PlotRange -> {{-12, 12}, {-5, 5}}]
 , {t, -10, 10}, {{cutoff, 4}, 1, 6}]

highlight transition

Exporting

And for your convenience, here are the exportable commands:

Fade

opacityfactor = .1;
fade = Table[
   Graphics[{
     Thick, Opacity[Abs[opacityfactor*t]], Circle[{t, 0}, 2],
     Text[
      Style[If[t < 0, "|0〉", 
        "|1〉"], 32], {t, 0}],
     Opacity[1], EdgeForm[Thick], FaceForm[White], 
     Rectangle[{-3, -3}, {3, 3}], Text[Style["X", 64]]
     }, PlotRange -> {{-12, 12}, Automatic}], {t, -10, 10, 0.4}];
Export["fade.gif", fade]

Highlight

cutoff = 4;
highlight = Table[
   Graphics[{
     Thick, Circle[{t, 0}, 2], 
     Style[Circle[{t, 0}, Max[Abs[1.5*t], 2]], Red, Thick, 
      Opacity[If[Abs[t] < cutoff, 1, 0]]],
     Text[
      Style[If[t < 0, "|0〉", 
        "|1〉"], 32], {t, 0}],
     Opacity[1], EdgeForm[Thick], FaceForm[White], 
     Rectangle[{-3, -3}, {3, 3}], Text[Style["X", 64]]
     }, PlotRange -> {{-12, 12}, {-5, 5}}], {t, -10, 10, 0.4}];
Export["highlight.gif", highlight]
$\endgroup$
  • $\begingroup$ Thanks so much - these will be cool to play around with. +1. =) $\endgroup$ – heather Oct 3 '16 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.