Funz Calculator
The Funz calculator provides compatibility with legacy Java Funz calculator servers, enabling FZ to leverage existing Funz infrastructure.
Overview
Funz is a Java-based framework for computational experiments. The FZ Funz calculator allows Python FZ to communicate with Java Funz calculator servers, providing backward compatibility and integration with existing Funz deployments.
URI Format
Components
- host (optional): Hostname of the Funz server (default: localhost)
- port (required): TCP port number of the Funz server
- code: Model/language code supported by the server (e.g., R, Python, bash)
Examples
Local Funz Server
import fz
results = fz.fzr(
"input.txt",
{"param1": [1, 2, 3]},
model,
calculators="funz://:5555/R",
results_dir="results"
)
Remote Funz Server
Multiple Funz Servers
Load balance across multiple calculator servers:
calculators = [
"funz://server1.example.com:5555/R",
"funz://server2.example.com:5555/R",
"funz://server3.example.com:5555/R"
]
Protocol
The Funz calculator uses TCP socket communication with a specific protocol:
Reservation
Before executing a calculation, FZ reserves the calculator:
Server responds with:
Execution
Files are uploaded and execution is requested:
Result Retrieval
After execution, results are downloaded:
Server responds with file content.
Unreservation
After completion, the calculator is released:
UDP Discovery
Funz servers can advertise themselves via UDP broadcast. FZ can automatically discover available Funz calculators on the local network.
Discovery Process
- FZ sends UDP broadcast on port 21001:
WHO - Funz servers respond with:
FUNZ <host>:<port> <codes> - FZ automatically configures discovered calculators
Automatic Discovery
# FZ automatically discovers Funz servers
results = fz.fzr(
"input.txt",
variables,
model,
calculators="funz", # Auto-discover
results_dir="results"
)
Calculator Configuration
Funz calculators can be configured via JSON files in .fz/calculators/:
Features
File Transfer
- Automatic upload of input files to Funz server
- Download of output files after execution
- Binary file support
Job Management
- Calculator reservation system prevents conflicts
- Automatic retry on calculator failure
- Graceful cleanup on interruption (Ctrl+C)
Multi-Language Support
Funz servers can support multiple languages/codes:
- R statistical computing
- Python scripting
- Bash shell scripts
- MATLAB/Octave
- Custom calculation codes
Requirements
- Java Funz calculator server running and accessible
- Network connectivity to Funz server
- Port not blocked by firewall
Setting Up a Funz Server
To start a Java Funz calculator server:
For multiple codes:
Model Compatibility
The Funz calculator requires that the model is compatible with the specified code:
model = {
"varprefix": "$",
"code": "R", # Must match calculator code
"output": {
"result": "cat output.txt"
}
}
calculators = "funz://:5555/R" # Code must match
Examples
R Statistical Analysis
import fz
model = {
"varprefix": "$",
"code": "R",
"output": {
"mean": "grep 'Mean:' output.txt | awk '{print $2}'"
}
}
results = fz.fzr(
"analysis.R",
{
"sample_size": [100, 500, 1000],
"mean": [0, 10, 20],
"sd": [1, 2, 5]
},
model,
calculators="funz://:5555/R",
results_dir="r_results"
)
Python Simulation
calculators = "funz://compute-server.local:5555/Python"
results = fz.fzr(
"simulation.py",
{"iterations": [1000, 5000, 10000]},
model,
calculators=calculators,
results_dir="sim_results"
)
Load Balancing
Distribute calculations across multiple Funz servers:
calculators = [
"funz://node1:5555/R",
"funz://node2:5555/R",
"funz://node3:5555/R",
"funz://node4:5555/R"
]
results = fz.fzr(
"model.R",
large_parameter_grid,
model,
calculators=calculators,
n_parallel=4 # Use all 4 servers
)
Troubleshooting
Connection Refused
Check that the Funz server is running:
Verify firewall rules allow the connection.
Code Not Supported
Ensure the Funz server supports the requested code:
Check the server's code list in the response.
File Transfer Fails
Large files may require timeout adjustments:
Calculator Reserved
If a calculator is stuck in reserved state, restart the Funz server:
# Kill existing server
pkill -f "Funz-Calculator"
# Restart
java -jar Funz-Calculator.jar -code R -port 5555
See Also
- SSH Calculator - For remote SSH execution
- SLURM Calculator - For HPC cluster execution
- Calculator Overview - Overview of all calculator types
- Funz Protocol Documentation - Detailed protocol specification