public async Task ReallocateQubitInGroundStateTest() { var sim = new QrackSimulator(); 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); }
public void QrackSimX() { using (var sim = new QrackSimulator(throwOnReleasingQubitsNotInZeroState: false)) { var x = sim.Get <Intrinsic.X>(); var measure = sim.Get <Intrinsic.M>(); var set = sim.Get <Measurement.SetToBasisState>(); var ctrlX = x.__ControlledBody__.AsAction(); OperationsTestHelper.ctrlTestShell(sim, ctrlX, (enabled, ctrls, q) => { set.Apply((Result.Zero, q)); var result = measure.Apply(q); var expected = Result.Zero; Assert.Equal(expected, result); x.__ControlledBody__((ctrls, q)); result = measure.Apply(q); expected = (enabled) ? Result.One : Result.Zero; Assert.Equal(expected, result); });