Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Implements transformation-based synthesis in Q# #41

Merged
merged 7 commits into from Apr 6, 2018

Conversation

msoeken
Copy link
Member

@msoeken msoeken commented Apr 3, 2018

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.

Copy link
Contributor

@cgranade cgranade left a 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
Copy link
Contributor

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!

Copy link
Member Author

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[] {
Copy link
Contributor

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?

Copy link
Member Author

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);
Copy link
Contributor

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.

Copy link
Member Author

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[])) : () {
Copy link
Contributor

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!

Copy link
Member Author

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)
Copy link
Contributor

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!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, will fix that.

@msoeken
Copy link
Member Author

msoeken commented Apr 5, 2018

Thanks for the feedback. My last commit addresses the comments.

@cgranade
Copy link
Contributor

cgranade commented Apr 6, 2018

Wonderful, thank you so much!

@cgranade cgranade merged commit 13eea5d into master Apr 6, 2018
@anpaz anpaz deleted the msoeken/reversible-logic-synthesis branch February 1, 2019 22:33
jwittner pushed a commit to jwittner/Quantum that referenced this pull request Dec 16, 2019
* 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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants