projekter / yquant

Typesetting quantum circuits in a human-readable language
LaTeX Project Public License v1.3c
56 stars 5 forks source link

Circuit equations #11

Closed projekter closed 3 years ago

projekter commented 3 years ago

Circuit equations are probably encountered quite often, but in order to implement them in yquant, I'm not quite satisfied with the current solutions. I want to implement at least some kind of built-in support for them.

Required features:

Desired features:

Thoughts:

First idea:

\begin{yquantgroup}% replaces yquant, optional options go to the yquant environment.
                   % as with \yquantimport: can be inside a tikzpicture (then no page
                   % breaking, but easy to pass options to the picture) or outside
                   % (which allows for page breaking, but options must be passed
                   % manually).
                   % yquantgroup* is available, but all _outer_ registers must be
                   % declared explicitly, only inner ones can be declared on-the-fly.
   \registers{
      % put arbitrary shared register declarations in here
      qubit {$\ket0$} a[4];
      qubit {$\ket1$} b;
   }
   \circuit[frameless]{% basically inserts a subcircuit, optional arguments are passed as
                       % subcircuit arguments
      import -; % use the import command to make the outer registers known in the
                % inner circuit. All registers that were not imported manually will be
                % imported automatically as soon as the first non-declaration gate occurs
                % (not necessarily the first gate that uses this register, but any).
                % Manual importing allows to intersperse the registers with internal
                % wires.
      % now just some arbitrary gate commands, as usual
      h -;
      cnot b | a[3];
      cnot b | a[0];
      h -;
   }
   \equals*[$=$] % emit the equality sign.
                 % star = put a horizontal alignment mark at this position
                 % optional parameter: customize the text
   \circuit{
      % next circuit which goes to the right
   }
   \\ % line break = new line in the circuit - end and restart the yquant environment
   \shiftright[1] % the current yquant environment will be shifted to the right either
                  % - by the amount specified in the argument if it is a dimension
                  % - to the position of the xth horizontal alignment mark defined
                  %   before, where x is the optional argument (one based, default 1)
                  % - or not shifted, if the argument is zero
                  % \shiftright can only directly follow a break
                  % \shiftright* additionally puts an alignment at this position
                  % If [aligned] is passed to the yquantgroup, \shiftright is implied
                  % after each line break, unless it is manually specified with a
                  % different argument.
   \equals[$=$] % without the star, the alignment marks of the previous line are copied
                % with the star, the alignment marks are cleared, then overwritten
   \circuit{
      % again a circuit
   }
   \pagebreak % or \newpage or \clearpage or \cleardoublepage: those commands must be
              % inserted manually, then end the yquant and tikzpicture environment and
              % restart them. Only works if yquantgroup is not within a tikzpicture.
              % If commands should be repeated at the beginning of every tikzpicture,
              % they should be specified as the [preamble={}] option to yquantgroup
   % ...
\end{yquantgroup}

Thoughts on this/suggestions? @engeljh or others that frequently use circuit equations?

engeljh commented 3 years ago

Benjamin,

This all seems reasonable. My only advice would be to make it as simple as reasonably possible to use. So, for example, I would make "frameless" the default for these circuits; I have never seen an example of a circuit equation with frames around the individual circuits. And I would probably not worry about page breaks until implementing the more useful stuff; if an equation is displayed with a page break it will often be harder to understand. And I would not require the user to refer to subcircuits when accessing nodes, if that is possible (which I guess means making the names visible without a prefix).

Best, Jon Engel


From: Benjamin Desef @.> Sent: Sunday, July 4, 2021 2:01 PM To: projekter/yquant @.> Cc: Engel, Jonathan @.>; Mention @.> Subject: [projekter/yquant] Circuit equations (#11)

Circuit equations are probably encountered quite often, but in order to implement them in yquant, I'm not quite satisfied with the current solutions. I want to implement at least some kind of built-in support for them.

Required features:

Desired features:

Thoughts:

First idea:

\begin{yquantgroup}% replaces yquant, optional options go to the yquant environment. % as with \yquantimport: can be inside a tikzpicture (then no page % breaking, but easy to pass options to the picture) or outside % (which allows for page breaking, but options must be passed % manually). % yquantgroup is available, but all outer registers must be % declared explicitly, only inner ones can be declared on-the-fly. \registers{ % put arbitrary shared register declarations in here qubit {$\ket0$} a[4]; qubit {$\ket1$} b; } \circuit[frameless]{% basically inserts a subcircuit, optional arguments are passed as % subcircuit arguments import -; % use the import command to make the outer registers known in the % inner circuit. All registers that were not imported manually will be % imported automatically as soon as the first non-declaration gate occurs % (not necessarily the first gate that uses this register, but any). % Manual importing allows to intersperse the registers with internal % wires. % now just some arbitrary gate commands, as usual h -; cnot b | a[3]; cnot b | a[0]; h -; } \equals[$=$] % emit the equality sign. % star = put a horizontal alignment mark at this position % optional parameter: customize the text \circuit{ % next circuit which goes to the right } \ % line break = new line in the circuit - end and restart the yquant environment \shiftright[1] % the current yquant environment will be shifted to the right either % - by the amount specified in the argument if it is a dimension % - to the position of the xth horizontal alignment mark defined % before, where x is the optional argument (one based, default 1) % - or not shifted, if the argument is zero % \shiftright can only directly follow a break % \shiftright* additionally puts an alignment at this position % If [aligned] is passed to the yquantgroup, \shiftright is implied % after each line break, unless it is manually specified with a % different argument. \equals[$=$] % without the star, the alignment marks of the previous line are copied % with the star, the alignment marks are cleared, then overwritten \circuit{ % again a circuit } \pagebreak % or \newpage or \clearpage or \cleardoublepage: those commands must be % inserted manually, then end the yquant and tikzpicture environment and % restart them. Only works if yquantgroup is not within a tikzpicture. % If commands should be repeated at the beginning of every tikzpicture, % they should be specified as the [preamble={}] option to yquantgroup % ... \end{yquantgroup}

Thoughts on this/suggestions? @engeljhhttps://github.com/engeljh or others that frequently use circuit equations?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/projekter/yquant/issues/11, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AL3DBEZ6RSUGXPP7OWDSQ3TTWCOWFANCNFSM47ZM2NQQ.

projekter commented 3 years ago

Noted, frameless by default makes sense. I will probably introduce some style that is applied for subcircuits generated via \circuit, which is by default frameless but allows to switch this globally. I also agree that the page breaking stuff is not a priority in implementation, but I want to at least have a concept that would allow to have some of these capabilities without requiring the user to again type more than necessary. And actually, if it is done like this, the implementation of this part should be pretty straightforward. I'll leave this open for comments until next weekend and will then start with the implementation.