Implements transformation-based synthesis in Q# #41
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an amazing contribution, thank you so much! I've left a few comments that would be great to address before merging in, but we really appreciate everything you've done with the PR so far.
|
||
// Some helper functions | ||
|
||
// # Summary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you be willing to change these to documentation comments (that is, change //
→ ///
), and to expand on the contents a bit? The ///
comments on Zip
might make a good format to follow. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, I will add extensive documentation to all helper functions. Is this also required for the private functions that are used in the implementation of TBS
. I'll also add a more comprehensive documentation to PermutationOracle
.
// # Summary | ||
// Constructs a MCMTMask type as a singleton array if targets is not 0, | ||
// otherwise returns an empty array | ||
function MakeGateMask(controls: Int, targets: Int) : MCMTMask[] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name Make
could be seen to imply a side effect, would you be willing to rename it to GateMask
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will rename it to GateMask
.
let (perm, gates) = state; | ||
let y = perm[x]; | ||
let masks = GateMasksForAssignment(x, y); | ||
let new_perm = Fold(UpdatePermutation, perm, masks); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a beautiful line of code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
|
||
// # Summary | ||
// Synthesize Toffoli network from a permutation using functional synthesis | ||
operation PermutationOracle(perm : Int[], qubits : Qubit[], synth : ((Int[], Qubit[]) -> MCTGate[])) : () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, we've tried to place input elements of type Qubit[]
last, as we have found that they are the most commonly to be left as _
in partial application. That way, for most common usecases, partial application looks like currying. Would you be willing to swap the order of qubits
and synth
? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, also makes the code in HiddenShiftProblem
look more consistent.
@@ -0,0 +1,82 @@ | |||
// Author: Mathias Soeken, EPFL (Mail: mathias.soeken@epfl.ch) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I apologize for the hassle, but I believe that we need for the copyright header to match the headers on other files; would you be willing to modify the PR accordingly? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, will fix that.
Thanks for the feedback. My last commit addresses the comments. |
Wonderful, thank you so much! |
* fixing doc gen call * adding a test for docs generation * need to generate docs for source files only such that we can build the docs for muliple dlls without interferences * forgot to check if the dictionary exists before clearning it in test
This is an Q# implementation of the unidirectional variant of the transformation based synthesis approach [Miller, Maslov, Dueck, DAC 2003].
There are two example operations that are using the automatic synthesis algorithms. The first example finds the circuit for the permutation and checks whether it correctly computes the permutation using exhaustive simulation of all input patterns. The second example implements an instance of the hidden-shift quantum algorithm, in which the bent function is the inner product applied to a two set of qubits, where the first set of qubits is permuted.
There are tests for the utility functions and the synthesis function.
I tried to follow code conventions and documentation styles as I saw it in other samples.