Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Cherry-Picked: Broken up QuantumSimulator into CommonNativeSimulator and QuantumSimulator #895

Merged
merged 2 commits into from
Jan 11, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

namespace Microsoft.Quantum.Simulation.Simulators
{
public partial class QuantumSimulator
public partial class CommonNativeSimulator
{
void IIntrinsicApplyControlledX.Body(Qubit control, Qubit target)
{
this.CheckQubits(new QArray<Qubit>(new Qubit[]{ control, target }));

MCX(this.Id, 1, new uint[]{(uint)control.Id}, (uint)target.Id);
MCX(1, new uint[]{(uint)control.Id}, (uint)target.Id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

namespace Microsoft.Quantum.Simulation.Simulators
{
public partial class QuantumSimulator
public partial class CommonNativeSimulator
{
void IIntrinsicApplyControlledZ.Body(Qubit control, Qubit target)
{
this.CheckQubits(new QArray<Qubit>(new Qubit[]{ control, target }));

MCZ(this.Id, 1, new uint[]{(uint)control.Id}, (uint)target.Id);
MCZ(1, new uint[]{(uint)control.Id}, (uint)target.Id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

namespace Microsoft.Quantum.Simulation.Simulators
{
public partial class QuantumSimulator
public partial class CommonNativeSimulator
{
void IIntrinsicApplyUncontrolledH.Body(Qubit target)
{
this.CheckQubit(target);

H(this.Id, (uint)target.Id);
H((uint)target.Id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

namespace Microsoft.Quantum.Simulation.Simulators
{
public partial class QuantumSimulator
public partial class CommonNativeSimulator
{
void IIntrinsicApplyUncontrolledRx.Body(double angle, Qubit target)
{
this.CheckQubit(target, nameof(target));
CheckAngle(angle);
R(this.Id, Pauli.PauliX, angle, (uint)target.Id);
R(Pauli.PauliX, angle, (uint)target.Id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

namespace Microsoft.Quantum.Simulation.Simulators
{
public partial class QuantumSimulator
public partial class CommonNativeSimulator
{
void IIntrinsicApplyUncontrolledRy.Body(double angle, Qubit target)
{
this.CheckQubit(target, nameof(target));
CheckAngle(angle);
R(this.Id, Pauli.PauliY, angle, (uint)target.Id);
R(Pauli.PauliY, angle, (uint)target.Id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

namespace Microsoft.Quantum.Simulation.Simulators
{
public partial class QuantumSimulator
public partial class CommonNativeSimulator
{
void IIntrinsicApplyUncontrolledRz.Body(double angle, Qubit target)
{
this.CheckQubit(target, nameof(target));
CheckAngle(angle);
R(this.Id, Pauli.PauliZ, angle, (uint)target.Id);
R(Pauli.PauliZ, angle, (uint)target.Id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

namespace Microsoft.Quantum.Simulation.Simulators
{
public partial class QuantumSimulator
public partial class CommonNativeSimulator
{
void IIntrinsicApplyUncontrolledS.Body(Qubit target)
{
this.CheckQubit(target);

S(this.Id, (uint)target.Id);
S((uint)target.Id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

namespace Microsoft.Quantum.Simulation.Simulators
{
public partial class QuantumSimulator
public partial class CommonNativeSimulator
{
void IIntrinsicApplyUncontrolledSAdj.Body(Qubit target)
{
this.CheckQubit(target);

AdjS(this.Id, (uint)target.Id);
AdjS((uint)target.Id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Microsoft.Quantum.Simulation.Simulators
{
public partial class QuantumSimulator
public partial class CommonNativeSimulator
{
void IIntrinsicApplyUncontrolledSWAP.Body(Qubit qubit1, Qubit qubit2)
{
Expand All @@ -16,9 +16,9 @@ void IIntrinsicApplyUncontrolledSWAP.Body(Qubit qubit1, Qubit qubit2)

this.CheckQubits(new QArray<Qubit>(new Qubit[]{ qubit1, qubit2 }));

MCX(this.Id, 1, new uint[]{(uint)qubit1.Id}, (uint)qubit2.Id);
MCX(this.Id, 1, new uint[]{(uint)qubit2.Id}, (uint)qubit1.Id);
MCX(this.Id, 1, new uint[]{(uint)qubit1.Id}, (uint)qubit2.Id);
MCX(1, new uint[]{(uint)qubit1.Id}, (uint)qubit2.Id);
MCX(1, new uint[]{(uint)qubit2.Id}, (uint)qubit1.Id);
MCX(1, new uint[]{(uint)qubit1.Id}, (uint)qubit2.Id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

namespace Microsoft.Quantum.Simulation.Simulators
{
public partial class QuantumSimulator
public partial class CommonNativeSimulator
{
void IIntrinsicApplyUncontrolledT.Body(Qubit target)
{
this.CheckQubit(target);

T(this.Id, (uint)target.Id);
T((uint)target.Id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

namespace Microsoft.Quantum.Simulation.Simulators
{
public partial class QuantumSimulator
public partial class CommonNativeSimulator
{
void IIntrinsicApplyUncontrolledTAdj.Body(Qubit target)
{
this.CheckQubit(target);

AdjT(this.Id, (uint)target.Id);
AdjT((uint)target.Id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

namespace Microsoft.Quantum.Simulation.Simulators
{
public partial class QuantumSimulator
public partial class CommonNativeSimulator
{
void IIntrinsicApplyUncontrolledX.Body(Qubit target)
{
this.CheckQubit(target);

X(this.Id, (uint)target.Id);
X((uint)target.Id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

namespace Microsoft.Quantum.Simulation.Simulators
{
public partial class QuantumSimulator
public partial class CommonNativeSimulator
{
void IIntrinsicApplyUncontrolledY.Body(Qubit target)
{
this.CheckQubit(target);

Y(this.Id, (uint)target.Id);
Y((uint)target.Id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

namespace Microsoft.Quantum.Simulation.Simulators
{
public partial class QuantumSimulator
public partial class CommonNativeSimulator
{
void IIntrinsicApplyUncontrolledZ.Body(Qubit target)
{
this.CheckQubit(target);

Z(this.Id, (uint)target.Id);
Z((uint)target.Id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@

namespace Microsoft.Quantum.Simulation.Simulators
{
public partial class QuantumSimulator
public partial class CommonNativeSimulator
{
// `QSimAssert` makes an impression that it is never used,
// but since it inherits from Quantum.Diagnostics.AssertMeasurement
// (which is a C# class that corresponds to a Q# operation in our core libraries), it will be automatically used.
// It is instantiated via reflection, hence we don't see it easily in the code.
public class QSimAssert : Microsoft.Quantum.Diagnostics.AssertMeasurement
{
private QuantumSimulator Simulator { get; }
private CommonNativeSimulator Simulator { get; }

public QSimAssert(QuantumSimulator m) : base(m)
public QSimAssert(CommonNativeSimulator m) : base(m)
{
this.Simulator = m;
}
Expand All @@ -32,7 +36,7 @@ public QSimAssert(QuantumSimulator m) : base(m)
var tolerance = 1.0e-10;
var expectedPr = result == Result.Zero ? 0.0 : 1.0;

var ensemblePr = JointEnsembleProbability(this.Simulator.Id, (uint)paulis.Length, paulis.ToArray(), qubits.GetIds());
var ensemblePr = this.Simulator.JointEnsembleProbability((uint)paulis.Length, paulis.ToArray(), qubits.GetIds());

if (Abs(ensemblePr - expectedPr) > tolerance)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@

namespace Microsoft.Quantum.Simulation.Simulators
{
public partial class QuantumSimulator
public partial class CommonNativeSimulator
{
// `QSimAssertProb` makes an impression that it is never used,
// but since it inherits from Quantum.Diagnostics.AssertMeasurementProbability
// (which is a C# class that corresponds to a Q# operation in our core libraries), it will be automatically used.
// It is instantiated via reflection, hence we don't see it easily in the code.
public class QSimAssertProb : Microsoft.Quantum.Diagnostics.AssertMeasurementProbability
{
private QuantumSimulator Simulator { get; }
private CommonNativeSimulator Simulator { get; }

public QSimAssertProb(QuantumSimulator m) : base(m)
public QSimAssertProb(CommonNativeSimulator m) : base(m)
{
this.Simulator = m;
}
Expand All @@ -38,7 +42,7 @@ public QSimAssertProb(QuantumSimulator m) : base(m)
expectedPr = 1 - expectedPr;
}

var ensemblePr = JointEnsembleProbability(Simulator.Id, (uint)paulis.Length, paulis.ToArray(), qubits.GetIds());
var ensemblePr = this.Simulator.JointEnsembleProbability((uint)paulis.Length, paulis.ToArray(), qubits.GetIds());

if (Abs(ensemblePr - expectedPr) > tol)
{
Expand Down
Loading