Branch
Branching creates a snapshot of an instance and then launches a specified number of new instances from that snapshot. This is particularly useful for scenarios where you need multiple identical environments, like parallel testing, training multiple machine learning models, or preparing environments for a team.
Creating Multiple Clones
Branching an instance creates multiple clone instances based on the current state of the original instance.
- Python
- TypeScript
- CLI
from morphcloud.api import MorphCloudClient
client = MorphCloudClient()
instance_id = "morphvm_abc123" # Replace with a valid instance ID
instance = client.instances.get(instance_id=instance_id)
snapshot, clones = instance.branch(count=3)
print(f"Snapshot created: {snapshot.id}")
print("Cloned instances:")
for clone in clones:
print(f" - {clone.id}")
import { MorphCloudClient } from 'morphcloud';
const client = new MorphCloudClient();
async function branchInstance() {
const instanceId = "morphvm_abc123"; // Replace with a valid instance ID
const instance = await client.instances.get({ instanceId: instanceId });
// Create 3 branches from original instance
const level1Result = await instance.branch(3);
// Optional: Create branches from one of the clones
if (level1Result.instances.length > 0) {
const level2Result = await level1Result.instances[0].branch(2);
console.log(`Created ${level2Result.instances.length} level 2 instances`);
}
}
branchInstance();
# Branch an instance to create 3 clones
morphcloud instance branch morphvm_abc123 --count 3
Use Cases for Branching
Branching is particularly useful in the following scenarios:
-
Parallelized Testing: Create multiple identical environments to run different test suites in parallel.
-
Machine Learning Training: Branch a prepared environment to train multiple models with different parameters.
-
Team Development: Create identical environments for each team member from a pre-configured instance.
-
A/B Deployment Testing: Run the same application with different configurations to test performance or behavior.
-
Batch Processing: Process different data chunks in parallel with identical processing environments.