Skip to content

Remove w/= and w/ operations in our repo's Q# code #2423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 compiler/qsc_partial_eval/src/tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,5 +606,5 @@ fn evaluation_error_within_stdlib_yield_correct_package_span() {
}
"#,
});
assert_error(&error, &expect!["UnexpectedDynamicValue(PackageSpan { package: PackageId(1), span: Span { lo: 13910, hi: 13925 } })"]);
assert_error(&error, &expect!["UnexpectedDynamicValue(PackageSpan { package: PackageId(1), span: Span { lo: 13902, hi: 13917 } })"]);
}
2 changes: 1 addition & 1 deletion compiler/qsc_partial_eval/src/tests/qubits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,6 @@ fn qubit_relabel_in_dynamic_block_triggers_capability_error() {

assert_error(
&error,
&expect!["CapabilityError(UseOfDynamicQubit(Span { lo: 60173, hi: 60186 }))"],
&expect!["CapabilityError(UseOfDynamicQubit(Span { lo: 60168, hi: 60181 }))"],
);
}
6 changes: 3 additions & 3 deletions katas/content/KatasLibrary.qs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ namespace KatasUtils {
// get the solution's answer and verify if NOT a match, then differentiate what kind of mismatch
let ans = testImpl(q);
if ans != (state == 1) {
set misclassifications w/= state <- misclassifications[state] + 1;
misclassifications[state] += 1;
}

// If the final state is to be preserved, check if it was not modified
Expand Down Expand Up @@ -271,11 +271,11 @@ namespace KatasUtils {
if ans >= 0 and ans < nStates {
// classification result is a valid state index - check if is it correct
if ans != state {
set misclassifications w/= ((state * nStates) + ans) <- (misclassifications[(state * nStates) + ans] + 1);
misclassifications[(state * nStates) + ans] += 1;
}
} else {
// classification result is an invalid state index - file it separately
set unknownClassifications w/= state <- (unknownClassifications[state] + 1);
unknownClassifications[state] += 1;
}

if preserveState {
Expand Down
4 changes: 2 additions & 2 deletions katas/content/distinguishing_unitaries/Common.qs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ namespace Kata.Verification {

if returnedIndex != actualIndex {
if returnedIndex < 0 or returnedIndex >= nUnitaries {
set unknownClassifications w/= actualIndex <- unknownClassifications[actualIndex] + 1;
unknownClassifications[actualIndex] += 1;
} else {
let index = actualIndex * nUnitaries + returnedIndex;
set wrongClassifications w/= index <- wrongClassifications[index] + 1;
wrongClassifications[index] += 1;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion katas/content/key_distribution/examples/BB84Demo.qs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace Kata {
operation RandomArray(N : Int) : Bool[] {
mutable array = [false, size = N];
for i in 0..N - 1 {
set array w/= i <- DrawRandomInt(0, 1) == 0;
array[i] = DrawRandomInt(0, 1) == 0;
}
return array;
}
Expand Down
2 changes: 1 addition & 1 deletion katas/content/key_distribution/random_array/Solution.qs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Kata {
operation RandomArray(N : Int) : Bool[] {
mutable array = [false, size = N];
for i in 0..N - 1 {
set array w/= i <- DrawRandomInt(0, 1) == 0;
array[i] = DrawRandomInt(0, 1) == 0;
}
return array;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Kata {
// and convert the result to an integer, interpreting it as big endian binary notation.
let result = (MResetZ(qs[0]) == One ? 1 | 0) * 2 + (MResetZ(qs[1]) == One ? 1 | 0);

set countArray w/= result <- countArray[result] + 1;
countArray[result] += 1;
}

// Obtain simulated probability of measurement for each outcome.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Kata {

// Measure the first qubit.
let outcome = M(qs[0]) == Zero ? 0 | 1;
set countArray w/= outcome <- countArray[outcome] + 1;
countArray[outcome] += 1;

if countArray[outcome] == 1 {
// The first time the outcome is 0/1, print the system state afterwards.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Kata {
mutable counts = [0, size = 2^n];
for _ in 1..100 {
let res = PhaseEstimation(U, P, n);
set counts w/= res <- counts[res] + 1;
counts[res] += 1;
}
for i in 0..2^n - 1 {
if counts[i] > 0 {
Expand Down
2 changes: 1 addition & 1 deletion katas/content/random_numbers/Common.qs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace Kata.Verification {
return 0x1;
}
set average += IntAsDouble(val);
set counts w/= val <- counts[val] + 1;
counts[val] += 1;
}

set average = average / IntAsDouble(nRuns);
Expand Down
6 changes: 3 additions & 3 deletions katas/content/solving_sat/Common.qs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ namespace Kata.Verification {
set nextInd = DrawRandomInt(0, nVar - 1);
} until (not usedVariables[nextInd])
fixup {}
set clause w/= k <- (nextInd, DrawRandomBool(0.5));
set usedVariables w/= nextInd <- true;
clause[k] = (nextInd, DrawRandomBool(0.5));
usedVariables[nextInd] = true;
}
return clause;
}
Expand All @@ -50,7 +50,7 @@ namespace Kata.Verification {
mutable problem = [[(0, false), size = 0], size = nClause];

for j in 0..nClause - 1 {
set problem w/= j <- Generate_SAT_Clause(nVar, nTerms);
problem[j] = Generate_SAT_Clause(nVar, nTerms);
}
return problem;
}
Expand Down
14 changes: 7 additions & 7 deletions library/chemistry/src/JordanWigner/BlockEncoding.qs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ function JWBlockEncodingGeneratorSystem(data : JWOptimizedHTerms) : GeneratorSys

for idx in IndexRange(ZData) {
// Array of Arrays of Length 1
genIdxes w/= idx <- (ZTermToPauliGenIdx(HTermToGenIdx(ZData[idx], [0])))[0];
genIdxes[idx] = (ZTermToPauliGenIdx(HTermToGenIdx(ZData[idx], [0])))[0];
}

startIdx = Length(ZData);

for idx in IndexRange(ZZData) {
// Array of Arrays of Length 1
genIdxes w/= startIdx + idx <- (ZZTermToPauliGenIdx(HTermToGenIdx(ZZData[idx], [1])))[0];
genIdxes[startIdx + idx] = (ZZTermToPauliGenIdx(HTermToGenIdx(ZZData[idx], [1])))[0];
}

startIdx = startIdx + Length(ZZData);
Expand All @@ -66,8 +66,8 @@ function JWBlockEncodingGeneratorSystem(data : JWOptimizedHTerms) : GeneratorSys

// Array of Arrays of Length 2
let genArr = PQandPQQRTermToPauliGenIdx(HTermToGenIdx(PQandPQQRData[idx], [2]));
genIdxes w/= startIdx + 2 * idx <- genArr[0];
genIdxes w/= (startIdx + 2 * idx) + 1 <- genArr[1];
genIdxes[startIdx + 2 * idx] = genArr[0];
genIdxes[(startIdx + 2 * idx) + 1] = genArr[1];
}

startIdx = startIdx + 2 * Length(PQandPQQRData);
Expand All @@ -78,7 +78,7 @@ function JWBlockEncodingGeneratorSystem(data : JWOptimizedHTerms) : GeneratorSys
let genArr = V0123TermToPauliGenIdx(HTermToGenIdx(h0123Data[idx], [3]));

for idx0123 in IndexRange(genArr) {
genIdxes w/= finalIdx <- genArr[idx0123];
genIdxes[finalIdx] = genArr[idx0123];
finalIdx += 1;
}
}
Expand Down Expand Up @@ -203,11 +203,11 @@ function V0123TermToPauliGenIdx(term : GeneratorIndex) : GeneratorIndex[] {
for idxOp in IndexRange(ops) {
if (IsNotZero(v0123[idxOp % 4])) {
let newCoeff = [v0123[idxOp % 4]];
genIdxes w/= nonZero <- new GeneratorIndex {
genIdxes[nonZero] = new GeneratorIndex {
Term = (ops[idxOp] + Repeated(3, Length(qubitsPQJW) + Length(qubitsRSJW)), newCoeff),
Subsystem = ((qubitsPQ + qubitsRS) + qubitsPQJW) + qubitsRSJW
};
nonZero = nonZero + 1;
nonZero += 1;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ function ComputeJWBitString(nFermions : Int, idxFermions : Int[]) : Bool[] {
}
// NOTE: This could be optimized
for idx in 0..fermionIdx {
zString w/= idx <- not zString[idx];
zString[idx] = not zString[idx];
}
}

for fermionIdx in idxFermions {
zString w/= fermionIdx <- false;
zString[fermionIdx] = false;
}
return zString;
}
Expand All @@ -60,7 +60,7 @@ function ComputeJWPauliZString(nFermions : Int, idxFermions : Int[]) : Pauli[] {
mutable pauliString = Repeated(PauliI, Length(bitString));
for idx in IndexRange(bitString) {
if bitString[idx] {
pauliString w/= idx <- PauliZ;
pauliString[idx] = PauliZ;
}
}
return pauliString;
Expand All @@ -79,7 +79,7 @@ function ComputeJWPauliString(
for idx in IndexRange(idxFermions) {
let idxFermion = idxFermions[idx];
let op = pauliReplacements[idx];
pauliString w/= idxFermion <- op;
pauliString[idxFermion] = op;
}

return pauliString;
Expand Down
18 changes: 9 additions & 9 deletions library/chemistry/src/JordanWigner/OptimizedBlockEncoding.qs
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,15 @@ function V0123TermToPauliMajIdx(term : GeneratorIndex) : OptimizedBETermIndex[]
for idxOp in 0..3 {
if IsNotZero(v0123[idxOp]) {
let newCoeff = (2.0 * 0.25) * v0123[idxOp];
majIdxes w/= nonZero <- new OptimizedBETermIndex {
majIdxes[nonZero] = new OptimizedBETermIndex {
Coefficient = newCoeff,
UseSignQubit = v0123[idxOp] < 0.0,
ZControlRegisterMask = selectZControlRegisters,
OptimizedControlRegisterMask = optimizedBEControlRegisters,
PauliBases = ops[idxOp],
RegisterIndices = indexRegisters
};
nonZero = nonZero + 1;
nonZero += 1;
}
}

Expand Down Expand Up @@ -322,25 +322,25 @@ function OptimizedBlockEncodingGeneratorSystem(data : JWOptimizedHTerms) : Optim

for idx in IndexRange(ZData) {
// Array of Arrays of Length 1
majIdxes w/= idx <- ZTermToPauliMajIdx(HTermToGenIdx(ZData[idx], [0]));
majIdxes[idx] = ZTermToPauliMajIdx(HTermToGenIdx(ZData[idx], [0]));
}

startIdx = Length(ZData);

for idx in IndexRange(ZZData) {
// Array of Arrays of Length 1
majIdxes w/= startIdx + idx <- ZZTermToPauliMajIdx(HTermToGenIdx(ZZData[idx], [1]));
majIdxes[startIdx + idx] = ZZTermToPauliMajIdx(HTermToGenIdx(ZZData[idx], [1]));
}

startIdx = startIdx + Length(ZZData);
startIdx += Length(ZZData);

for idx in IndexRange(PQandPQQRData) {

// Array of Arrays of Length 1
majIdxes w/= startIdx + idx <- PQandPQQRTermToPauliMajIdx(HTermToGenIdx(PQandPQQRData[idx], [2]));
majIdxes[startIdx + idx] = PQandPQQRTermToPauliMajIdx(HTermToGenIdx(PQandPQQRData[idx], [2]));
}

startIdx = startIdx + Length(PQandPQQRData);
startIdx += Length(PQandPQQRData);
mutable finalIdx = startIdx;

for idx in 0..Length(h0123Data) - 1 {
Expand All @@ -349,8 +349,8 @@ function OptimizedBlockEncodingGeneratorSystem(data : JWOptimizedHTerms) : Optim
let genArr = V0123TermToPauliMajIdx(HTermToGenIdx(h0123Data[idx], [3]));

for idx0123 in IndexRange(genArr) {
majIdxes w/= finalIdx <- genArr[idx0123];
finalIdx = finalIdx + 1;
majIdxes[finalIdx] = genArr[idx0123];
finalIdx += 1;
}
}

Expand Down
26 changes: 13 additions & 13 deletions library/chemistry/src/JordanWigner/VQE.qs
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ function MeasurementOperators(
if termType == 0 or termType == 1 {
mutable op = Repeated(PauliI, nQubits);
for idx in indices {
op w/= idx <- PauliZ;
op[idx] = PauliZ;
}
ops w/= 0 <- op;
ops[0] = op;
}

// PQRS terms set operators between indices P and Q (resp R and S) to PauliZ
Expand All @@ -267,15 +267,15 @@ function MeasurementOperators(

mutable op = Repeated(PauliI, nQubits);
for idx in IndexRange(indices) {
op w/= indices[idx] <- compactOp[idx];
op[indices[idx]] = compactOp[idx];
}
for i in indices[0] + 1..indices[1] - 1 {
op w/= i <- PauliZ;
op[i] = PauliZ;
}
for i in indices[2] + 1..indices[3] - 1 {
op w/= i <- PauliZ;
op[i] = PauliZ;
}
ops w/= iOp <- op;
ops[iOp] = op;
}
}

Expand All @@ -289,17 +289,17 @@ function MeasurementOperators(
mutable op = Repeated(PauliI, nQubits);

let nIndices = Length(indices);
op w/= indices[0] <- compactOp[0];
op w/= indices[nIndices-1] <- compactOp[1];
op[indices[0]] = compactOp[0];
op[indices[nIndices-1]] = compactOp[1];
for i in indices[0] + 1..indices[nIndices - 1] - 1 {
op w/= i <- PauliZ;
op[i] = PauliZ;
}

// Case of PQQR term
if nIndices == 4 {
op w/= indices[1] <- (indices[0] < indices[1] and indices[1] < indices[3]) ? PauliI | PauliZ;
op[indices[1]] = (indices[0] < indices[1] and indices[1] < indices[3]) ? PauliI | PauliZ;
}
ops w/= iOp <- op;
ops[iOp] = op;
}
}

Expand Down Expand Up @@ -333,10 +333,10 @@ function ExpandedCoefficients(coeff : Double[], termType : Int) : Double[] {

// Return the expanded array of coefficients
if termType == 0 or termType == 1 {
coeffs w/= 0 <- coeff[0];
coeffs[0] = coeff[0];
} elif termType == 2 or termType == 3 {
for i in 0..nCoeffs - 1 {
coeffs w/= i <- coeff[i / 2];
coeffs[i] = coeff[i / 2];
}
}

Expand Down
8 changes: 4 additions & 4 deletions library/chemistry/src/MixedStatePreparation.qs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function QuantumROMDiscretization(bitsPrecision : Int, coefficients : Double[])

// Uniformly distribute excess bars across coefficients.
for idx in 0..AbsI(bars) - 1 {
keepCoeff w/= idx <- keepCoeff[idx] + (bars > 0 ? -1 | + 1);
keepCoeff[idx] += (bars > 0 ? -1 | + 1);
}

mutable barSink = [];
Expand All @@ -241,8 +241,8 @@ function QuantumROMDiscretization(bitsPrecision : Int, coefficients : Double[])
barSink = Most(barSink);
barSource = Most(barSource);

keepCoeff w/= idxSource <- keepCoeff[idxSource] - barHeight + keepCoeff[idxSink];
altIndex w/= idxSink <- idxSource;
keepCoeff[idxSource] += keepCoeff[idxSink] - barHeight;
altIndex[idxSink] = idxSource;

if keepCoeff[idxSource] < barHeight {
barSink += [idxSource];
Expand All @@ -252,7 +252,7 @@ function QuantumROMDiscretization(bitsPrecision : Int, coefficients : Double[])
} elif Length(barSource) > 0 {
let idxSource = Tail(barSource);
barSource = Most(barSource);
keepCoeff w/= idxSource <- barHeight;
keepCoeff[idxSource] = barHeight;
} else {
return (oneNorm, keepCoeff, altIndex);
}
Expand Down
2 changes: 1 addition & 1 deletion library/fixed_point/src/Convert.qs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function FixedPointAsBoolArray(integerBits : Int, fractionalBits : Int, value :
set currentBit = not currentBit;
}
if currentBit {
set result w/= idx <- true;
result[idx] = true;
}
}

Expand Down
2 changes: 1 addition & 1 deletion library/src/tests/resources/src/state_preparation.qs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ namespace Test {
let bitsize = 2^n;
for i in 0..bitsize - 1 {
mutable c = Repeated(0.0, bitsize);
set c w/= i <- 1.0;
c[i] = 1.0;
PreparePureStateD(c, qs);
DumpMachine();
ResetAll(qs);
Expand Down
Loading
Loading