-
Notifications
You must be signed in to change notification settings - Fork 180
Enhancements to Microsoft.Quantum.Preparation namespace #344
Description
Enhancements to Microsoft.Quantum.Preparation namespace
Proposal
Deprecated API
(full signatures for replacements are listed below)
→function QuantumROM(targetError: Double, coefficients: Double[])PurifiedMixedState→function QuantumROMQubitCount(targetError: Double, nCoeffs: Int)PurifiedMixedStateRequirements→operation PrepareQubit(basis : Pauli, qubit : Qubit)PreparePauliEigenstate→operation PrepareArbitraryState(coefficients : ComplexPolar[], qubits : LittleEndian)PrepareArbitraryStateCP→ only as operationfunction StatePreparationComplexCoefficients(coefficients : ComplexPolar[])PrepareArbitraryStateCP→ only as operationfunction StatePreperationPositiveCoefficients(coefficients : Double[])PrepareArbitraryStateD
New UDTs
newtype MixedStatePreparation = (
Requirements: MixedStatePreparationRequirements,
Norm: Double,
Prepare: ((LittleEndian, Qubit[], Qubit[]) => Unit is Adj + Ctl)
);
newtype MixedStatePreparationRequirements = (
NTotalQubits: Int,
(
NIndexQubits: Int,
NDataQubits: Int,
NGarbageQubits: Int
)
);Note that Prepare takes as second parameter an additional Qubit register to prepare auxiliary data, e.g., the sign of a coefficient.
New or modified functions and operations
M.Q.Preparation namespace
function PurifiedMixedState(targetError : Double, coefficients : Double[]) : MixedStatePreparation
(new name and signature forQuantumROM)function PurifiedMixedStateWithData(targetError : Double, coefficients : (Double, Bool[])[]) : MixedStatePreparationfunction PurifiedMixedStateRequirements(targetError : Double, nCoefficients : Int) : MixedStatePreparationRequirementsoperation PreparePauliEigenstate(basis : Pauli, qubit : Qubit) : Unitoperation PrepareArbitraryStateCP(coefficients : ComplexPolar[], qubits : LittleEndian) : Unit is Adj + Ctloperation PrepareArbitraryStateD(coefficients : Double[], qubits : LittleEndian) : Unit is Adj + Ctlfunction BlochSphereCoordinates(a0 : ComplexPolar, a1 : ComplexPolar) : (ComplexPolar, Double, Double)
Update: As per API review discussions, the term "purified mixed state" is used in the context of this proposal to mean states of the form |ψ⟩ = Σᵢ √𝑝ᵢ |𝑖⟩ |garbageᵢ⟩ specified by a vector of coefficients {𝑝ᵢ}. States of this form can be reduced to mixed states ρ ≔ 𝑝ᵢ |𝑖⟩⟨𝑖| by tracing over the "garbage" register (that is, a mixed state that is diagonal in the computational basis). Similarly, a "purified mixed state with data" refers to a state of the form Σᵢ √𝑝ᵢ |𝑖⟩ |𝑥ᵢ⟩ |garbageᵢ⟩, where each 𝑥ᵢ is a bitstring encoding additional data associated with the register |𝑖⟩.
See https://arxiv.org/pdf/1805.03662.pdf?page=15 for further discussion.
M.Q.Convert namespace
function DoubleAsComplexPolar(input : Double) : ComplexPolar
Example use cases
Prepare purified mixed state and also output sign of coefficient
let coefficients = [3.14, -1.59, -2.65, -3.58];
// extract sign and wrap it into singleton Bool array
let data = Mapped(ConstantArray(1, _), Mapped(LessThanD(_, 0.0), coefficients));
let state = PurifiedMixedStateWithData(10e-2, Zipped(coefficients, data));
let reqs = state::Requirements;
using ((indexQubits, dataQubits, garbageQubits) = (reqs::NIndexQubits, reqs::NDataQubits, reqs::NGarbageQubits)) {
state::Prepare(LittleEndian(indexQubits), dataQubits, garbageQubits);
let signQubit = Head(dataQubits);
// ...
}Considerations
- Some changes are already implemented as part of Classical Control Migrate qsharp-compiler#322
- Previous discussion on these changes in Generic function unnexpectedly returns 'QVoid' when called from another file qsharp-runtime#76 with implementations in Bug fix for attribute resolution qsharp-compiler#212 (we can reuse parts of these implementations)