Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8e60956
Started work on code quality for M.Q.Preparation.
cgranade Jan 23, 2020
88f219d
Various quality improvements to arbitrary state prep.
cgranade Jan 23, 2020
e628997
Started refactoring quantum ROM feature.
cgranade Jan 23, 2020
7671cb8
Removed extraneous commented code.
cgranade Jan 23, 2020
48daae9
Added description of preparation verb.
cgranade Jan 23, 2020
0410446
Small improvements.
cgranade Jan 27, 2020
e84decf
Applied a consistent set of names for quantum ROM operations / functi…
cgranade Jan 28, 2020
3af5c57
Workaround for private dependence.
cgranade Jan 28, 2020
d959867
Begin removing extraneous use of partial application.
cgranade Jan 28, 2020
32c4e05
Added type suffixes, focused on only operation form.
cgranade Jan 28, 2020
4f3de29
Added test for new conversion function.
cgranade Jan 28, 2020
89945ac
Merge branch 'master' into cgranade/preparation-quality
Jan 28, 2020
f5c343f
Typo fix.
cgranade Jan 30, 2020
abef225
Add test coverage for BlochSphereCoordinates.
cgranade Jan 30, 2020
2bb0ae9
Improved test quality some.
cgranade Jan 30, 2020
f36a2e1
Merge branch 'master' into cgranade/preparation-quality
Jan 30, 2020
8c68168
Merge branch 'master' into cgranade/preparation-quality
Jan 30, 2020
160606b
Merge branches 'cgranade/preparation-quality' and 'cgranade/preparati…
cgranade Feb 4, 2020
418f40d
Merge branch 'master' into cgranade/preparation-quality
Feb 5, 2020
78e3a43
Merge branch 'master' into cgranade/preparation-quality
anpaz Feb 5, 2020
27ea3fd
Fixed a second typo.
cgranade Feb 6, 2020
da1e1ed
Slight test improvements.
cgranade Feb 6, 2020
e424747
Fix another typo.
cgranade Feb 12, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Build/check_indents.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def check_file(filename : str) -> bool:
found_spaces = False
found_tabs = False

with open(filename, 'r') as f:
with open(filename, 'r', encoding='utf8') as f:
contents = list(f.readlines())

for line in contents:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ namespace Microsoft.Quantum.Chemistry.JordanWigner {


function _JordanWignerOptimizedBlockEncodingQubitManager_ (targetError : Double, nCoeffs : Int, nZ : Int, nMaj : Int, nIdxRegQubits : Int, ctrlRegister : Qubit[]) : ((LittleEndian, Qubit[], Qubit, Qubit[], Qubit[], Qubit[], LittleEndian, LittleEndian[]), (Qubit, Qubit[], Qubit[], Qubit[], LittleEndian[]), Qubit[]) {

let ((qROMIdx, qROMGarbage), rest0) = _QuantumROMQubitManager(targetError, nCoeffs, ctrlRegister);
// FIXME: This is a dependency on a private function from a different assembly!
let ((qROMIdx, qROMGarbage), rest0) = _PartitionedForQuantumROM(targetError, nCoeffs, ctrlRegister);
let ((signQubit, selectZControlRegisters, optimizedBEControlRegisters, pauliBases, indexRegisters, tmp), rest1) = _JordanWignerSelectQubitManager_(nZ, nMaj, nIdxRegQubits, rest0, new Qubit[0]);
let registers = Partitioned([3], rest1);
let pauliBasesIdx = LittleEndian(registers[0]);
Expand Down
42 changes: 21 additions & 21 deletions Chemistry/src/Runtime/JordanWigner/StatePreparation.qs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ namespace Microsoft.Quantum.Chemistry.JordanWigner {

// The last term is the reference state.
let referenceState = PrepareTrialState((2, [terms[nTerms-1]]), _);

PrepareUnitaryCoupledClusterState(referenceState, terms[0..nTerms-2], trotterStepSize, qubits);
}
}


/// # Summary
/// Simple state preparation of trial state by occupying
/// spin-orbitals
Expand All @@ -54,23 +54,23 @@ namespace Microsoft.Quantum.Chemistry.JordanWigner {
/// ## qubits
/// Qubits of Hamiltonian.
operation PrepareSingleConfigurationalStateSingleSiteOccupation (qubitIndices : Int[], qubits : Qubit[]) : Unit {

body (...) {
ApplyToEachCA(X, Subarray(qubitIndices, qubits));
}

adjoint invert;
controlled distribute;
controlled adjoint distribute;
}


function _PrepareSingleConfigurationalStateSingleSiteOccupation (qubitIndices : Int[]) : (Qubit[] => Unit is Adj + Ctl) {

return PrepareSingleConfigurationalStateSingleSiteOccupation(qubitIndices, _);
}


/// # Summary
/// Sparse multi-configurational state preparation of trial state by adding excitations
/// to initial trial state.
Expand All @@ -85,34 +85,34 @@ namespace Microsoft.Quantum.Chemistry.JordanWigner {
/// ## qubits
/// Qubits of Hamiltonian.
operation PrepareSparseMultiConfigurationalState (initialStatePreparation : (Qubit[] => Unit), excitations : JordanWignerInputState[], qubits : Qubit[]) : Unit {

let nExcitations = Length(excitations);

//FIXME compile error let coefficientsSqrtAbs = Mapped(Compose(Compose(Sqrt, Fst),Fst), excitations);
mutable coefficientsSqrtAbs = new Double[nExcitations];
mutable coefficientsNewComplexPolar = new ComplexPolar[nExcitations];
mutable applyFlips = new Int[][nExcitations];

for (idx in 0 .. nExcitations - 1) {
let (x, excitation) = excitations[idx]!;
set coefficientsSqrtAbs w/= idx <- Sqrt(AbsComplexPolar(ComplexAsComplexPolar(Complex(x))));
set coefficientsNewComplexPolar w/= idx <- ComplexPolar(coefficientsSqrtAbs[idx], ArgComplexPolar(ComplexAsComplexPolar(Complex(x))));
set applyFlips w/= idx <- excitation;
}

let nBitsIndices = Ceiling(Lg(IntAsDouble(nExcitations)));

repeat {
mutable success = false;

using (auxillary = Qubit[nBitsIndices + 1]) {
using (flag = Qubit[1]) {
let multiplexer = MultiplexerBruteForceFromGenerator(nExcitations, LookupFunction(Mapped(_PrepareSingleConfigurationalStateSingleSiteOccupation, applyFlips)));
(StatePreparationComplexCoefficients(coefficientsNewComplexPolar))(LittleEndian(auxillary));
PrepareArbitraryStateCP(coefficientsNewComplexPolar, LittleEndian(auxillary));
multiplexer(LittleEndian(auxillary), qubits);
(Adjoint (StatePreparationPositiveCoefficients(coefficientsSqrtAbs)))(LittleEndian(auxillary));
Adjoint PrepareArbitraryStateD(coefficientsSqrtAbs, LittleEndian(auxillary));
(ControlledOnInt(0, X))(auxillary, flag[0]);

// if measurement outcome one we prepared required state
let outcome = Measure([PauliZ], flag);
set success = outcome == One;
Expand All @@ -126,9 +126,9 @@ namespace Microsoft.Quantum.Chemistry.JordanWigner {
ResetAll(qubits);
}
}

/// # Summary
/// Unitary coupled-cluster state preparation of trial state
/// Unitary coupled-cluster state preparation of trial state
///
/// # Input
/// ## initialStatePreparation
Expand Down
18 changes: 18 additions & 0 deletions Standard/src/Math/Convert.qs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@

namespace Microsoft.Quantum.Math {

/// # Summary
/// Converts a real floating-point number to a complex number in its polar
/// representation.
///
/// # Input
/// ## input
/// The real number to be represented as a complex number.
///
/// # Output
/// A complex number representing the given input in terms of polar
/// coordinates.
function DoubleAsComplexPolar(input : Double) : ComplexPolar {
return ComplexPolar(
AbsD(input),
input < 0.0 ? PI() | 0.0
);
}

/// # Summary
/// Converts a complex number of type `ComplexPolar` to a complex
/// number of type `Complex`.
Expand Down
Loading