-
Notifications
You must be signed in to change notification settings - Fork 1
Implement Financial Chart of Accounts as Virtual Hardware Architecture for LLM Simulation #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Financial Chart of Accounts as Virtual Hardware Architecture for LLM Simulation #1
Conversation
…virtual hardware Co-authored-by: danregima <10253941+danregima@users.noreply.github.com>
…d comprehensive documentation Co-authored-by: danregima <10253941+danregima@users.noreply.github.com>
danregima
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fantastic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a novel financial simulation system that models a Chart of Accounts (CoA) as virtual hardware architecture, enabling LLM-powered reasoning over financial operations using circuit design principles. The system treats financial accounts as electronic nodes with voltage levels representing balances, transactions as signal routing operations, and double-entry accounting as conservation laws.
Key changes implemented:
- Complete financial circuit simulator with hardware analogy mapping
- Interactive command interface for exploring financial operations
- LLM integration for AI-driven financial circuit analysis
- Comprehensive test suite validating the hardware simulation logic
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| examples/financial-sim/financial-sim.cpp | Main financial circuit simulator implementing the core CoA-to-hardware mapping logic |
| examples/financial-sim/test-financial-logic.cpp | Comprehensive test suite validating Chart of Accounts, transaction processing, and hardware analogy concepts |
| examples/financial-sim/README.md | Documentation explaining the hardware analogy concept, usage examples, and feature overview |
| examples/financial-sim/sample-coa.json | Sample Chart of Accounts with hardware descriptions for each account type |
| examples/financial-sim/CMakeLists.txt | Build configuration for the financial simulator and test executable |
| examples/CMakeLists.txt | Integration of financial-sim subdirectory into the main examples build |
| Account* equity = coa.get_account("3100"); // Equity - credit normal | ||
| Account* revenue = coa.get_account("4100"); // Revenue - credit normal | ||
| Account* expense = coa.get_account("5101"); // Expense - debit normal | ||
|
|
Copilot
AI
Sep 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function get_account() returns a pointer that could be null if the account doesn't exist. These pointers should be checked for null before dereferencing them in the subsequent assertions.
| assert(cash != nullptr && "Account '1101' (cash) not found"); | |
| assert(payable != nullptr && "Account '2101' (payable) not found"); | |
| assert(equity != nullptr && "Account '3100' (equity) not found"); | |
| assert(revenue != nullptr && "Account '4100' (revenue) not found"); | |
| assert(expense != nullptr && "Account '5101' (expense) not found"); | |
| case AccountType::ASSET: return "Asset (Storage/Input)"; | ||
| case AccountType::LIABILITY: return "Liability (Output/Buffer)"; | ||
| case AccountType::EQUITY: return "Equity (Core Processing)"; | ||
| case AccountType::REVENUE: return "Revenue (Signal Source)"; |
Copilot
AI
Sep 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The get_account_type_name() function is missing a case for AccountType::EXPENSE. This will cause expense accounts to be labeled as 'Unknown' instead of their proper type description.
| case AccountType::REVENUE: return "Revenue (Signal Source)"; | |
| case AccountType::REVENUE: return "Revenue (Signal Source)"; | |
| case AccountType::EXPENSE: return "Expense (Signal Consumer)"; |
|
|
||
| void generate_response(const std::string& prompt) { | ||
| // Tokenize the prompt | ||
| const int n_prompt = -llama_tokenize(vocab, prompt.c_str(), prompt.size(), NULL, 0, true, true); |
Copilot
AI
Sep 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Using negative return value from llama_tokenize() to get token count is an unusual pattern. Consider using a more explicit approach or add a comment explaining this tokenization technique.
| const int n_prompt = -llama_tokenize(vocab, prompt.c_str(), prompt.size(), NULL, 0, true, true); | |
| // llama_tokenize returns a negative token count when called with NULL output buffer (see llama.cpp API). | |
| int n_prompt_raw = llama_tokenize(vocab, prompt.c_str(), prompt.size(), NULL, 0, true, true); | |
| if (n_prompt_raw >= 0) { | |
| std::cerr << "Error: Unexpected non-negative return from llama_tokenize when counting tokens\n"; | |
| return; | |
| } | |
| const int n_prompt = -n_prompt_raw; |
| {"1102", 5000.0, 0.0, "Equipment purchased"}, // Debit Equipment (Asset) | ||
| {"1101", 0.0, 5000.0, "Cash paid"} // Credit Cash (Asset) |
Copilot
AI
Sep 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The transaction is debiting account '1102' which is labeled as 'Equipment purchased' but account '1102' was initialized as 'Accounts Receivable' in the setup. This should debit a proper equipment account or the account code should be corrected.
This PR implements a novel financial simulation system that models a Chart of Accounts (CoA) as virtual hardware architecture, enabling LLM-powered reasoning over financial operations using circuit design principles.
Core Concept
The implementation treats financial accounting as an electronic circuit system:
Key Features
Hardware Analogy Mapping
Signal Routing System
The system processes transactions as signal routing operations with proper polarity:
Multiple Operation Modes
Demo Mode (No LLM Required)
Runs a complete financial circuit simulation showcasing:
Interactive Mode
Provides hands-on circuit exploration with commands like:
balance-sheet- View current circuit statetransaction- Process signal routing operationsaccounts- List all hardware nodesquick-demo- Run demonstration transactionsLLM-Powered Analysis
Enables AI-driven financial circuit analysis using hardware engineering terminology.
Implementation Details
Chart of Accounts Structure
The system implements a hierarchical account structure with parent-child relationships, treating each level as different circuit abstraction layers.
Transaction Processing
Every transaction must satisfy conservation laws (balanced debits/credits) before being routed through the financial circuit. The system validates:
Hardware-Style Reporting
Testing
Comprehensive test suite validates:
./test-financial-logic # Runs all validation testsLLM Integration
When used with a language model, the system generates hardware-focused prompts that enable the LLM to reason about financial operations using circuit design principles:
This bridges abstract financial logic with digital circuit/systems design thinking, creating a novel approach to financial analysis and education.
Files Added
examples/financial-sim/financial-sim.cpp- Main financial circuit simulatorexamples/financial-sim/test-financial-logic.cpp- Comprehensive test suiteexamples/financial-sim/README.md- Documentation and usage examplesexamples/financial-sim/sample-coa.json- Sample chart of accountsexamples/financial-sim/CMakeLists.txt- Build configurationThe implementation successfully demonstrates how language models can simulate and reason over structured, rule-based systems by mapping them to familiar hardware concepts.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
ggml.ai/home/REDACTED/work/ggnumlcash.cpp/ggnumlcash.cpp/build/bin/test-arg-parser(dns block)huggingface.co/usr/lib/git-core/git-remote-https origin REDACTED(dns block)/home/REDACTED/work/ggnumlcash.cpp/ggnumlcash.cpp/build/bin/test-thread-safety -hf ggml-org/models -hff tinyllamas/stories15M-q4_0.gguf -ngl 99 -p The meaning of life is -n 128 -c 256 -ub 32 -np 4 -t 2(dns block)/home/REDACTED/work/ggnumlcash.cpp/ggnumlcash.cpp/build/bin/llama-eval-callback --hf-repo ggml-org/models --hf-file tinyllamas/stories260K.gguf --model stories260K.gguf --prompt hello --seed 42 -ngl 0(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.