예제 #1
0
func main() {
	t := table.NewOutTable("Time Step", "C Correlation", "X Correlation")

	info := &ising.SweepInfo{
		ising.New(ising.Grid2DType, widthPow),
		ising.RandomSweep,
		mcrand.New(mcrand.GoCrypto, int64(time.Now().UnixNano())),
		temp,
	}

	stats := ising.SweepStatistics(info, initialSweeps, trials)

	fCs, _ := ising.Tau(stats.EHistory)
	fMags, _ := ising.Tau(stats.MagHistory)

	if len(fCs) < len(fMags) {
		for 0 < len(fMags)-len(fCs) {
			fCs = append(fCs, 0.0)
		}
	} else {
		for 0 < len(fCs)-len(fMags) {
			fMags = append(fMags, 0.0)
		}
	}

	info.Im.Print()

	println("Total steps:", len(fMags))

	for i := 0; i < len(fMags); i++ {
		t.AddRow(float64(i), fCs[i], fMags[i])
	}

	t.Write(table.KeepHeader, "tau.table")
}
예제 #2
0
func BenchmarkIterateSweep8(b *testing.B) {
	im := New(Grid2DType, 3)
	b.ResetTimer()
	info := &SweepInfo{
		im,
		IterSweep,
		mcrand.New(mcrand.GoRand, 0),
		testTemp,
	}
	Sweep(info, b.N)
}
예제 #3
0
func BenchmarkRandomSweep64(b *testing.B) {
	im := New(Grid2DType, 6)
	b.ResetTimer()
	info := &SweepInfo{
		im,
		RandomSweep,
		mcrand.New(mcrand.GoRand, 0),
		testTemp,
	}
	Sweep(info, b.N)
}
예제 #4
0
func BenchmarkMultiplyWithCarryGenerator(b *testing.B) {
	im := New(Grid2DType, 5)
	b.ResetTimer()
	info := &SweepInfo{
		im,
		CheckerSweep,
		mcrand.New(mcrand.MultiplyWithCarry, 0),
		testTemp,
	}
	Sweep(info, b.N)
}
예제 #5
0
func BenchmarkXorshiftGenerator(b *testing.B) {
	im := New(Grid2DType, 5)
	b.ResetTimer()
	info := &SweepInfo{
		im,
		CheckerSweep,
		mcrand.New(mcrand.Xorshift, 0),
		testTemp,
	}
	Sweep(info, b.N)
}
예제 #6
0
func BenchmarkCheckerSweep32(b *testing.B) {
	im := New(Grid2DType, 5)
	b.ResetTimer()
	info := &SweepInfo{
		im,
		CheckerSweep,
		mcrand.New(mcrand.GoRand, 0),
		testTemp,
	}
	Sweep(info, b.N)
}
예제 #7
0
func main() {
	fmt.Println("Run statistics:")
	fmt.Printf("  %15s %5d\n", "Grid Width", 1<<widthPow)
	fmt.Printf("  %15s %5d\n", "Initial Sweeps", initialSweeps)
	fmt.Printf("  %15s %5d\n", "Trial Sweeps", trials)
	fmt.Printf("  %15s %5d\n", "Runs", runs)
	fmt.Printf("  %15s %5d\n", "Plot Points", int(points))

	t0 := float64(time.Now().UnixNano())

	infos := make([]*ising.SweepInfo, runs)
	for i := 0; i < runs; i++ {
		infos[i] = &ising.SweepInfo{
			ising.New(ising.Grid2DType, widthPow),
			ising.RandomSweep,
			mcrand.New(mcrand.Xorshift, int64(time.Now().Nanosecond())),
			minTemp,
		}
	}

	t := table.NewOutTable("Temp", "Energy", "Mag", "S. Heat", "Chi")
	stats := make([]*ising.SweepStats, runs)

	print("Running simulation")
	for point := 0.0; point < points; point++ {
		print(".")

		for i, info := range infos {
			info.Temp = minTemp + (maxTemp-minTemp)*point/points
			stats[i] = ising.SweepStatistics(info, initialSweeps, trials)
		}

		stat := ising.AvgSweepStats(stats)

		t.AddRow(infos[0].Temp, stat.E, stat.Mag, stat.C, stat.X)
	}
	println()

	t.Write(table.KeepHeader, fmt.Sprintf("temp%d.table", 1<<widthPow))

	t1 := float64(time.Now().UnixNano())
	fmt.Printf("Run time: %.3gs\n", (t1-t0)/1e9)
}
예제 #8
0
// This is too monolithic and should be pruned.
func main() {
	sampleTemp := minSampleTemp

	maximumTable := table.NewOutTable("L", "1/L",
		"Critical Temperature", "Max Specific Heat", "Max Specific Heat Per Site")
	maximumTable.SetHeader(fmt.Sprintf("Created with %g trials per grid.",
		math.Pow(10, maxTrialsPow)))

	for widthPow := minPow; widthPow <= maxPow; widthPow++ {
		cols := make([]string, 1+2*(maxTrialsPow-minTrialsPow+1))
		cols[0] = "Temperature"

		fcols := make([][]float64, int((maxTemp-minTemp)/tempStep))
		for i := 0; i < len(fcols); i++ {
			fcols[i] = make([]float64, 1+2*(maxTrialsPow-minTrialsPow+1))
		}

		secs1 := 0.0
		secs2 := 0.0

		fmt.Printf("\n%d-Width Grid:\n", 1<<widthPow)
		for i := 0; i <= maxTrialsPow-minTrialsPow; i++ {
			trials := int(math.Pow(10, float64(minTrialsPow+i)))
			fmt.Printf("  Running %d trial suite\n", trials)

			cols[2*i+1] = fmt.Sprintf("E (%d)", trials)
			cols[2*i+2] = fmt.Sprintf("C (%d)", trials)

			info := &ising.SweepInfo{
				ising.New(ising.Grid2DType, uint32(widthPow)),
				ising.IterSweep,
				mcrand.New(mcrand.Xorshift, int64(time.Now().UnixNano())),
				sampleTemp,
			}

			t0 := time.Now().UnixNano()
			ising.SweepStatistics(info, initialSweeps, trials)
			t1 := time.Now().UnixNano()
			secs1 += float64(t1-t0) / 1e9

			h := info.Im.EnergyHistogram()

			minValidTemp, maxValidTemp := maxTemp, minTemp
			for j := 0; j < len(fcols); j++ {
				temp := minTemp + float64(j)*tempStep

				E := h.Energy(sampleTemp, temp)
				C := h.SpecificHeat(sampleTemp, temp)

				if !math.IsNaN(C) && !math.IsInf(C, 0) {
					if temp > maxValidTemp {
						maxValidTemp = temp
					}
					if temp < minValidTemp {
						minValidTemp = temp
					}
				}

				fcols[j][2*i+1] = E / float64(info.Im.Sites())
				fcols[j][2*i+2] = C / float64(info.Im.Sites())
			}

			if i+minTrialsPow == maxTrialsPow {
				tCrit := h.CriticalTemp(sampleTemp, minValidTemp, maxValidTemp)
				cCrit := h.SpecificHeat(sampleTemp, tCrit)
				maximumTable.AddRow(float64(int(1<<widthPow)),
					1.0/float64(int(1<<widthPow)), tCrit,
					cCrit, cCrit/float64(info.Im.Sites()))

				sampleTemp = tCrit
			}

			t2 := time.Now().UnixNano()
			secs2 += float64(t2-t1) / 1e9
		}

		headerString := fmt.Sprintf(
			"%16s: %g\n%16s: %d\n%16s: %d\n"+
				"%16s: %s\n%16s: %s\n%16s: %g\n%20s: %g",
			"Sample Temperature", sampleTemp,
			"Initial Sweeps", initialSweeps,
			"Width", 1<<widthPow,
			"Generator", "Xorshift",
			"Sweep Pattern", "IterSweep",
			"Total Sweep Time", secs1,
			"Total Histogram Time", secs2)

		t := table.NewOutTable(cols...)

		t.SetHeader(headerString)

		for i := 0; i < len(fcols); i++ {
			if !math.IsNaN(fcols[i][1]) {
				fcols[i][0] = minTemp + tempStep*float64(i)
				t.AddRow(fcols[i]...)
			}
		}

		t.Write(table.KeepHeader,
			fmt.Sprintf("tables/iter/hist-temp%d.table", 1<<widthPow))
	}

	maximumTable.Write(table.KeepHeader, "tables/iter/hist-maximum.table")
}