calcoloscientifico:cluster:softwareapplicativo:conda
Differenze
Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.
| Entrambe le parti precedenti la revisioneRevisione precedente | |||
| calcoloscientifico:cluster:softwareapplicativo:conda [03/07/2024 17:34] – fabio.spataro | calcoloscientifico:cluster:softwareapplicativo:conda [05/07/2024 10:04] (versione attuale) – federico.prost | ||
|---|---|---|---|
| Linea 652: | Linea 652: | ||
| conda deactivate | conda deactivate | ||
| + | </ | ||
| + | |||
| + | ==== Virtualenv " | ||
| + | |||
| + | Available versions of the " | ||
| + | |||
| + | ^ condaenv | ||
| + | | pennylane | ||
| + | | pennylane-gpu | ||
| + | |||
| + | Enable the default version of the " | ||
| + | |||
| + | < | ||
| + | module load miniconda3 | ||
| + | source " | ||
| + | conda activate pennylane | ||
| + | </ | ||
| + | |||
| + | Enable the gpu version of the " | ||
| + | |||
| + | < | ||
| + | module load miniconda3 | ||
| + | source " | ||
| + | conda activate pennylane-gpu | ||
| + | </ | ||
| + | |||
| + | Packages in the " | ||
| + | |||
| + | < | ||
| + | conda list | ||
| + | </ | ||
| + | |||
| + | Disable the " | ||
| + | |||
| + | < | ||
| + | conda deactivate | ||
| + | </ | ||
| + | |||
| + | Script '' | ||
| + | |||
| + | <code bash slurm-pennylane-gpu.sh> | ||
| + | #!/bin/bash | ||
| + | #SBATCH --job-name=plExample | ||
| + | #SBATCH --output=%x.o%j | ||
| + | #SBATCH --error=%x.e%j | ||
| + | #SBATCH --nodes=1 | ||
| + | #SBATCH --partition=gpu | ||
| + | #SBATCH --qos=gpu | ||
| + | #SBATCH --gres=gpu: | ||
| + | #SBATCH --mem=8G | ||
| + | #SBATCH --time=0-10: | ||
| + | #SBATCH --ntasks-per-node 4 | ||
| + | #SBATCH --account=< | ||
| + | |||
| + | module load miniconda3 | ||
| + | source " | ||
| + | conda activate pennylane-gpu | ||
| + | |||
| + | PYTHON_VERSION=$(python -V | awk '{ print $2 }') | ||
| + | echo $PYTHON_VERSION | ||
| + | |||
| + | python -u ./ | ||
| + | |||
| + | conda deactivate | ||
| + | </ | ||
| + | |||
| + | |||
| + | Script '' | ||
| + | |||
| + | <code pyton plExample.py> | ||
| + | # | ||
| + | |||
| + | # Simple example where we train a parameterized quantum circuit | ||
| + | # to minimize the expectation value of a Pauli-Z operator. | ||
| + | import pennylane as qml | ||
| + | from pennylane import numpy as np | ||
| + | |||
| + | # Define a quantum device with one qubit | ||
| + | dev = qml.device(" | ||
| + | |||
| + | # Define a variational quantum circuit | ||
| + | @qml.qnode(dev) | ||
| + | def circuit(params): | ||
| + | qml.RX(params[0], | ||
| + | qml.RY(params[1], | ||
| + | return qml.expval(qml.PauliZ(0)) | ||
| + | |||
| + | # Define the cost function to minimize | ||
| + | def cost(params): | ||
| + | return circuit(params) | ||
| + | |||
| + | # Initialize parameters | ||
| + | init_params = np.array([0.01, | ||
| + | |||
| + | # Set up the optimizer | ||
| + | opt = qml.GradientDescentOptimizer(stepsize=0.1) | ||
| + | |||
| + | # Number of optimization steps | ||
| + | steps = 100 | ||
| + | |||
| + | # Optimize the circuit parameters | ||
| + | params = init_params | ||
| + | for i in range(steps): | ||
| + | params = opt.step(cost, | ||
| + | if (i + 1) % 10 == 0: | ||
| + | print(f" | ||
| + | |||
| + | print(f" | ||
| + | print(f" | ||
| + | |||
| </ | </ | ||
calcoloscientifico/cluster/softwareapplicativo/conda.1720020886.txt.gz · Ultima modifica: da fabio.spataro
