Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2 from TsvetelinKostadinv/develop/Tsvetelin
Browse files Browse the repository at this point in the history
Pull request for version 1.2
  • Loading branch information
TsvetelinKostadinv authored Mar 4, 2020
2 parents 613c7f4 + 8a4f85a commit 7cd6e94
Show file tree
Hide file tree
Showing 61 changed files with 1,976 additions and 990 deletions.
2 changes: 1 addition & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</attributes>
</classpathentry>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/openjdk-13">
<attributes>
<attribute name="module" value="true"/>
</attributes>
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/bin
/test_results
/.settings
/build
161 changes: 161 additions & 0 deletions src/main/java/com/presenting/Presenting.java
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()] );
}

}
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;
49 changes: 49 additions & 0 deletions src/main/java/com/simulationQ/Engine.java
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();
}

}
43 changes: 38 additions & 5 deletions src/main/java/com/simulationQ/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/
package com.simulationQ;

import com.simulationQ.gui.MainWindow;

/**
* @author Tsvetelin
Expand All @@ -19,14 +18,48 @@ public class Main
public Main ()
{}

/**
*
* @param args
* @throws Exception
*/
public static void main ( String [] args ) throws Exception
{

try
{
switch ( args[0] )
{
case "gui" :
startInGUIMode( args );
break;
case "nogui" :
startInNOGUIMode( args );
break;
default :
System.out.println( "Unexpected command: " + args[0] );
}
} catch ( IndexOutOfBoundsException e )
{
System.out.println( "You must specify the mode first - gui/nogui" );
}
}

/**
* @param args
*/
private static void startInGUIMode ( String [] args )
{
System.out.println( "String GUI" );

}

/**
* @param args
*/
public static void main ( String [] args )
private static void startInNOGUIMode ( String [] args )
{
Thread main = new Thread( new MainWindow() );

main.start();
System.out.println( "String NOGUI" );
}

}
38 changes: 38 additions & 0 deletions src/main/java/com/simulationQ/Mediator.java
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 );
// }


}
Loading

0 comments on commit 7cd6e94

Please sign in to comment.