#annealing #optimization #ising-model #spin-glass

ernst

Ernst: 量子退火二维自旋玻璃模拟

1 个不稳定版本

0.1.0 2024年3月23日

#192 in 科学

GPL-3.0-only

55KB
965

Ernst: 量子退火二维自旋玻璃模拟

Crates.io docs

量子退火是利用物理量子效应解决NP难问题的一种有趣方式。它依赖于将问题编码为单个二维自旋玻璃,使其简并基态与所寻求的解一一对应。

这个库的目的是让您轻松创建自旋玻璃,模拟它们,然后将它们发送到量子退火器。

功能

使用Ernst,您可以

  1. 使用可扩展的SpinNetwork结构逐步构建二维自旋玻璃,并附带一个预构建的逻辑门库
  2. 使用find_all_ground_states找到其精确基态(仅当自旋数小于48时推荐使用)
  3. 使用run_simulated_annealing高效地寻找可能非常大自旋网络的基态(带历史记录)
  4. 获取SpinNetwork哈密顿量的hJ组件,以发送到D-

以下是一个示例

use ernst::spin_network::SpinNetwork;
use ernst::types::{ExternalMagneticField, Interactions};
use std::time::Instant;
use ernst::nodelib::logic_gates::OR;

fn main() {
    let some_h: ExternalMagneticField = vec![
        5.0, 5.0, 5.0, 0.0, 0.0, 0.0, 0.0, 0.5, 0.5, -1.0, 0.5, 0.5, -1.0, 0.5, 0.5, -1.0, 0.5,
        0.5, -1.0,
    ];
    let some_j: Interactions = vec![
        (0, 7, 1.0),
        (1, 8, 1.0),
        (7, 8, -0.5),
        (7, 9, 1.0),
        (8, 9, 1.0),
        (1, 10, 1.0),
        (2, 11, 1.0),
        (10, 11, -0.5),
        (10, 12, 1.0),
        (11, 12, 1.0),
        (0, 13, 1.0),
        (4, 14, 1.0),
        (13, 14, -0.5),
        (13, 15, 1.0),
        (14, 15, 1.0),
        (3, 16, 1.0),
        (2, 17, 1.0),
        (16, 17, -0.5),
        (16, 18, 1.0),
        (17, 18, 1.0),
        (3, 9, 1.0),
        (4, 12, 1.0),
        (5, 15, 1.0),
        (6, 18, 1.0),
    ];

    let now = Instant::now();
    let exact_ground_states = ernst::solvers::find_all_ground_states(&some_j, &some_h);
    let time_to_compute = now.elapsed().as_millis();
    println!("Complex spin glass ground state - took: {} ms", time_to_compute);
    for ground_state in exact_ground_states {
        println!(
            "\tEnergy: {} - State: {:?}",
            ground_state.0, ground_state.1
        );
    }

    let now = Instant::now();
    let approximate_ground_states = ernst::solvers::simulated_annealing(&some_j, &some_h, None);
    let time_to_compute = now.elapsed().as_millis();
    println!("\nComplex spin glass ground state with simulated annealing - took: {} ms", time_to_compute);
    for ground_state in approximate_ground_states {
        println!(
            "\tEnergy: {} - State: {:?} - Found in sweep number: {}",
            ground_state.0, ground_state.1, ground_state.2
        );
    }

    let mut spin_network = SpinNetwork::new();
    let s0 = spin_network.add_input_node(0.0);
    let s1 = spin_network.add_input_node(0.0);
    let s2 = spin_network.add_input_node(0.0);
    let or_gate = OR::default();
    let z_aux = spin_network.add_binary_node(s0, s1, &or_gate);
    let z = spin_network.add_binary_node(z_aux, s2, &or_gate);

    let interesting_spins = vec![s0, s1, s2, z];
    let ternary_or_ground_states = spin_network.find_all_ground_states(Some(interesting_spins.clone()));
    println!("\nTernary OR spin glass ground states:");
    for ground_state in ternary_or_ground_states {
        println!("\tEnergy: {} - State: {:?}", ground_state.0, ground_state.1);
    }

    let copy_ground_states = spin_network.run_simulated_annealing(None, Some(interesting_spins));
    println!("\nTernary OR spin glass ground states with simulated annealing:");
    for ground_state in copy_ground_states {
        println!("\tEnergy: {} - State: {:?} - Found in sweep number: {}", ground_state.0, ground_state.1, ground_state.2);
    }
}

实现

此库针对CPU上的增量计算进行了优化。它不使用线性代数库。其效率来源是巧妙地对能量计算进行增量调整,使用 Fenwick树

为什么叫Ernst?

自旋玻璃配置的能量通常根据著名的统计力学模型哈密顿量进行计算,即伊辛模型,该模型以Ernst Ising的名字命名。

路线图

  1. 并行退火
  2. 贝叶斯优化

Ernst商业项目

您有兴趣将Ernst用于商业量子优化项目吗?那么请发邮件至@protonmail.ch

Ernst研究

如果您发现这个项目对您的研究有用,您可以按以下方式引用它

@misc{Rucy2024,
  author = {Rucy, B.C.D.L}
  title = {Ernst},
  year = {2024},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/brurucy/ernst}},
}

此外,您可以考虑给仓库加星。这种正面反馈可以提高项目的可见性。

依赖项

~2.5MB
~40K SLoC