private void TestHGate28Q() { QuantumCircuit qc = new QuantumCircuit(28); qc.Apply(Gates.H(0)); System.DateTime t = System.DateTime.Now; qc.Apply(Gates.H(0)); Debug.Log($"H: {(System.DateTime.Now - t).TotalMilliseconds / 1000f}s"); StateVector sv = qc.stateVector; }
public void ApplyOneGateProvideStateVectorToGate() { // Arrange QuantumCircuit qc = new QuantumCircuit(2); qc.stateVector[0] = Complex.Zero; qc.stateVector[1] = Complex.Zero; qc.stateVector[2] = Complex.One; qc.stateVector[3] = Complex.Zero; StateVector sv = new StateVector(2); IGate gate = new IGateMocks.GateStub(s => sv = s); Complex expect0IdxValue = Complex.Zero; Complex expect1IdxValue = Complex.Zero; Complex expect2IdxValue = Complex.One; Complex expect3IdxValue = Complex.Zero; // Act qc.Apply(gate); Complex actual0IdxValue = sv[0]; Complex actual1IdxValue = sv[1]; Complex actual2IdxValue = sv[2]; Complex actual3IdxValue = sv[3]; // Assert Assert.IsTrue(expect0IdxValue == actual0IdxValue && expect1IdxValue == actual1IdxValue && expect2IdxValue == actual2IdxValue && expect3IdxValue == actual3IdxValue, $"QuantumCircuit should pass the current StateVector to the gate, " + $"expected [ {expect0IdxValue}, {expect1IdxValue}, {expect2IdxValue}, {expect3IdxValue} ]" + $"but found [ {actual0IdxValue}, {actual1IdxValue}, {actual2IdxValue}, {actual3IdxValue} ]."); }
public void ApplyOneGateTest() { // Arrange QuantumCircuit qc = new QuantumCircuit(2); StateVector sv = new StateVector(2); sv[0] = Complex.Zero; sv[1] = Complex.Zero; sv[2] = Complex.Zero; sv[3] = Complex.One; IGate gate = new IGateMocks.GateStub(_ => sv); Complex expect0IdxValue = Complex.Zero; Complex expect1IdxValue = Complex.Zero; Complex expect2IdxValue = Complex.Zero; Complex expect3IdxValue = Complex.One; // Act qc.Apply(gate); Complex actual0IdxValue = qc.stateVector[0]; Complex actual1IdxValue = qc.stateVector[1]; Complex actual2IdxValue = qc.stateVector[2]; Complex actual3IdxValue = qc.stateVector[3]; // Assert Assert.IsTrue(expect0IdxValue == actual0IdxValue && expect1IdxValue == actual1IdxValue && expect2IdxValue == actual2IdxValue && expect3IdxValue == actual3IdxValue, $"Apply IGate should modify StateVector, " + $"expected [ {expect0IdxValue}, {expect1IdxValue}, {expect2IdxValue}, {expect3IdxValue} ]" + $"but found [ {actual0IdxValue}, {actual1IdxValue}, {actual2IdxValue}, {actual3IdxValue} ]."); }
private void TestHGate10Q() { QuantumCircuit qc = new QuantumCircuit(10); qc.Apply(Gates.H(0)); const int it = 100; System.DateTime t = System.DateTime.Now; for (int i = 0; i < it; i++) { qc.Apply(Gates.H(0)); } Debug.Log($"H: {(System.DateTime.Now - t).TotalMilliseconds / it}ms"); StateVector sv = qc.stateVector; }
private void TestCXGate() { QuantumCircuit qc = new QuantumCircuit(3); qc.Apply(Gates.H(0)); qc.Apply(new CXGate(1, 0)); qc.Apply(new CXGate(2, 0)); StateVector sv = qc.stateVector; string s = ""; for (int i = 0; i < sv.length; i++) { s += $"[{sv[i].Real:N2} :: {sv[i].Imaginary:N2}i]\n"; } Debug.Log(s); }
private void TestChunk() { for (int i = 8; i <= 16; i++) { const int it = 10; const int qubits = 28; StateVector.chunkSize = i; QuantumCircuit qc = new QuantumCircuit(qubits); qc.Apply(Gates.H(0)); System.DateTime t0 = System.DateTime.Now; for (int j = 0; j < it; j++) { qc.Apply(Gates.H(j % qubits)); } System.DateTime t1 = System.DateTime.Now; Debug.Log($"Chunk(2^{i}): {(t1 - t0).TotalMilliseconds / (1000f * it)}s"); } }
private void TestH0Gate() { QuantumCircuit qc = new QuantumCircuit(3); System.DateTime t = System.DateTime.Now; qc.Apply(Gates.H(0)); Debug.Log($"H: {(System.DateTime.Now - t).TotalMilliseconds / 1000f}s"); StateVector sv = qc.stateVector; string s = ""; for (int i = 0; i < sv.length; i++) { s += $"[{sv[i].Real:N2} :: {sv[i].Imaginary:N2}i]\n"; } Debug.Log(s); }
private void TestCompare() { QuantumCircuit qc = new QuantumCircuit(24); /* * qc.Apply(RotationGate.H(10)); * Debug.Log(System.DateTime.Now - t); */ System.DateTime t = System.DateTime.Now; /* * //qc = new QuantumCircuit(24); * t = System.DateTime.Now; * for (int j = 0; j < 10; j++) { * qc.Apply(RotationGate.H(j)); * } * Debug.Log($"H: {(System.DateTime.Now - t).TotalMilliseconds / 10000f}s"); */ //qc = new QuantumCircuit(24); t = System.DateTime.Now; for (int j = 0; j < 10; j++) { qc.Apply(new CXGate(j, 0)); } Debug.Log($"CX: {(System.DateTime.Now - t).TotalMilliseconds / 10000f}s"); /* * StateVector sv = qc.stateVector; * * QuantumCircuit qc1 = new QuantumCircuit(1); * * t = System.DateTime.Now; * qc1.RawApply(RotationGate.H(0)); * Debug.Log(System.DateTime.Now - t); * * StateVector sv1 = qc1.stateVector; * * bool equals = true; * for (int i = 0; i < sv1.length; i++) { * equals &= sv[i] == sv1[i]; * } * Debug.Log(equals); */ }