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 90
Change to allow a qubit to be released if it is measured #231
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e0c1bed
Change to allow relese of qubit if measured
205a386
added comments to change to allow relese of qubit if measured
2dd3672
Changes to reflect PR review
2cf468a
Changes to add documentation as per PR review
1fc5bcf
Merge branch 'master' into anikda_rampup
AniketDalvi 806a638
Test renamed to reflect PR review
5014364
Merge branch 'master' into anikda_rampup
bettinaheim 0a02ee8
Merge branch 'master' into anikda_rampup
bettinaheim 3f0f59b
Merge branch 'master' into anikda_rampup
bettinaheim 90aa8c9
Updated summary of CheckQubit functions to reflect change in isMeasur…
fe2a1aa
Added test for checking state of reallocated qubit
318c5b4
Merge branch 'master' into anikda_rampup
AniketDalvi 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
64 changes: 64 additions & 0 deletions
64
src/Simulation/Simulators.Tests/QuantumSimulatorTests/QubitReleaseTest.cs
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,64 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Quantum.Simulation.Core; | ||
| using Microsoft.Quantum.Simulation.Simulators.Exceptions; | ||
| using Microsoft.Quantum.Simulation.Simulators.Tests.Circuits; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.Quantum.Simulation.Simulators.Tests | ||
| { | ||
| public partial class QuantumSimulatorTests | ||
| { | ||
| //test to check that qubit cannot be released if it is not in zero state | ||
| [Fact] | ||
| public async Task ZeroStateQubitReleaseTest() | ||
| { | ||
| var sim = new QuantumSimulator(); | ||
|
|
||
| await Assert.ThrowsAsync<ReleasedQubitsAreNotInZeroState>(() => UsingQubitCheck.Run(sim)); | ||
| } | ||
|
|
||
| //test to check that qubit can be released if measured | ||
| [Fact] | ||
| public async Task MeasuredQubitReleaseTest() | ||
| { | ||
| var sim = new QuantumSimulator(); | ||
|
|
||
| //should not throw an exception, as Measured qubits are allowed to be released, and the release aspect is handled in the C++ code | ||
| await ReleaseMeasuredQubitCheck.Run(sim); | ||
| } | ||
|
|
||
| //test to check that qubit that is released and reallocated is in state |0> | ||
| [Fact] | ||
| public async Task ReallocateQubitInGroundStateTest() | ||
| { | ||
| var sim = new QuantumSimulator(); | ||
| var allocate = sim.Get<Intrinsic.Allocate>(); | ||
| var release = sim.Get<Intrinsic.Release>(); | ||
| var q1 = allocate.Apply(1); | ||
| var q1Id = q1[0].Id; | ||
| var gate = sim.Get<Intrinsic.X>(); | ||
| var measure = sim.Get<Intrinsic.M>(); | ||
| gate.Apply(q1[0]); | ||
| var result1 = measure.Apply(q1[0]); | ||
| //Check X operation | ||
| Assert.Equal(result1, Result.One); | ||
| release.Apply(q1[0]); | ||
| var q2 = allocate.Apply(1); | ||
| var q2Id = q2[0].Id; | ||
| //Assert reallocated qubit has the same id as the one released | ||
| Assert.Equal(q1Id, q2Id); | ||
| var result2 = measure.Apply(q2[0]); | ||
| //Assert reallocated qubit has is initialized in state |0> | ||
| Assert.Equal(result2, Result.Zero); | ||
|
|
||
|
|
||
|
|
||
| } | ||
| } | ||
| } |
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
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
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.
Any reason that the "if (q == null) throw new ArgumentNullException..." in CheckQubitInUse above is not just replace with a call to CheckQubit? Then all the adaptions in CheckQubits would not be needed.
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.
I am unsure of why it is in the current state. However, before making a change around this, I would let the original author comment on this, as this was as is when I looked at it.
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.
If you don't here back, please add that change - I will be to blame for any resulting issues. :)