LogoLogo
  • JuliaOS Documentation Hub
  • About JuliaOS
    • Mission & Vision
    • Features and Capabilities
    • Roadmap
    • Tokenomics
  • Ecosystem
    • Overview
  • Partners
    • Heurist
    • Fetch.ai
    • Soulgraph
    • cheqd.io
    • Aethir
    • Anyone
    • TensorLabs
    • Hashpower
  • Technology
    • Overview
    • Open Source
      • Modular Framework
      • CLI Mode
    • AI Platform
      • Dashboard
      • Agent Management
      • Swarm Management
      • Marketplace
      • Mining
    • LLM
    • Launchpad
    • Robotics & IOT
      • SwarmIOT
      • Modular AI with Robotics
        • J3OS MiniLLM
          • 🔧 Use Cases
  • Technical
    • Overview
    • Developer Hub
      • Getting Started
        • Installation Guide
          • Github Guide
        • Basic Concepts
        • Quick Start Guide
          • Handling secrets
        • Examples and Use
          • Example: Using the Trading Functionality
          • Example: Using the Benchmarking Feature
          • Example: Multi-Agent Swarm Coordination
          • Example: Using the Python Wrapper for LLM Integration
          • Example: Using Cross-Chain Bridges
          • Example: Creating and Running a Swarm Optimization
          • Page 4
      • Best Practices
        • Performance Tuning
        • Agent/Swarm Design Patterns
        • Best Practices & Patterns
        • Security Best Practices
      • CLI
        • JuliaOS CLI Interface
        • Agent Management (CLI)
        • CLI Configuration
        • Cross-Chain Hub (CLI)
        • Swarm Management (CLI)
        • CLI Troubleshooting
        • Wallet Management (CLI)
      • Framework SDK
        • Modules
          • Bridge
          • Agents Module
          • Dex
          • Swarms Module
          • Wallet
        • Python Wrapper
          • LangChain Integration
          • Python Wrapper
      • Contributing Guide
      • Extending JuliaOS
      • Development Setup & Conventions
      • Testing & Debugging
      • Troubleshooting
    • Architecture
      • High Level JuliaOS
      • CLI <-> Backend Communication
      • Data Storage Architecture
      • Framework Internals
      • Architecture Deep Dive
        • Architectual Notes
    • Concepts
      • Core Features & Concepts
      • Agents
        • Agent Skills & Specializations
      • Swarms
      • Neural Networks
      • Blockchains & Chains
      • Bridges (Cross-Chain)
      • Integrations
        • Google ADK
        • LLMs
        • Price Feed
        • DEX Integration
      • Storage
      • Trading Capabilities
      • Use Cases
      • Wallets
      • Portfolio Optimization
  • Research
    • JuliaOS Research
  • API Documentation
    • API Reference
      • API Reference: Julia Backend Commands
      • API Reference: CLI Commands
      • API Reference: Node.js API
      • API Reference: Python API
      • API Reference
  • Community
    • Community & Support
  • FAQ
    • General
    • Technical
    • Community
Powered by GitBook
On this page
  • Overview
  • Installation
  • Usage
  • Initializing the Swarms Module
  • Creating a Swarm
  • Starting a Swarm
  • Adding Agents to a Swarm
  • Running an Optimization
  • Getting Swarm Status
  • Stopping a Swarm
  • Listing Swarms
  • Removing an Agent from a Swarm
  • Deleting a Swarm
  • Swarm Algorithms
  • Particle Swarm Optimization (PSO)
  • Differential Evolution (DE)
  • Grey Wolf Optimizer (GWO)
  • Ant Colony Optimization (ACO)
  • Genetic Algorithm (GA)
  • Whale Optimization Algorithm (WOA)
  • Hybrid DEPSO
  • Listing Available Algorithms
  • Error Handling
  • See Also
Export as PDF
  1. Technical
  2. Developer Hub
  3. Framework SDK
  4. Modules

Swarms Module

The Swarms module in the JuliaOS framework provides a comprehensive interface for creating, managing, and interacting with swarms. This page explains how to use the Swarms module in your applications.

Overview

The Swarms module connects to the Julia backend through the JuliaBridge and provides methods for creating, retrieving, starting, stopping, and running optimizations with swarms. It also includes various swarm algorithms for different optimization and coordination tasks.

Installation

npm install @juliaos/framework

Usage

Initializing the Swarms Module

import { JuliaBridge } from '@juliaos/julia-bridge';
import { Swarms } from '@juliaos/framework';

// Initialize the bridge
const bridge = new JuliaBridge({ host: 'localhost', port: 8052 });
await bridge.initialize();

// Create the Swarms module
const swarms = new Swarms(bridge);

Creating a Swarm

const swarm = await swarms.createSwarm({
  name: 'MySwarm',
  algorithm: 'PSO',
  config: {
    particles: 30,
    c1: 2.0,
    c2: 2.0,
    w: 0.7,
    dimensions: 10,
    bounds: [[-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10]],
    objective: 'minimize'
  }
});

console.log('Created swarm:', swarm);

Starting a Swarm

await swarms.startSwarm(swarm.id);
console.log('Swarm started');

Adding Agents to a Swarm

// Assuming you have created an agent
await swarms.addAgentToSwarm(swarm.id, agent.id);
console.log('Agent added to swarm');

Running an Optimization

// Define an objective function
const objectiveFunction = 'function(x) return sum(x.^2) end';

// Run the optimization
const result = await swarms.runOptimization(swarm.id, objectiveFunction, [], {
  max_iterations: 100,
  tolerance: 1e-6
});

console.log('Optimization result:', result);

Getting Swarm Status

const status = await swarms.getSwarmStatus(swarm.id);
console.log('Swarm status:', status);

Stopping a Swarm

await swarms.stopSwarm(swarm.id);
console.log('Swarm stopped');

Listing Swarms

const allSwarms = await swarms.listSwarms();
console.log('All swarms:', allSwarms);

Removing an Agent from a Swarm

await swarms.removeAgentFromSwarm(swarm.id, agent.id);
console.log('Agent removed from swarm');

Deleting a Swarm

await swarms.deleteSwarm(swarm.id);
console.log('Swarm deleted');

Swarm Algorithms

The Swarms module supports various swarm intelligence algorithms:

Particle Swarm Optimization (PSO)

const psoSwarm = await swarms.createSwarm({
  name: 'PSOSwarm',
  algorithm: 'PSO',
  config: {
    particles: 30,
    c1: 2.0,
    c2: 2.0,
    w: 0.7,
    dimensions: 10,
    bounds: [[-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10]],
    objective: 'minimize'
  }
});

Differential Evolution (DE)

const deSwarm = await swarms.createSwarm({
  name: 'DESwarm',
  algorithm: 'DE',
  config: {
    population: 50,
    F: 0.8,
    CR: 0.9,
    dimensions: 10,
    bounds: [[-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10]],
    objective: 'minimize'
  }
});

Grey Wolf Optimizer (GWO)

const gwoSwarm = await swarms.createSwarm({
  name: 'GWOSwarm',
  algorithm: 'GWO',
  config: {
    wolves: 30,
    a_start: 2.0,
    a_end: 0.0,
    dimensions: 10,
    bounds: [[-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10]],
    objective: 'minimize'
  }
});

Ant Colony Optimization (ACO)

const acoSwarm = await swarms.createSwarm({
  name: 'ACOSwarm',
  algorithm: 'ACO',
  config: {
    ants: 30,
    alpha: 1.0,
    beta: 2.0,
    rho: 0.5,
    dimensions: 10,
    bounds: [[-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10]],
    objective: 'minimize'
  }
});

Genetic Algorithm (GA)

const gaSwarm = await swarms.createSwarm({
  name: 'GASwarm',
  algorithm: 'GA',
  config: {
    population: 100,
    crossover_rate: 0.8,
    mutation_rate: 0.1,
    dimensions: 10,
    bounds: [[-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10]],
    objective: 'minimize'
  }
});

Whale Optimization Algorithm (WOA)

const woaSwarm = await swarms.createSwarm({
  name: 'WOASwarm',
  algorithm: 'WOA',
  config: {
    whales: 30,
    b: 1.0,
    dimensions: 10,
    bounds: [[-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10]],
    objective: 'minimize'
  }
});

Hybrid DEPSO

const depsoSwarm = await swarms.createSwarm({
  name: 'DEPSOSwarm',
  algorithm: 'DEPSO',
  config: {
    population: 50,
    F: 0.8,
    CR: 0.9,
    w: 0.7,
    c1: 1.5,
    c2: 1.5,
    hybrid_ratio: 0.5,
    adaptive: true,
    dimensions: 10,
    bounds: [[-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10], [-10, 10]],
    objective: 'minimize'
  }
});

Listing Available Algorithms

const algorithms = await swarms.listAlgorithms();
console.log('Available algorithms:', algorithms);

Error Handling

The Swarms module includes robust error handling:

try {
  const swarm = await swarms.createSwarm({
    name: 'MySwarm',
    algorithm: 'PSO',
    config: { /* ... */ }
  });
} catch (error) {
  console.error('Failed to create swarm:', error);
}

See Also

  • Agents Module - Learn about agents and how to use them with swarms

  • Bridge Module - Learn about the bridge that connects to the Julia backend

  • Algorithms - Learn more about the swarm algorithms

PreviousDexNextWallet