This repository has been archived by the owner on Jun 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from TsvetelinKostadinv/develop/Tsvetelin
Pull request for version 1.2
- Loading branch information
Showing
61 changed files
with
1,976 additions
and
990 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/bin | ||
/test_results | ||
/.settings | ||
/build |
This file contains 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,161 @@ | ||
/* | ||
* 04/03/2020 14:30:17 | ||
* Presenting.java created by Tsvetelin | ||
*/ | ||
package com.presenting; | ||
|
||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
import com.simulationQ.simulation.computation.QCollapser; | ||
import com.simulationQ.simulation.computation.QFinalStateCalculator; | ||
import com.simulationQ.simulation.computation.gates.QGate; | ||
import com.simulationQ.simulation.computation.gates.impl.Hadamard; | ||
import com.simulationQ.simulation.computation.gates.impl.NOT; | ||
import com.simulationQ.simulation.computation.gates.impl.PauliY; | ||
import com.simulationQ.simulation.computation.gates.impl.PauliZ; | ||
import com.simulationQ.simulation.computation.program.QProgram; | ||
import com.simulationQ.simulation.computation.qubits.Qubit; | ||
import com.simulationQ.simulation.computation.qubits.register.CRegister; | ||
import com.simulationQ.simulation.computation.qubits.register.QRegister; | ||
|
||
|
||
/** | ||
* @author Tsvetelin | ||
* | ||
*/ | ||
public abstract class Presenting | ||
{ | ||
|
||
// äîïóñòèìè ñèìâîëè 1 è 0 | ||
// çà âñè÷êè îñòàíàëè íåäîïóñòèìè ñèìâîëè ñå ãåíåðèðà ãðåøêà | ||
|
||
public static final String REGISTER = "010"; | ||
|
||
|
||
|
||
// äîïóñòèìè ñèìâîëè H, X, Y, Z | ||
// ðàçñòîÿíèÿ è äîëíè ÷åðòè ñå èãíîðèðàò, | ||
// çà âñè÷êè îñòàíàëè íåäîïóñòèìè ñèìâîëè ñå ãåíåðèðà ãðåøêà | ||
|
||
public static final String [] PROGRAM = new String[] { | ||
"", | ||
"", | ||
"" | ||
}; | ||
|
||
|
||
public static final long COLLAPSES = 1_000_000L; | ||
|
||
/** | ||
* @param args | ||
*/ | ||
public static void main ( String [] args ) | ||
{ | ||
final QRegister register = new QRegister( parseRegister() ); | ||
System.out.println( "Start: " + register ); | ||
|
||
final QProgram program = new QProgram(); | ||
|
||
final QGate [] [] gates = parseProgram(); | ||
|
||
for ( int index = 0 ; index < gates.length ; index++ ) | ||
{ | ||
for ( int j = 0 ; j < gates[index].length ; j++ ) | ||
{ | ||
program.addPart( gates[index][j] , index ); | ||
} | ||
} | ||
|
||
final QRegister finalState = QFinalStateCalculator.calculateFinalState( program , register ); | ||
System.out.println( "Final state: " + finalState ); | ||
|
||
long start = System.currentTimeMillis(); | ||
|
||
final CRegister result = QCollapser.collapse( finalState , COLLAPSES ); | ||
|
||
long end = System.currentTimeMillis(); | ||
|
||
System.out.println( "Result(after "+COLLAPSES+" collapses) : " + result ); | ||
System.out.println( "Took: " + (end-start) + "ms" ); | ||
|
||
} | ||
|
||
/** | ||
* @return | ||
*/ | ||
private static final QGate [] [] parseProgram () | ||
{ | ||
final String registerAndProgramNotTheSameSizeMessage = "Ðàçìåðíîñòòà íà ðåãèñòúðúò è íà ïúðâîòî èçìåðåíèå íà ïðîãðàìàòà òðÿáâà äà ñúâïàäàò"; | ||
final String unexpectedSymbolMessage = "Íåäîïóñòèì ñèìâîë íà ðåä %s - %s"; | ||
if ( PROGRAM.length != REGISTER.length() ) | ||
throw new IllegalArgumentException( registerAndProgramNotTheSameSizeMessage ); | ||
|
||
List< QGate [] > programRows = new LinkedList<>(); | ||
|
||
for ( String row : PROGRAM ) | ||
{ | ||
List< QGate > currentRow = new LinkedList<>(); | ||
for ( char symbol : row.toCharArray() ) | ||
{ | ||
switch ( symbol ) | ||
{ | ||
case 'H' : | ||
case 'h' : | ||
currentRow.add( new Hadamard() ); | ||
break; | ||
case 'X' : | ||
case 'x' : | ||
currentRow.add( new NOT() ); | ||
break; | ||
case 'Y' : | ||
case 'y' : | ||
currentRow.add( new PauliY() ); | ||
break; | ||
case 'Z' : | ||
case 'z' : | ||
currentRow.add( new PauliZ() ); | ||
break; | ||
case ' ' : | ||
case '_' : | ||
break; | ||
default : | ||
throw new IllegalArgumentException( String.format( unexpectedSymbolMessage , | ||
row , | ||
symbol ) ); | ||
} | ||
} | ||
programRows.add( currentRow.toArray( new QGate[currentRow.size()] ) ); | ||
} | ||
|
||
return programRows.toArray( new QGate[programRows.size()][] ); | ||
|
||
} | ||
|
||
/** | ||
* @return | ||
*/ | ||
private static final Qubit [] parseRegister () | ||
{ | ||
final String unexpectedSymbolMessage = "Ðåãèñòúðúò òðÿáâà äà ñúäúðæà ñàìî ñèìâîëè 1 èëè 0"; | ||
|
||
final List< Qubit > reg = new LinkedList< Qubit >(); | ||
for ( char bit : REGISTER.toCharArray() ) | ||
{ | ||
switch ( bit ) | ||
{ | ||
case '0' : | ||
reg.add( Qubit.QUBIT_OFF ); | ||
break; | ||
case '1' : | ||
reg.add( Qubit.QUBIT_ON ); | ||
break; | ||
default : | ||
throw new IllegalArgumentException( unexpectedSymbolMessage ); | ||
} | ||
} | ||
return reg.toArray( new Qubit[reg.size()] ); | ||
} | ||
|
||
} |
4 changes: 2 additions & 2 deletions
4
...om/simulationQ/gui/icon/package-info.java → ...ain/java/com/presenting/package-info.java
This file contains 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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
/* | ||
* 27/11/2019 16:31:12 | ||
* 04/03/2020 14:29:53 | ||
* package-info.java created by Tsvetelin | ||
*/ | ||
/** | ||
* @author Tsvetelin | ||
* | ||
*/ | ||
package com.simulationQ.gui.icon; | ||
package com.presenting; |
This file contains 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,49 @@ | ||
/* | ||
* 06/12/2019 09:45:06 | ||
* Engine.java created by Tsvetelin | ||
*/ | ||
package com.simulationQ; | ||
|
||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.Future; | ||
|
||
import com.simulationQ.simulation.computation.qubits.register.QRegister; | ||
|
||
|
||
/** | ||
* @author Tsvetelin | ||
* | ||
*/ | ||
public class Engine implements Closeable | ||
{ | ||
|
||
public static final Engine instance = new Engine(); | ||
|
||
private static final int NEEDED_THREADS = 2; | ||
|
||
private ExecutorService ex; | ||
|
||
/** | ||
* | ||
*/ | ||
private Engine () | ||
{ | ||
this.ex = Executors.newFixedThreadPool( NEEDED_THREADS ); | ||
} | ||
|
||
public Future< QRegister > runSimulation ( SimulationRound round ) | ||
{ | ||
return ex.submit( round::runSimulation ); | ||
} | ||
|
||
@Override | ||
public void close () throws IOException | ||
{ | ||
ex.shutdown(); | ||
} | ||
|
||
} |
This file contains 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 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,38 @@ | ||
/* | ||
* 08/12/2019 13:57:36 | ||
* Mediator.java created by Tsvetelin | ||
*/ | ||
package com.simulationQ; | ||
|
||
|
||
/** | ||
* | ||
* This is the mediator between the GUI and the engine | ||
* | ||
* @author Tsvetelin | ||
* | ||
*/ | ||
public final class Mediator | ||
{ | ||
|
||
public static final Mediator instance = new Mediator(); | ||
|
||
/** | ||
* | ||
*/ | ||
private Mediator () | ||
{} | ||
|
||
// public final Future< QRegister > runSimulation ( final List< QGate > gates , | ||
// final QRegister startState , | ||
// final long rounds ) | ||
// { | ||
// final QRegister finalState = QFinalStateCalculator.calculateFinalState( gates , | ||
// startState ); | ||
// final SimulationRound round = new SimulationRound( finalState , | ||
// rounds ); | ||
// return Engine.instance.runSimulation( round ); | ||
// } | ||
|
||
|
||
} |
Oops, something went wrong.