ernst

Easy and efficient 2D spin glass simulation for quantum annealing

https://github.com/brurucy/ernst

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (7.3%) to scientific vocabulary
Last synced: 6 months ago · JSON representation ·

Repository

Easy and efficient 2D spin glass simulation for quantum annealing

Basic Info
  • Host: GitHub
  • Owner: brurucy
  • License: other
  • Language: Rust
  • Default Branch: master
  • Homepage:
  • Size: 21.5 KB
Statistics
  • Stars: 11
  • Watchers: 2
  • Forks: 1
  • Open Issues: 1
  • Releases: 1
Created almost 2 years ago · Last pushed almost 2 years ago
Metadata Files
Readme Changelog License Citation

README.md

Ernst: 2D Spin Glass Simulation for quantum annealing

Crates.io docs

Quantum Annealing is an interesting way to leverage physical quantum effects to solve NP-hard problems. It relies on encoding problems as a single 2-dimensional Spin Glass, such that its degenerate ground states will map one-to-one to the solutions being sought.

The raison d'etre of this library is to make it easy for you to create spin glasses, simulate them, and then send them over to a quantum annealer.

Functionality

With Ernst you can:

  1. Incrementally build a 2D spin glass with the extensible SpinNetwork struct, alongside a library of pre-built logic gates
  2. Find its exact ground states with find_all_ground_states (only recommended if the number of spins is < 48)
  3. Efficiently seek for ground states (with history) of potentially very large spin networks with run_simulated_annealing
  4. Get the h and J components of the SpinNetwork hamiltonian to send to D-wave

Here is an example: ```rust use ernst::spinnetwork::SpinNetwork; use ernst::types::{ExternalMagneticField, Interactions}; use std::time::Instant; use ernst::nodelib::logicgates::OR;

fn main() { let someh: 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 somej: 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);
}

} ```

Implementation

This library is optimized for incremental computation on a CPU. It does not make use of a linear algebra library. Its source of efficiency lies in cleverly doing incremental adjustments to the energy calculation with a Fenwick Tree.

Why is it called Ernst?

The energy of a spin glass configuration is often computed according to the hamiltonian of a well-known statistical mechanics model, the Ising Model, which is named after Ernst Ising.

Roadmap

  1. Parallel tempering
  2. Bayesian Optimisation

Ernst for commercial projects

Are you interested in using Ernst for a commercial quantum optimization project? Then hit me up at @protonmail.ch

Ernst for research

If you find this project useful for your research, you may cite it as follows:

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

Additionally, you may consider adding a star to the repository. This positive feedback improves the visibility of the project.

Owner

  • Name: Bruno Rucy Carneiro Alves de Lima
  • Login: brurucy
  • Kind: user
  • Location: Tartu

🧙

Citation (CITATION.cff)

# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!

cff-version: 1.2.0
title: 'Ernst: 2D Spin Glass Simulation'
message: >-
  If you use this software, please cite it using the
  metadata from this file.
type: software
authors:
  - given-names: Bruno Rucy
    family-names: Carneiro Alves de Lima
    email: <github-username>@protonmail.ch
repository-code: 'https://github.com/brurucy/ernst'
license: GPL-3.0

GitHub Events

Total
  • Watch event: 3
Last Year
  • Watch event: 3

Packages

  • Total packages: 1
  • Total downloads:
    • cargo 1,418 total
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 1
  • Total maintainers: 1
crates.io: ernst

Ernst: 2D Spin Glass Simulation for quantum annealing

  • Documentation: https://docs.rs/ernst/
  • License: GPL-3.0-only
  • Latest release: 0.1.0
    published almost 2 years ago
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 1,418 Total
Rankings
Dependent repos count: 28.5%
Dependent packages count: 33.6%
Average: 52.9%
Downloads: 96.6%
Maintainers (1)
Last synced: 6 months ago

Dependencies

Cargo.lock cargo
  • ahash 0.8.11
  • autocfg 1.1.0
  • cfg-if 1.0.0
  • equivalent 1.0.1
  • fixedbitset 0.5.1
  • ftree 1.0.1
  • getrandom 0.2.12
  • hashbrown 0.14.3
  • indexmap 2.2.5
  • libc 0.2.153
  • num-traits 0.2.18
  • once_cell 1.19.0
  • ordered-float 4.2.0
  • ppv-lite86 0.2.17
  • proc-macro2 1.0.79
  • quote 1.0.35
  • rand 0.8.5
  • rand_chacha 0.3.1
  • rand_core 0.6.4
  • syn 2.0.53
  • unicode-ident 1.0.12
  • version_check 0.9.4
  • wasi 0.11.0+wasi-snapshot-preview1
  • zerocopy 0.7.32
  • zerocopy-derive 0.7.32
Cargo.toml cargo