Skip to content

Commit

Permalink
add the run target and small refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
tjira committed Dec 25, 2024
1 parent a67d351 commit 39fbb93
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 50 deletions.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
/*.dot*
/*.jso*
/*.mat*
/*.out*
/*.pdf*
/*.xyz*

docs/**/*.loc*
docs/**/*.pdf*

research/fssh_vs_lzsh/*.jso*
research/fssh_vs_lzsh/*.mat*
research/fssh_vs_lzsh/*.png*

research/uracil_lvc/*.mat*
research/uracil_lvc/*.png*

*zig*/
*pyt*/
*sit*/
*tex*/
File renamed without changes.
9 changes: 2 additions & 7 deletions .github/README.md → README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
·
<a href="https://github.com/tjira/acorn#examples">Examples</a>
·
<a href="https://github.com/tjira/acorn#credits">Credits</a>
·
<a href="https://tjira.github.io/acorn/">Docs</a>
</h4>

Expand All @@ -22,13 +20,10 @@
<a href="https://github.com/tjira/acorn/actions/workflows/test.yml">
<img src="https://img.shields.io/github/actions/workflow/status/tjira/acorn/test.yml?style=for-the-badge&label=test"/>
</a>
<a href="https://app.codecov.io/gh/tjira/acorn">
<img src="https://img.shields.io/codecov/c/github/tjira/acorn?style=for-the-badge"/>
</a>
<br>
<a href="https://github.com/tjira/acorn/stargazers">
<img src="https://img.shields.io/github/stars/tjira/acorn?style=for-the-badge"/>
</a>
<br>
<a href="https://github.com/tjira/acorn">
<img src="https://img.shields.io/github/languages/code-size/tjira/acorn?style=for-the-badge"/>
</a>
Expand All @@ -51,7 +46,7 @@ Below are all the important features of Acorn divided into categories.
### Quantum Mechanical Methods

* Numerically Exact Adiabatic & Nonadiabatic Quantum Dynamics with Arbitrary Number of States & Dimensions
* Restricted Hartree–Fock, Møller–Plesset Perturbation Theory & Configuration Interaction Methods
* Restricted Hartree–Fock Method, Møller–Plesset Perturbation Theory & Configuration Interaction Methods

## Compilation

Expand Down
11 changes: 10 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const std = @import("std");
const std = @import("std"); const builtin = @import("builtin");

const targets: []const std.Target.Query = &.{
.{.os_tag = .linux , .cpu_arch = .aarch64},
.{.os_tag = .linux , .cpu_arch = .arm },
.{.os_tag = .linux , .cpu_arch = .riscv64},
.{.os_tag = .linux , .cpu_arch = .x86 },
.{.os_tag = .linux , .cpu_arch = .x86_64 },
.{.os_tag = .windows, .cpu_arch = .aarch64},
.{.os_tag = .windows, .cpu_arch = .x86 },
.{.os_tag = .windows, .cpu_arch = .x86_64 },
.{.os_tag = .macos , .cpu_arch = .aarch64},
.{.os_tag = .macos , .cpu_arch = .x86_64 },
Expand All @@ -30,6 +32,13 @@ pub fn build(builder: *std.Build) !void {
});

builder.getInstallStep().dependOn(&output.step);

if (builtin.target.cpu.arch == target.cpu_arch and builtin.target.os.tag == target.os_tag) {

const run_executable = builder.addRunArtifact(main_executable);

builder.step("run", "Run the executable").dependOn(&run_executable.step);
}
}

const test_executable = builder.addTest(.{
Expand Down
6 changes: 0 additions & 6 deletions docs/.gitignore

This file was deleted.

1 change: 1 addition & 0 deletions docs/Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
source "https://rubygems.org"

gem "erb"
gem "jekyll-include-cache"
gem "jekyll-remote-theme"
gem "jekyll-seo-tag"
Expand Down
3 changes: 0 additions & 3 deletions research/fssh_vs_lzsh/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions research/uracil_lvc/.gitignore

This file was deleted.

75 changes: 44 additions & 31 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,61 +16,74 @@ pub const Matrix = @import("matrix.zig").Matrix;
pub const Tensor = @import("tensor.zig").Tensor;
pub const Vector = @import("vector.zig").Vector;

pub fn main() !void {
var timer = try std.time.Timer.start(); var args = try std.process.argsWithAllocator(allocator); defer args.deinit();
pub fn parse(filebuf: []const u8) !void {
const inputjs = try std.json.parseFromSlice(std.json.Value, allocator, filebuf, .{}); defer inputjs.deinit();

try std.io.getStdOut().writer().print("ZIG VERSION: {}\n", .{builtin.zig_version});
if (inputjs.value.object.contains("hartree_fock")) {

_ = args.next(); while (args.next()) |arg| {
const obj = try std.json.parseFromValue(hfm.HartreeFockOptions(f64), allocator, inputjs.value.object.get("hartree_fock").?, .{}); defer obj.deinit();

const filebuf = try std.fs.cwd().readFileAlloc(allocator, arg, fsize); defer allocator.free(filebuf);
const output = try hfm.run(f64, obj.value, true, allocator); defer output.deinit();
}

const inputjs = try std.json.parseFromSlice(std.json.Value, allocator, filebuf, .{}); defer inputjs.deinit();
if (inputjs.value.object.contains("moller_plesset")) {

try std.io.getStdOut().writer().print("\nPROCESSED FILE: {s}\n", .{arg});
const obj = try std.json.parseFromValue(mpm.MollerPlessetOptions(f64), allocator, inputjs.value.object.get("moller_plesset").?, .{}); defer obj.deinit();

if (inputjs.value.object.contains("hartree_fock")) {
const output = try mpm.run(f64, obj.value, true, allocator); defer output.deinit();
}

const obj = try std.json.parseFromValue(hfm.HartreeFockOptions(f64), allocator, inputjs.value.object.get("hartree_fock").?, .{}); defer obj.deinit();
if (inputjs.value.object.contains("configuration_interaction")) {

const output = try hfm.run(f64, obj.value, true, allocator); defer output.deinit();
}
const obj = try std.json.parseFromValue(cim.ConfigurationInteractionOptions(f64), allocator, inputjs.value.object.get("configuration_interaction").?, .{}); defer obj.deinit();

if (inputjs.value.object.contains("moller_plesset")) {
const output = try cim.run(f64, obj.value, true, allocator); defer output.deinit();
}

const obj = try std.json.parseFromValue(mpm.MollerPlessetOptions(f64), allocator, inputjs.value.object.get("moller_plesset").?, .{}); defer obj.deinit();
if (inputjs.value.object.contains("classical_dynamics")) {

const output = try mpm.run(f64, obj.value, true, allocator); defer output.deinit();
}
const obj = try std.json.parseFromValue(cdn.ClassicalDynamicsOptions(f64), allocator, inputjs.value.object.get("classical_dynamics").?, .{}); defer obj.deinit();

if (inputjs.value.object.contains("configuration_interaction")) {
const output = try cdn.run(f64, obj.value, true, allocator); defer output.deinit();
}

const obj = try std.json.parseFromValue(cim.ConfigurationInteractionOptions(f64), allocator, inputjs.value.object.get("configuration_interaction").?, .{}); defer obj.deinit();
if (inputjs.value.object.contains("quantum_dynamics")) {

const output = try cim.run(f64, obj.value, true, allocator); defer output.deinit();
}
const obj = try std.json.parseFromValue(qdn.QuantumDynamicsOptions(f64), allocator, inputjs.value.object.get("quantum_dynamics").?, .{}); defer obj.deinit();

const output = try qdn.run(f64, obj.value, true, allocator); defer output.deinit();
}

if (inputjs.value.object.contains("classical_dynamics")) {
if (inputjs.value.object.contains("model_potential")) {

const obj = try std.json.parseFromValue(cdn.ClassicalDynamicsOptions(f64), allocator, inputjs.value.object.get("classical_dynamics").?, .{}); defer obj.deinit();
const obj = try std.json.parseFromValue(mpt.ModelPotentialOptions(f64), allocator, inputjs.value.object.get("model_potential").?, .{}); defer obj.deinit();

const output = try cdn.run(f64, obj.value, true, allocator); defer output.deinit();
}
try mpt.write(f64, obj.value, allocator);
}
}

if (inputjs.value.object.contains("quantum_dynamics")) {
pub fn main() !void {
var timer = try std.time.Timer.start(); var argv = try std.process.argsWithAllocator(allocator); defer argv.deinit(); var argc: usize = 0;

const obj = try std.json.parseFromValue(qdn.QuantumDynamicsOptions(f64), allocator, inputjs.value.object.get("quantum_dynamics").?, .{}); defer obj.deinit();
try std.io.getStdOut().writer().print("ZIG VERSION: {}\n", .{builtin.zig_version});

const output = try qdn.run(f64, obj.value, true, allocator); defer output.deinit();
}
_ = argv.next(); while (argv.next()) |arg| {

if (inputjs.value.object.contains("model_potential")) {
try std.io.getStdOut().writer().print("\nPROCESSED FILE: {s}\n", .{arg});

const obj = try std.json.parseFromValue(mpt.ModelPotentialOptions(f64), allocator, inputjs.value.object.get("model_potential").?, .{}); defer obj.deinit();
const filebuf = try std.fs.cwd().readFileAlloc(allocator, arg, fsize); defer allocator.free(filebuf);

try mpt.write(f64, obj.value, allocator);
}
try parse(filebuf); argc += 1;
}

default: {if (argc == 0) {

const filebuf = std.fs.cwd().readFileAlloc(allocator, "input.json", fsize) catch break :default;

try std.io.getStdOut().writer().print("\nPROCESSED FILE: {s}\n", .{"input.json"});

try parse(filebuf); allocator.free(filebuf);
}}

std.debug.print("\nTOTAL EXECUTION TIME: {}\n", .{std.fmt.fmtDuration(timer.read())});
}
7 changes: 7 additions & 0 deletions src/modelpotential.zig
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub fn dims(potential: []const u8) !u32 {
if (std.mem.eql(u8, potential, "harmonic1D_1")) return 1;
if (std.mem.eql(u8, potential, "harmonic2D_1")) return 2;
if (std.mem.eql(u8, potential, "harmonic3D_1")) return 3;
if (std.mem.eql(u8, potential, "harmonic4D_1")) return 4;
if (std.mem.eql(u8, potential, "doubleState1D_1")) return 1;
if (std.mem.eql(u8, potential, "doubleState1D_2")) return 1;
if (std.mem.eql(u8, potential, "tripleState1D_1")) return 1;
Expand All @@ -45,6 +46,7 @@ pub fn eval(comptime T: type, U: *Matrix(T), potential: []const u8, r: Vector(T)
if (std.mem.eql(u8, potential, "harmonic1D_1")) return harmonic1D_1(T, U, r);
if (std.mem.eql(u8, potential, "harmonic2D_1")) return harmonic2D_1(T, U, r);
if (std.mem.eql(u8, potential, "harmonic3D_1")) return harmonic3D_1(T, U, r);
if (std.mem.eql(u8, potential, "harmonic4D_1")) return harmonic4D_1(T, U, r);
if (std.mem.eql(u8, potential, "doubleState1D_1")) return doubleState1D_1(T, U, r);
if (std.mem.eql(u8, potential, "doubleState1D_2")) return doubleState1D_2(T, U, r);
if (std.mem.eql(u8, potential, "tripleState1D_1")) return tripleState1D_1(T, U, r);
Expand All @@ -63,6 +65,7 @@ pub fn states(potential: []const u8) !u32 {
if (std.mem.eql(u8, potential, "harmonic1D_1")) return 1;
if (std.mem.eql(u8, potential, "harmonic2D_1")) return 1;
if (std.mem.eql(u8, potential, "harmonic3D_1")) return 1;
if (std.mem.eql(u8, potential, "harmonic4D_1")) return 1;
if (std.mem.eql(u8, potential, "doubleState1D_1")) return 2;
if (std.mem.eql(u8, potential, "doubleState1D_2")) return 2;
if (std.mem.eql(u8, potential, "tripleState1D_1")) return 3;
Expand All @@ -89,6 +92,10 @@ pub fn harmonic3D_1(comptime T: type, U: *Matrix(T), r: Vector(T)) !void {
U.ptr(0, 0).* = 0.5 * (r.at(0) * r.at(0) + r.at(1) * r.at(1) + r.at(2) * r.at(2));
}

pub fn harmonic4D_1(comptime T: type, U: *Matrix(T), r: Vector(T)) !void {
U.ptr(0, 0).* = 0.5 * (r.at(0) * r.at(0) + r.at(1) * r.at(1) + r.at(2) * r.at(2) + r.at(3) * r.at(3));
}

pub fn doubleState1D_1(comptime T: type, U: *Matrix(T), r: Vector(T)) !void {
U.ptr(0, 0).* = 0.001 * r.at(0);
U.ptr(0, 1).* = 0.001 * std.math.exp(-0.05 * r.at(0) * r.at(0));
Expand Down

0 comments on commit 39fbb93

Please sign in to comment.