microsoft / microsoft/qdk

Make it easier to implement circuits described using mutable arrays

Open
#485 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement language
Dominant language
Rust
Stars
1k
Forks
212
Avg merge
3d 8h
Merged PRs (30d)
65

Description

From microsoft/qsharp-language#59:

> I was trying to implement the carry lookahead adder from https://arxiv.org/pdf/2004.01826.pdf . it has a step described like this:
>
> ![image](https://user-images.githubusercontent.com/79941/100188549-4ce9ca80-2e9f-11eb-8c26-323e8f710337.png)
>
> As you can see, their description involves storing a reference to an initialized qubit into an array, which will be used during later steps.
>
> Currently, it is difficult to implement this in Q# because:
>
> 1. The syntax for mutating an array-of-arrays is extremely verbose.
> 2. `set` lines prevent the creation of an automatic adjoint.
> 3. Qubits need to be allocated outside the nested loop, requiring you to separately calculate the total number you need to allocate instead of just relying on the loop to do it.
>
> I'm not exactly sure how to fix this, but it's something that I've run into more than once.
>
> Here are some ideas:
>
> 1. Have a concept of a "qubit pool", which you can iteratively ask for more qubits from and where all the qubits are deallocated when the pool goes away. Using a pool would prevent the automatic creation of an adjoint:
>
> ```
> using (pool = QubitPool()) {
> for (...complicated...) {
> let q = pool.allocate_another();
> }
> }
> ```
>
> 2. Add support for mutable arrays, and/or multi-dimensional arrays, and/or hash maps. Support syntax like `set map[(i, j)] = x`.
> 3. Allow the use of `set` statements inside of auto-adjoint operations as long as they invoke no operation that returns a value (except perhaps for some whitelisted special case operations like allocation). Implement these methods by executing them forwards, with all operations replaced by no-ops, recording the historical state of mutable variables. Then rewind while applying the inverses of the operations.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the linked microsoft/qsharp-language#59 discussion and the current Q# handling of array mutation, automatic adjoints, and qubit allocation. The issue presents several possible designs rather than a chosen change, so done requires selecting and specifying one approach before implementation and testing can begin.

Written by the indexing model from the issue text.

Assessment

Domain
compilers, quantum-computing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.