Chris Pollett > Students > Yunxuan

    Print View

    [Bio]

    [Blog]

    [First Proposal]

    [Final Step of Shor's and Grover's Algorithms]

    [jQuantum QFT]

    [My Quantum Circuits]

    [Three Models]

    [Threshold of Error Correction]

    [jQuantum Manual]

    [Quantum State and LH]

    [QHC Scientists]

    [LH and Tensor Networks]

    [k-LH is QMA-complete]

    [Deutch Josza Algorithm]

    [Semester Report]

    [Second Proposal]

    [SolveQ Algorithm: 2-SAT]

    [Random-kSAT-Generator: Version 1]

    [Freezing Point Experiment]

    [Random-kQSAT-Generator: Version 2]

    [Random-kQSAT-Generator: Version 3]

    [Antiferromagnetic Heisenberg Model]

    [Ising Model]

    [Random-kQSAT-Generator: Version 4]

    [Random-kQSAT-Generator: Version 5]

    [Random-kQSAT-Generator: Version 6]

    [SolveQ Algorithm: 2-QSAT]

    [Thesis]

























This program goes along with Antiferromagnetic Heisenberg Model. It is a simulation of the Ising Model. Currently it only tells you whether there are any null vectors found: answer is no. But eventually, it will tell you if there are any eigen vectors with with small eigenvalues. Again, I will update this page when I am done.

Update 1:
I added methods for finding determinants. This is how I envision, I will test for eigenvalues less than the threshold: test to see if the determinant is close enough to 0.
The code below crashes due to large matrix size!!!!
import java.io.*;

import static java.lang.Math.*;

import java.util.*;

public class IsingModel {
	private int clausesize = 2;
	private int numvariable = 5; //crashes for more than 5
	// numvariable is number of atoms other than the "central atom." so it's total minus one.
	private int numclause = 3; //crashes for more than 3
	private int numinstances = 5;//crashes for more than 5
	private int success= 0;
	private int counter=0;
	private double j_constant = 0.5;
	private double g_constant = 0.35;
	private double threshold = 0.66; //12/9*0.5
	private int counter3=0;
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		IsingModel im = new IsingModel();
		im.generate();
	}
	public void generate(){
		ArrayList<Integer>temp = new ArrayList<Integer>();
		ArrayList<ArrayList<Integer>> temp2 = new ArrayList<ArrayList<Integer>>();
		ArrayList<Integer>temp3 = new ArrayList<Integer>();
		ArrayList<ArrayList<Integer>> temp4 = new ArrayList<ArrayList<Integer>>();
		/*for (int k = 0; k<numinstances; k++) {
			for (int j = 0; j<numclause; j++) {
				temp.add(new Integer(0));
				for(int i = 0; i<clausesize-1; i++){
					int a = (int)(Math.random()*numvariable)+1;
					temp.add(new Integer(a));
				}
				temp2.add(temp);
				temp = new ArrayList<Integer>();
			}
			for(int i = 0; i<numclause; i++){
				ArrayList<Integer>temp5 = temp2.get(i);
				temp3.add(temp5.get(1));
			}
			if(Solve(temp2, temp3)){
				success++;
			}
			temp2 = new ArrayList<ArrayList<Integer>>();
			temp3 = new ArrayList<Integer>();
			counter3=0;
		}*/
		//tube
		for(int i=0; i<2; i++) {
			for(int j=0; j<2; j++){
				Integer b= new Integer(i*3+j);
				Integer c= new Integer(i*3+j+1);
				temp.add(b);
				temp.add(c);
				temp2.add(temp);
				temp= new ArrayList<Integer>();
			}
			Integer b= new Integer(i*3);
			Integer c= new Integer(i*3+2);
			temp.add(b);
			temp.add(c);
			temp2.add(temp);
			temp= new ArrayList<Integer>();
		}
		for(int j=0; j<3; j++) {
			for(int i=0; i<1; i++){
				Integer b= new Integer(j+3*i);
				Integer c= new Integer(j+3*(i+1));
				temp.add(b);
				temp.add(c);
				temp2.add(temp);
				temp= new ArrayList<Integer>();
			}
		}
		
		//string
		/*for(int i=0; i<5; i++) {
			Integer b= new Integer(i);
			Integer c= new Integer(i+1);
			temp.add(b);
			temp.add(c);
			temp2.add(temp);
			temp= new ArrayList<Integer>();
		}*/
		//torus: 9 particle
		/*
		 for(int i=0; i<3; i++) {
			for(int j=0; j<2; j++){
				Integer b= new Integer(i*3+j);
				Integer c= new Integer(i*3+j+1);
				temp.add(b);
				temp.add(c);
				temp2.add(temp);
				temp= new ArrayList<Integer>();
			}
			Integer b= new Integer(i*3);
			Integer c= new Integer(i*3+2);
			temp.add(b);
			temp.add(c);
			temp2.add(temp);
			temp= new ArrayList<Integer>();
		}
		 for(int j=0; j<3; j++) {
			for(int i=0; i<2; i++){
				Integer b= new Integer(j+3*i);
				Integer c= new Integer(j+3*(i+1));
				temp.add(b);
				temp.add(c);
				temp2.add(temp);
				temp= new ArrayList<Integer>();
			}
			Integer b= new Integer(j);
			Integer c= new Integer(j+3*2);
			temp.add(b);
			temp.add(c);
			temp2.add(temp);
			temp= new ArrayList<Integer>();
		}*/
		//twist: 9 particle
		/*
		 for(int i=0; i<3; i++) {
			for(int j=0; j<2; j++){
				Integer b= new Integer(i*3+j);
				Integer c= new Integer(i*3+j+1);
				temp.add(b);
				temp.add(c);
				temp2.add(temp);
				temp= new ArrayList<Integer>();
			}
			Integer b= new Integer(i*3);
			Integer c= new Integer(i*3+2);
			temp.add(b);
			temp.add(c);
			temp2.add(temp);
			temp= new ArrayList<Integer>();
		}
		 for(int j=0; j<3; j++) {
			for(int i=0; i<2; i++){
				Integer b= new Integer(j+3*i);
				Integer c= new Integer(j+3*(i+1));
				temp.add(b);
				temp.add(c);
				temp2.add(temp);
				temp= new ArrayList<Integer>();
			}
			Integer b= new Integer(j);
			Integer c= new Integer(3-j-1+3*2);
			temp.add(b);
			temp.add(c);
			temp2.add(temp);
			temp= new ArrayList<Integer>();
		}
		 
		
		/*for(int i=0; i<temp2.size(); i++){
			ArrayList<Integer> list1= temp2.get(i);
			System.out.println(list1.get(0)+" "+list1.get(1));
		}*/
		
		for(int i=0; i<2; i++){
			for(int j=0; j<3; j++){
				temp3.add(new Integer(i*3+j));
			}
		}
		if(Solve(temp2, temp3)) {
			success++;
		}
		System.out.println(success);
	}
	public boolean nullvecExist(boolean [] x){
		for(int i=0; i<x.length; i++){
			if(x[i]==true){
				System.out.print(i+" ");
				counter3++;
			}
		}
		for(int i=0; i<x.length; i++){
			if(x[i]==true){
				return true;
			}
		}
		return false;
	}
	public int zeroCount2 (double[] vec){
		int temp = 0;
		for(int i = 0; i < vec.length; i++){
			if(vec[i]==0){
				temp++;
			} else{
				break;
			}
		}
		return temp;
	}
	public void swaprows(double[][]matrix){
		//int zerocount = 0;
		int max = matrix.length;
		double [] temp;
		int current = 0;
		double ratio = 1;
		boolean found = false;
		
		//current is the line number you have just fixed.  
		//i is all the line numbers that you are working on still.
		//the point of this part is to order rows by increasing zero count.
		/*for(int i=0; i<max; i++){
			System.out.print(zeroCount2(matrix[i])+" ");
		}*/
		current=0;
		int currentCount=0;
		while(current<max){
			for(int i = current; i < max; i++){
				if(zeroCount2(matrix[i]) == currentCount){
					temp = matrix[i];
					matrix[i] = matrix[current];
					matrix[current] = temp;		
					current++;
				}
			}
			currentCount++;
		}
	}
	public void swaprows2 (double [][] matrix, int one, int two){
		double[] temp;
		temp = matrix[one];
		matrix[one] = matrix[two];
		matrix[two] = temp;		
	}
	public boolean [] gaussianElimination(double [][]matrix){
		int max = matrix.length;
		double ratio = 1;
		boolean [] sol= new boolean [max];
		
		swaprows(matrix);
		int ind=0;
		int oldind=ind;
		int count = zeroCount2(matrix[ind]);
		while(ind+1<max){
			int holdon=ind;
			
			//partial pivoting
			for(int i = ind+1; i<max; i++){
				int c = zeroCount2(matrix[i]);
				if(c==count) {
					if(Math.abs(matrix[i][count])>Math.abs(matrix[ind][count]))
						holdon=i;	
				} else if(c>count){
					swaprows2(matrix,holdon,ind);
					break;
				}
			}
			
			for(int i = ind+1; i<max; i++){
				int c = zeroCount2(matrix[i]);
				if(c==count) {
					ratio = matrix[i][count]/matrix[ind][count];
					for(int w = 0; w < matrix.length; w++){
						matrix[i][w]-=matrix[ind][w]*ratio;
					}
				} else if(c>count){
					break;
				}
			}
			swaprows(matrix);
			for(int i=1; i<max; i++){
				if(zeroCount2(matrix[i])==zeroCount2(matrix[i-1])){
					ind=i-1;
					break;
				}
				if(i==max-1){
					ind=max-1;
				}
			}
			
			count=zeroCount2(matrix[ind]);
			if(count==max){
				break;
			}
		}
	
		for(int i=0; i<sol.length; i++){
			sol[i]=true;
		}
		
		for(int i=0; i<matrix.length; i++){
			if(Math.abs(matrix[i][i])>threshold){
				sol[i]=false;
			}
		}
		return sol;
	}
	public boolean Solve(ArrayList<ArrayList<Integer>> temp2, ArrayList<Integer>temp3){
		int max = (int)pow(2,numvariable+1);
		double [] alpha = new double [max];
		boolean [] beta = new boolean[max];
		double[][] one = new double[max][max];
		double [][] two=new double[max][max];
		double[][] three=new double[max][max];
		double[][] Constraint=new double[max][max];
		double[][] Constraint2=new double[max][max];
		boolean success=false;
		int blanckrow=0;
		
		for(int i=0; i<max; i++){
			for(int j=0; j<max; j++){
				Constraint[i][j]=0;
				Constraint2[i][j]=0;
			}
		}
		
		for(int i=0; i<temp3.size(); i++){
			Integer num = temp3.get(i);
			String path= makeString2(num);
			three = makeSig(3, path);
			
			for(int k=0; k<max; k++){
				for(int s=0; s<max; s++){
					Constraint[k][s]+=three[k][s];
				}
			}
		}
		multiplyConst(-1*g_constant, Constraint);
		
		for(int i=0; i<temp2.size(); i++){
			ArrayList<Integer> list = temp2.get(i);
			String path = makeString(list);
			one = makeSig(1,path); //z
			for(int k=0; k<max; k++){
				for(int s=0; s<max; s++){
					Constraint2[k][s]+=one[k][s];
				}
			}
		} 
		multiplyConst(-j_constant, Constraint2);
		
		for(int i=0; i<max; i++){
			for(int j=0; j<max; j++){
				Constraint[i][j]+=Constraint2[i][j];
			}
		}
		/*for(int j = 0; j < Constraint.length; j++){
			for(int k = 0; k < Constraint.length; k++){
				System.out.print(Constraint[j][k]+" ");
				//Constraint[j][k]*=-1;
			}
			System.out.println("");
			//System.out.println(Constraint[j].length);
		}*/
		boolean [] x= gaussianElimination(Constraint);
		System.out.println("");
		System.out.println("");
		System.out.println("");
		System.out.println("");
		System.out.println("");
		for(int j = 0; j < Constraint.length; j++){
			for(int k = 0; k < Constraint.length; k++){
				System.out.print(Constraint[j][k]+" ");
			}
			System.out.println("");
		}
		success = nullvecExist(x);
		return success;

	}
	public void multiplyConst(double c, double[][]mat){
		for(int i=0; i<mat.length; i++){
			for(int j=0; j<mat.length; j++){
				mat[i][j]*=c;
			}
		}
	}
	public int countZero(double[]alpha){
		int count=0;
		for(int i=0; i<alpha.length; i++){
			if(alpha[i]!=0){
				break;
			}
			count++;
		}
		return count;
	}
	public double determinant (double[][] mat){
		if(mat.length==2){
			return( mat[0][0]*mat[1][1]-mat[0][1]*mat[1][0]);
		}
		double det=0;
		for(int i=0; i<mat.length; i++){
			double fac =mat[0][i];
			if(i%2==1){
				fac*=-1;
			}
			det+=fac*determinant(makeSmall(mat,0,i));
		}
		return det;
	}
	public double[][] makeSmall(double[][] mat, int row, int col){
		double [][] temp= new double[mat.length-1][mat.length-1]; 
		int x1=0;
		int x2=0;
		for(int i=0; i<mat.length; i++){
			if(i!=row){
				for(int j=0; j<mat.length; j++){
					if(j!=col){
						//System.out.println(x1+" "+x2);
						temp[x1][x2]=mat[i][j];
						x2++;
					}
				}
				x2=0;
				x1++;
			}
		}
		//System.out.println(x1+" "+x2);
		return temp;
	}
	public double[][] makeSig (int type, String path){

		char next;
		double a0, a1, a2, a3;
		double[][]ul,ur,ll,lr;
		double [][] orig = new double[2][2];
		if(path.charAt(path.length()-1)=='I'){
			orig[0][0]=1;
			orig[0][1]=0;
			orig[1][0]=0;
			orig[1][1]=1;
		}else {
			if(type==1){
				orig[0][0]=1;
				orig[0][1]=0;
				orig[1][0]=0;
				orig[1][1]=-1;
			}else if(type==2){
				orig[0][0]=0;
				orig[0][1]=-1;
				orig[1][0]=1;
				orig[1][1]=0;
			}else {
				orig[0][0]=0;
				orig[0][1]=1;
				orig[1][0]=1;
				orig[1][1]=0;
			}
		}
		for(int i=path.length()-2; i>=0; i--){
			next = path.charAt(i);
			if(next=='I'){
				a0=1;
				a1=0;
				a2=0;
				a3=1;
			}else {
				if(type==1){//z
					a0=1;
					a1=0;
					a2=0;
					a3=-1;
				}else if(type==2){//y
					a0=0;
					a1=-1;
					a2=1;
					a3=0;
				}else {//x
					a0=0;
					a1=1;
					a2=1;
					a3=0;
				}
			}
			ul=multiply(a0, clone(orig));
			ur=multiply(a1, clone(orig));
			ll=multiply(a2, clone(orig));
			lr=multiply(a3, clone(orig));
			orig=makeLarge(ul, ur, ll, lr);
		}
		
		return orig;
	}
	public double[][] clone(double[][] mat){
		double [][]temp = new double[mat.length][mat.length];
		for (int i=0; i<mat.length; i++){
			for(int j=0; j<mat[0].length; j++){
				temp[i][j]=mat[i][j];
			}
		}
		return temp;
	}
	public double[][] multiply(double c, double[][] mat){
		double [][] temp = new double[mat.length][mat.length];
		for (int i=0; i<mat.length; i++){
			for (int j=0; j<mat[0].length; j++){
				temp[i][j]= c*mat[i][j];
			}
		}
		return temp;
	}
	public double[][] makeLarge(double[][] ul, double[][] ur, double[][] ll, double[][]lr){
		double [][] temp = new double[ul.length*2][ul.length*2];
		for(int i =0; i<ul.length; i++){
			for(int j=0; j<ul.length; j++){
				temp[i][j]=ul[i][j];
			}
		}
		for(int i =0; i<ul.length; i++){
			for(int j=0; j<ul.length; j++){
				temp[i][j+ul.length]=ur[i][j];
			}
		}
		for(int i =0; i<ul.length; i++){
			for(int j=0; j<ul.length; j++){
				temp[i+ul.length][j]=ll[i][j];
			}
		}
		for(int i =0; i<ul.length; i++){
			for(int j=0; j<ul.length; j++){
				temp[i+ul.length][j+ul.length]=lr[i][j];
			}
		}
		return temp;
	}
	public String makeString(ArrayList<Integer> list){
		String str="";
		int a = Integer.parseInt(""+list.get(0));
		int b = Integer.parseInt(""+list.get(1));
		for(int i=0; i<numvariable+1; i++){
			if(i!=a && i!=b){
				str="I"+str;
			}else {
				str="S"+str;
			}
		}
		return str;
	}
	public String makeString2(Integer a){
		String str="";
		int a1 = Integer.parseInt(""+a);
		for(int i=0; i<numvariable+1; i++){
			if(i!=a1){
				str="I"+str;
			}else {
				str="S"+str;
			}
		}
		return str;
	}
}