8000 Package Virne CLI and configs by GeminiLight · Pull Request #55 · GeminiLight/virne · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,32 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install torch==2.13.0 --index-url https://download.pytorch.org/whl/cpu
python -m pip install --editable . pytest
python -m pip install build==1.5.0 pytest==9.1.1
python -m build
python -m pip install dist/*.whl
python -m pip check

- name: Test installed package
working-directory: /tmp
run: python -c "import importlib.util, gymnasium, torch, torch_geometric, virne; assert gymnasium.__version__ == '1.3.0'; assert torch.__version__.startswith('2.13.'); assert torch_geometric.__version__ == '2.8.0.post1'; assert importlib.util.find_spec('gym') is None"
run: |
python -c "import importlib.resources, importlib.util, gymnasium, torch, torch_geometric, virne; assert gymnasium.__version__ == '1.3.0'; assert torch.__version__.startswith('2.13.'); assert torch_geometric.__version__ == '2.8.0.post1'; assert importlib.util.find_spec('gym') is None; assert importlib.resources.files('virne').joinpath('configs/main.yaml').is_file()"
virne --version
virne --help
virne --cfg job

- name: Smoke test installed CLI
working-directory: /tmp
run: |
virne \
hydra.run.dir=/tmp/virne-smoke-${{ matrix.python-version }} \
experiment.run_id=ci-wheel-smoke \
experiment.if_save_config=false \
solver.solver_name=nrm_rank \
v_sim_setting.num_v_nets=10 \
training.use_cuda=false \
recorder.if_save_records=false \
recorder.if_temp_save_records=false \
'logger.backends=[console]'

- name: Run all tests
run: |
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
recursive-include settings *.yaml
recursive-include virne/configs *.yaml
40 changes: 24 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div align="center">
<img src="resources/figures/virne-logo-text.png" width="200" alt="Virne logo">
<img src="https://raw.githubusercontent.com/GeminiLight/virne/main/resources/figures/virne-logo-text.png" width="200" alt="Virne logo">
<h2>A Comprehensive Simulator & Benchmark for NFV-RA</h2>
<p>
<a href="https://deepwiki.com/GeminiLight/virne"><img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki"></a>
Expand Down Expand Up @@ -33,7 +33,7 @@ Virne offers a unified and comprehensive framework for NFV-RA, with the followin
>
> ✨ If you have any questions, please open a new issue or contact me via email (wtfly2018@gmail.com)

![Virne architecture: simulation, solver, environment, and evaluation components](resources/figures/virne-architecture.png)
![Virne architecture: simulation, solver, environment, and evaluation components](https://raw.githubusercontent.com/GeminiLight/virne/main/resources/figures/virne-architecture.png)

### Citations

Expand Down Expand Up @@ -95,44 +95,52 @@ Virne offers a unified and comprehensive framework for NFV-RA, with the followin

### Installation

The installation script supports CPU environments on Linux and macOS, plus
CUDA 12.6, 13.0, and 13.2 on Linux. Clone the repository, then create and
activate a Python 3.12 or newer environment:
Create and activate a Python 3.12 or newer environment, then install the
latest Virne release from PyPI:

```bash
git clone https://github.com/GeminiLight/virne.git
cd virne
python3 -m venv .venv
source .venv/bin/activate
python -m pip install virne
```

Install either the CPU build or a supported CUDA build. The script defaults to
CPU and installs PyTorch 2.13.0 with PyG 2.8.0.post1. It also installs the
matching optional `pyg_lib` acceleration wheel without hard-coding the
operating system or Python ABI:
The standard installation includes the complete Virne runtime and works
without optional compiled PyG extensions. Verify the installed command with:

```bash
virne --version
```

To select a specific CPU or CUDA build of PyTorch and install the matching
optional `pyg_lib` acceleration wheel, use the source installer instead. It
supports CPU environments on Linux and macOS, plus CUDA 12.6, 13.0, and 13.2
on Linux:

```bash
git clone https://github.com/GeminiLight/virne.git
cd virne

# CPU-only PyTorch and PyG
bash install.sh -c cpu

# CUDA 12.6 (use 13.0 or 13.2 when appropriate for your driver and GPU)
bash install.sh -c 12.6
```

The script installs Virne in editable mode and prints all three versions. You
can verify them again with:
The script installs Virne in editable mode and prints the installed versions.
You can verify them again with:

```bash
python -c "import torch, torch_geometric, virne; print(virne.__version__, torch.__version__, torch_geometric.__version__)"
```

### Run a Small Experiment

Use a fast heuristic and ten VN requests for the first run. Calling
`python main.py` without overrides starts the larger default RL experiment.
Use a fast heuristic and ten VN requests for the first run. Calling `virne`
without overrides starts the larger default RL experiment.

```bash
python main.py \
virne \
solver.solver_name=nrm_rank \
v_sim_setting.num_v_nets=10 \
training.use_cuda=false \
Expand Down
6 changes: 3 additions & 3 deletions docs/source/evaluation/aspects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ study:

for max_v_nodes in 4 6 8 10; do
for eval_seed in 0 1 2 3 4; do
python main.py \
virne \
solver.solver_name=nrm_rank \
v_sim_setting.num_v_nets=100 \
v_sim_setting.v_net_size.high=${max_v_nodes} \
Expand Down Expand Up @@ -94,7 +94,7 @@ For an RL solver, load the same checkpoint for every condition:

.. code-block:: bash

python main.py \
virne \
solver.solver_name=ppo_dual_gat+ \
training.num_train_epochs=0 \
solver.pretrained_model_path=/absolute/path/to/model.pkl \
Expand All @@ -120,7 +120,7 @@ also record peak memory:
.. code-block:: bash

for p_nodes in 50 100 200; do
/usr/bin/time -v python main.py \
/usr/bin/time -v virne \
solver.solver_name=nrm_rank \
p_net_setting.topology.num_nodes=${p_nodes} \
v_sim_setting.num_v_nets=100 \
Expand Down
8 changes: 4 additions & 4 deletions docs/source/intro/framework.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Core Components
- Main implementation
* - Configuration
- Defines the experiment, system, solver, training, PN, and VN settings.
- ``settings/main.yaml``, ``settings/learning.yaml``, and the PN/VN files
under ``settings/``
- ``virne/configs/main.yaml``, ``virne/configs/learning.yaml``, and the
PN/VN files under ``virne/configs/``
* - Network model
- Represents physical and virtual networks and generates request events.
- ``virne.network``
Expand All @@ -50,9 +50,9 @@ Core Components
Experiment Flow
---------------

When ``python main.py`` is executed, Virne follows this sequence:
When ``virne`` is executed, Virne follows this sequence:

1. Hydra composes ``settings/main.yaml`` and applies command-line overrides.
1. Hydra composes ``virne/configs/main.yaml`` and applies command-line overrides.
2. ``BaseSystem.from_config`` creates the network data, environment, solver,
controller, recorder, counter, and logger.
3. The selected system emits VN arrival and departure events.
Expand Down
6 changes: 3 additions & 3 deletions docs/source/intro/rl-support.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ requests, saves a checkpoint, and then evaluates the trained policy:

.. code-block:: bash

python main.py \
virne \
solver.solver_name=ppo_dual_gat+ \
v_sim_setting.num_v_nets=10 \
training.num_train_epochs=1 \
Expand Down Expand Up @@ -119,7 +119,7 @@ Key Training Settings
- Enables or disables invalid-action masking.

Defaults and the remaining optimizer and network settings live in
``settings/main.yaml`` and ``settings/learning.yaml``.
``virne/configs/main.yaml`` and ``virne/configs/learning.yaml``.

Evaluate a Saved Model
----------------------
Expand All @@ -128,7 +128,7 @@ Set training epochs to zero and pass an **absolute** checkpoint path:

.. code-block:: bash

python main.py \
virne \
solver.solver_name=ppo_dual_gat+ \
training.num_train_epochs=0 \
solver.pretrained_model_path=/absolute/path/to/model.pkl
Expand Down
2 changes: 1 addition & 1 deletion docs/source/solver/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Virne selects solvers through `solver.solver_name`. For example:

```bash
python main.py solver.solver_name=nrm_rank
virne solver.solver_name=nrm_rank
```

## How to Choose a Solver
Expand Down
39 changes: 24 additions & 15 deletions docs/source/start/installation.rst
8
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ Installation
Virne's RL environments use the ``gymnasium==1.3.0`` API. The scientific
stack requires NumPy 2 and Python 3.12 or newer.

Get the Source
--------------

.. code-block:: bash

git clone https://github.com/GeminiLight/virne.git
cd virne

Create a Virtual Environment
----------------------------

Expand All @@ -22,17 +14,33 @@ Create a Virtual Environment
python3 -m venv .venv
source .venv/bin/activate

Install with the Script
-----------------------
Install from PyPI
-----------------

Install the latest Virne release and verify its command-line entry point:

The script supports CPU environments on Linux and macOS, plus CUDA 12.6, 13.0,
and 13.2 on Linux. It installs PyTorch 2.13.0, PyG 2.8.0.post1, Gymnasium 1.3.0,
and Virne itself in editable mode. The matching optional ``pyg_lib`` acceleration
wheel is selected for the active platform and Python ABI. Run it from the
repository root after activating a Python 3.12 or newer environment.
.. code-block:: bash

python -m pip install virne
virne --version

The standard installation includes the complete Virne runtime. PyG's optional
compiled extensions are not required for correctness.

Select a CPU or CUDA Build
--------------------------

When you need to select an exact CPU or CUDA build of PyTorch, clone the source
repository and use the installation script. It supports CPU environments on
Linux and macOS, plus CUDA 12.6, 13.0, and 13.2 on Linux. It installs PyTorch
2.13.0, PyG 2.8.0.post1, Gymnasium 1.3.0, Virne in editable mode, and the
matching optional ``pyg_lib`` acceleration wheel.

.. code-block:: bash

git clone https://github.com/GeminiLight/virne.git
cd virne

# CPU-only PyTorch and PyG
bash install.sh -c cpu

Expand All @@ -49,6 +57,7 @@ Keep the virtual environment active and run:

.. code-block:: bash

virne --version
python -c "import gymnasium, torch, torch_geometric, virne; print(virne.__version__, gymnasium.__version__, torch.__version__, torch_geometric.__version__)"

The command should print the installed Virne, Gymnasium, PyTorch, and PyG
Expand Down
17 changes: 10 additions & 7 deletions docs/source/start/running.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ Quickstart
==========

This example runs a small CPU simulation with a fast heuristic solver. It is a
better first check than ``python main.py`` alone, because the default
better first check than ``virne`` alone, because the default
configuration trains an RL solver and processes 1,000 VN requests.

Run a Small Experiment
----------------------

From the repository root, with the ``virne`` Conda environment active, run:
With the environment containing Virne active, run this from any writable
directory:

.. code-block:: bash

python main.py \
virne \
solver.solver_name=nrm_rank \
v_sim_setting.num_v_nets=10 \
training.use_cuda=false \
Expand Down Expand Up @@ -53,16 +54,18 @@ can be overridden with ``key=value``. Prefix a new key with ``+``.
.. code-block:: bash

# Select another registered solver
python main.py solver.solver_name=random_rank
virne solver.solver_name=random_rank

# Load a physical topology from a GML file
python main.py +p_net_setting.topology.file_path=./datasets/topology/Geant.gml
virne +p_net_setting.topology.file_path=/path/to/Geant.gml

# Use the offline network system
python main.py system.if_offline_system=true
virne system.if_offline_system=true

# Preview the resolved configuration without running a simulation
python main.py --cfg job
virne --cfg job

Use the :doc:`solver registry <../solver/overview>` for valid solver names and
:doc:`simulation scenarios <simulation>` for the canonical PN and VN settings.
Source checkouts retain ``python main.py`` as a compatibility alias for the
``virne`` command.
10 changes: 5 additions & 5 deletions docs/source/start/simulation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ Lifetime
Canonical Configuration Files
-----------------------------

The configuration files under ``settings/`` are the source of truth. In particular, refer to:
The configuration files under ``virne/configs/`` are the source of truth. In particular, refer to:

* `settings/main.yaml <https://github.com/GeminiLight/virne/blob/main/settings/main.yaml>`_ for system, solver, recorder, and logging options.
* `settings/p_net_setting/default.yaml <https://github.com/GeminiLight/virne/blob/main/settings/p_net_setting/default.yaml>`_ for the default physical network.
* `settings/v_sim_setting/default.yaml <https://github.com/GeminiLight/virne/blob/main/settings/v_sim_setting/default.yaml>`_ for the default virtual network request simulation.
* `settings/p_net_setting/ <https://github.com/GeminiLight/virne/tree/main/settings/p_net_setting>`_ and `settings/v_sim_setting/ <https://github.com/GeminiLight/virne/tree/main/settings/v_sim_setting>`_ for the supported scenario variants.
* `virne/configs/main.yaml <https://github.com/GeminiLight/virne/blob/main/virne/configs/main.yaml>`_ for system, solver, recorder, and logging options.
* `virne/configs/p_net_setting/default.yaml <https://github.com/GeminiLight/virne/blob/main/virne/configs/p_net_setting/default.yaml>`_ for the default physical network.
* `virne/configs/v_sim_setting/default.yaml <https://github.com/GeminiLight/virne/blob/main/virne/configs/v_sim_setting/default.yaml>`_ for the default virtual network request simulation.
* `virne/configs/p_net_setting/ <https://github.com/GeminiLight/virne/tree/main/virne/configs/p_net_setting>`_ and `virne/configs/v_sim_setting/ <https://github.com/GeminiLight/virne/tree/main/virne/configs/v_sim_setting>`_ for the supported scenario variants.

These files are intentionally not duplicated here so that configuration examples cannot drift from the executable defaults.
30 changes: 2 additions & 28 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,5 @@
# os.chdir(os.path.join(os.getcwd(), 'code/virne-dev'))
import os

import hydra
from omegaconf import DictConfig, OmegaConf, open_dict
from virne.system import BaseSystem

from virne.utils.config import add_simulation_into_config, generate_run_id



@hydra.main(version_base="1.3", config_path="settings", config_name="main")
def run(config):
print(f"\n{'-' * 20} Start {'-' * 20}\n")
# ---- Before running the simulation ---- #
# Configure Customization
# Method 1. Update the config file
# Method 2. Use hydra CLI
# Method 3. Modify the config here [Not recommended]
if config.experiment.run_id == 'auto':
config.experiment.run_id = generate_run_id()
add_simulation_into_config(config)
# --------------------------------------- #
system = BaseSystem.from_config(config)
system.run()

print(f"\n{'-' * 20} Complete {'-' * 20}\n")
from virne.cli import main, run as run


if __name__ == '__main__':
run()
main()
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ dependencies = [
"torch_geometric == 2.8.0.post1"
]

dynamic = ["entry-points"]

[project.scripts]
virne = "virne.cli:main"

[project.urls]
Homepage = "https://github.com/GeminiLight/virne"
Expand All @@ -58,6 +60,7 @@ lint = [

[dependency-groups]
dev = [
"build == 1.5.0",
"pytest == 9.1.1",
"ruff == 0.16.2",
]
Expand All @@ -83,6 +86,9 @@ include-package-data = true
[tool.setuptools.packages.find]
include = ["virne", "virne.*"]

[tool.setuptools.package-data]
virne = ["configs/*.yaml", "configs/*/*.yaml"]

# Linter tools #################################################################

[tool.black]
Expand Down
Loading
Loading
0