Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Merged
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
9 changes: 9 additions & 0 deletions src/Simulation/Simulators.Tests/Circuits/CoreOperations.qs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ namespace Microsoft.Quantum.Tests.CoreOperations {

// Using a different namespace, so tests can be auto-discovered.
namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits {
open Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics;
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Diagnostics;
Expand Down Expand Up @@ -559,6 +560,14 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits {
}
}

operation ReleaseMeasureMultipleQubitCheck() : Unit {
using (qs = Qubit[2]) {
ApplyToEach(H, qs);
let r = Measure([PauliZ, PauliZ], qs);
// Should raise an exception
}
}

operation BorrowingQubitCheck () : Unit
{
using (q = Qubit())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ public async Task MeasuredQubitReleaseTest()
await ReleaseMeasuredQubitCheck.Run(sim);
}

//test to check that qubits cannot be released after multiple qubit measure
[Fact]
public async Task MeasuredMultipleQubitsReleaseTest()
{
var sim = new QuantumSimulator();

await Assert.ThrowsAsync<ReleasedQubitsAreNotInZeroState>(() => ReleaseMeasureMultipleQubitCheck.Run(sim));
}

//test to check that qubit that is released and reallocated is in state |0>
[Fact]
public async Task ReallocateQubitInGroundStateTest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
let arr = Default<Qubit[]>();
using (qs = Qubit[2]) {
Ignore(Measure([PauliX, PauliX], qs));
ResetAll(qs);
return "TargetedExe";
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/Simulation/Simulators/QuantumSimulator/Measure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ public QSimMeasure(QuantumSimulator m) : base(m)
{
throw new InvalidOperationException($"Both input arrays for {this.GetType().Name} (paulis,qubits), must be of same size");
}
foreach (Qubit q in qubits)
if (qubits.Length == 1)
{
//setting qubit as measured to allow for release
q.IsMeasured = true;
// When we are operating on a single qubit we will collapse the state, so mark
// that qubit as measured.
qubits[0].IsMeasured = true;
}
return Measure(Simulator.Id, (uint)paulis.Length, paulis.ToArray(), qubits.GetIds()).ToResult();
};
Expand Down