This repository was archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 180
Extend PurifiedMixedState for additional data preparation #322
Merged
cgranade
merged 23 commits into
feature/state-preparation
from
msoeken/state-preparation-sign
Nov 16, 2020
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
3cae584
Squashed commit of the following:
msoeken 4e7db2b
Remove duplicate code and reduce T-count.
msoeken 50f20f9
Cleanup.
msoeken 9c7061f
Squashed commit of the following:
msoeken bb56b3a
Squashed commit of the following:
msoeken 44a2f38
Preparing function and tests for QuantumROM with signed coefficients.
msoeken 45afe21
Further unification.
msoeken d3dc13c
Ineffecient way of creating sign bit.
msoeken e41efcb
Embed sign computation in multiplex.
msoeken 0c48387
Merge branch 'feature/state-preparation' into msoeken/state-preparati…
msoeken 24b794a
Picking changes from #212.
msoeken 64081f8
Changes from #212.
msoeken 131ef14
Generalize.
msoeken 91c72c3
Generalize data register.
msoeken 5ef6081
Unifying signatures.
msoeken b761750
Use UDT for PurifiedState.
msoeken 39ac8d3
Docs and cleanup.
msoeken 927cc7a
Incoprate API changes.
msoeken 6ac7ddb
Fix bug on Mac.
msoeken 86a1c78
Make public because of #239.
msoeken 2e5eab7
Add deprecated functions.
msoeken 94b4652
Merge branch 'feature/state-preparation' into msoeken/state-preparati…
msoeken 5ddba9f
Merge branch 'feature/state-preparation' into msoeken/state-preparati…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Microsoft.Quantum.Preparation { | ||
|
|
||
| open Microsoft.Quantum.Arithmetic; | ||
|
|
||
| /// # Summary | ||
| /// Uses the Quantum ROM technique to represent a given density matrix. | ||
| /// | ||
| /// Given a list of $N$ coefficients $\alpha_j$, this returns a unitary $U$ that uses the Quantum-ROM | ||
| /// technique to prepare | ||
| /// an approximation $\tilde\rho\sum_{j=0}^{N-1}p_j\ket{j}\bra{j}$ of the purification of the density matrix | ||
| /// $\rho=\sum_{j=0}^{N-1}\frac{|alpha_j|}{\sum_k |\alpha_k|}\ket{j}\bra{j}$. In this approximation, the | ||
| /// error $\epsilon$ is such that $|p_j-\frac{|alpha_j|}{\sum_k |\alpha_k|}|\le \epsilon / N$ and | ||
| /// $\|\tilde\rho - \rho\| \le \epsilon$. In other words, | ||
| /// $$ | ||
| /// \begin{align} | ||
| /// U\ket{0}^{\lceil\log_2 N\rceil}\ket{0}^{m}=\sum_{j=0}^{N-1}\sqrt{p_j} \ket{j}\ket{\text{garbage}_j}. | ||
| /// \end{align} | ||
| /// $$ | ||
| /// | ||
| /// # Input | ||
| /// ## targetError | ||
| /// The target error $\epsilon$. | ||
| /// ## coefficients | ||
| /// Array of $N$ coefficients specifying the probability of basis states. | ||
| /// Negative numbers $-\alpha_j$ will be treated as positive $|\alpha_j|$. | ||
| /// | ||
| /// # Output | ||
| /// ## First parameter | ||
| /// A tuple `(x,(y,z))` where `x = y + z` is the total number of qubits allocated, | ||
| /// `y` is the number of qubits for the `LittleEndian` register, and `z` is the Number | ||
| /// of garbage qubits. | ||
| /// ## Second parameter | ||
| /// The one-norm $\sum_j |\alpha_j|$ of the coefficient array. | ||
| /// ## Third parameter | ||
| /// The unitary $U$. | ||
| /// | ||
| /// # Remarks | ||
| /// ## Example | ||
| /// The following code snippet prepares an purification of the $3$-qubit state | ||
| /// $\rho=\sum_{j=0}^{4}\frac{|alpha_j|}{\sum_k |\alpha_k|}\ket{j}\bra{j}$, where | ||
| /// $\vec\alpha=(1.0,2.0,3.0,4.0,5.0)$, and the error is `1e-3`; | ||
| /// ```qsharp | ||
| /// let coefficients = [1.0,2.0,3.0,4.0,5.0]; | ||
| /// let targetError = 1e-3; | ||
| /// let ((nTotalQubits, (nIndexQubits, nGarbageQubits)), oneNorm, op) = QuantumROM(targetError, coefficients); | ||
| /// using (indexRegister = Qubit[nIndexQubits]) { | ||
| /// using (garbageRegister = Qubit[nGarbageQubits]) { | ||
| /// op(LittleEndian(indexRegister), garbageRegister); | ||
| /// } | ||
| /// } | ||
| /// ``` | ||
| /// | ||
| /// # References | ||
| /// - Encoding Electronic Spectra in Quantum Circuits with Linear T Complexity | ||
| /// Ryan Babbush, Craig Gidney, Dominic W. Berry, Nathan Wiebe, Jarrod McClean, Alexandru Paler, Austin Fowler, Hartmut Neven | ||
| /// https://arxiv.org/abs/1805.03662 | ||
| @Deprecated("Microsoft.Quantum.Preparation.PurifiedMixedState") | ||
| function QuantumROM(targetError: Double, coefficients: Double[]) | ||
| : ((Int, (Int, Int)), Double, ((LittleEndian, Qubit[]) => Unit is Adj + Ctl)) { | ||
| let preparation = PurifiedMixedState(targetError, coefficients); | ||
| return ( | ||
| preparation::Requirements!, | ||
| preparation::Norm, | ||
| IgnoreDataRegister(preparation::Prepare, _, _) | ||
| ); | ||
| } | ||
|
|
||
| internal operation IgnoreDataRegister(op : ((LittleEndian, Qubit[], Qubit[]) => Unit is Adj + Ctl), indexRegister : LittleEndian, garbageRegister : Qubit[]) : Unit is Adj + Ctl { | ||
| op(indexRegister, new Qubit[0], garbageRegister); | ||
| } | ||
|
|
||
| /// # Summary | ||
| /// Returns the total number of qubits that must be allocated | ||
| /// to the operation returned by `QuantumROM`. | ||
| /// | ||
| /// # Input | ||
| /// ## targetError | ||
| /// The target error $\epsilon$. | ||
| /// ## nCoeffs | ||
| /// Number of coefficients specified in `QuantumROM`. | ||
| /// | ||
| /// # Output | ||
| /// ## First parameter | ||
| /// A tuple `(x,(y,z))` where `x = y + z` is the total number of qubits allocated, | ||
| /// `y` is the number of qubits for the `LittleEndian` register, and `z` is the Number | ||
| /// of garbage qubits. | ||
| @Deprecated("Microsoft.Quantum.Preparation.PurifiedMixedStateRequirements") | ||
| function QuantumROMQubitCount(targetError: Double, nCoeffs: Int) | ||
| : (Int, (Int, Int)) { | ||
| return (PurifiedMixedStateRequirements(targetError, nCoeffs))!; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 it be useful to add a docstring here?
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, there should be a doctoring here. I'll add it with the next commit.
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.
Deferring to the next PR as part of completing work on #344.