Skip to content

Conversation

@jogisuda
Copy link
Contributor

I added one notebook called 3_hybrid_model.ipynb to illustrate a hybrid quark vs gluon classification using QiBO. Besides the notebook, I added two images to Quantum_machine_learning/figures folder.

@MatteoRobbiati MatteoRobbiati self-requested a review June 20, 2025 08:51
Copy link
Contributor

@MatteoRobbiati MatteoRobbiati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many, many thanks for this contribution!
I left a list of comments (some of them are really minor suggestions) below.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments on the notebook:

  1. I would rename the file into something like lie_equivariant_quantum_graph_nn.ipynb. Then, as you do in the text, we can mention it is a very good example for hybrid architectures :)
  2. QiBO --> Qibo in the first cell;
  3. Add some docstrings to function defined in code cell [2];
  4. I think the data are missing. Probably you just forgot to upload them into ../data/.;
  5. In the text of section 2. we define the graph with normal text font, while in the previous section \mathcal is used. I would choose one of the two;
  6. I would standardize the figures' captions with the way we do it in Qiboedu. Namely, Figure n: description. Nothing particularly relevant, it is just to have a uniform style;
  7. Add docstrings to functions in cells [5-7];
  8. I would move the Auxiliary functions to a proper file within the qiboedu/src/qiboedu/scripts folder, to lighten the notebook :) Of course, you also have to tell me if you prefer to keep these here. But I believe we could just mention that all the scripts are available in the aforementioned path;
  9. In cell [8] and [9] there are some imports already done in the cell [1]. Please, clean the imports and move all the necessary to the first cell;
  10. I was thinking if to move the model in some script as well, but it can be actually interesting to keep it here. I don't have any particular strong opinion on this. If we keep it, please add docstrings to all the methods of the model;
  11. I would add some comment to guide the reading of cells [10-15];
  12. Same as before, in cell [16] there are redundant imports;
  13. I would consider lighten the output during the training (e.g. removing tqdm), and, if it is not necessary to understand the tutorial, I would also move part of the training functions to scripts;
  14. cell [17] is probably still script-oriented. For example the if __name__ == "main", and the usage of global variable definition. I think this can be a bit confusing, so I would move the part to a script or make it a bit more notebook-friendly;
  15. I find curious how validation loss and accuracy are actually better than the training one. Do you have any idea on why this is happening?
  16. I would standardize the plots to the style proposed in qiboedu/src/qiboedu/scripts/plotscripts in terms of color, inches, etc. Please let me know if any help is needed :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! I'm working on the points above. Specifically referring to [8, 14], in order to upload the scripts in qiboedu/src/qiboedu/scripts, I need push permission, please.

jogisuda added 7 commits June 21, 2025 09:41
Add functions to plot accuracies and losses of models.
These two files contain training scripts and some utilitary functions for lie_eqgnn, like computing Minkowski invariant features, GradualWarmupScheduler, etc.
@MatteoRobbiati MatteoRobbiati self-requested a review July 2, 2025 08:22
Copy link
Contributor

@MatteoRobbiati MatteoRobbiati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your work! Some more comments follow :)
Also, we should fix the conflicts with the main before merging.

Comment on lines +52 to +55
"from qiboedu.scripts.lie_eqgnn_utils import *\n",
"from qiboedu.scripts.plotscripts import plot_loss, plot_accuracies\n",
"from qiboedu.scripts.lie_eqgnn_train import *\n",
"\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am now a big fan of from package import *, for readability and also because it is not often necessary to import all. I would prefer importing the single functions/classes individually :)

"metadata": {},
"outputs": [],
"source": [
"# to begin loading the jets, we will need some auxiliary functions to handle the graphical format.\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"# to begin loading the jets, we will need some auxiliary functions to handle the graphical format.\n",
"# To begin loading the jets, we will need some auxiliary functions to handle the graphical format.\n",

"def get_adj_matrix(n_nodes, batch_size, edge_mask):\n",
"\n",
" \"\"\"\n",
" Constructs a batched edge list (adjacency list) from a binary edge mask\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
" Constructs a batched edge list (adjacency list) from a binary edge mask\n",
" Construct a batched edge list (adjacency list) from a binary edge mask\n",

This is extremely pedantic .-. but, according to the PEP 257 Docstring Conventions:

The docstring is a phrase ending in a period. It prescribes the function or method’s effect as a command (“Do this”, “Return that”), not as a description; e.g. don’t write “Returns the pathname …”.

"def load_jets(p4s, nodes, labels, atom_mask, edge_mask, edges, batch_size, train_ratio, val_ratio, test_ratio):\n",
"\n",
" \"\"\"\n",
" Splits the full jet dataset into training, validation, and test sets,\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
" Splits the full jet dataset into training, validation, and test sets,\n",
" Split the full jet dataset into training, validation, and test sets,\n",

As before :)

"val_ratio = 0.1\n",
"test_ratio = 0.1\n",
"\n",
"dataloaders = load_jets(p4s, nodes, labels, atom_mask, edge_mask, edges, 16, train_ratio, val_ratio, test_ratio)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just expose the call to this load_jets function, and move the loading utils into dedicated script file, to lighten the readability. But I am open to discuss about it.

" def m_model(self, hi, hj, norms, dots):\n",
"\n",
" \"\"\"\n",
" Computes Lorentz-invariant edge messages for the graph neural network.\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
" Computes Lorentz-invariant edge messages for the graph neural network.\n",
" Compute Lorentz-invariant edge messages for the graph neural network.\n",

As before.

"\n",
" def h_model(self, h, edges, m, node_attr):\n",
" \"\"\"\n",
" Computes Lorentz-invariant scalar latent representation.\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
" Computes Lorentz-invariant scalar latent representation.\n",
" Compute Lorentz-invariant scalar latent representation.\n",

As before.

Comment on lines +1219 to +1220
"device = 'cuda'\n",
"dtype = torch.float64\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"device = 'cuda'\n",
"dtype = torch.float64\n",

I think this is not needed, since already defined above.

Comment on lines +1300 to +1302
"import os\n",
"import json\n",
"import matplotlib.pyplot as plt\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Remove matplotlib (since already imported above). Also, is it necessary to import it here, after the plotting functions have been moved to the scripts?
  2. Move the other two imports in the first cell (with the other imports).

Comment on lines +35 to +55
"import numpy as np\n",
"from math import sqrt\n",
"import matplotlib.pyplot as plt\n",
"\n",
"import torch\n",
"from torch import nn\n",
"from torch.utils.data import TensorDataset, DataLoader, random_split\n",
"from scipy.sparse import coo_matrix\n",
"\n",
"from qibo.symbols import Z, I\n",
"from qibo.hamiltonians import SymbolicHamiltonian\n",
"from qiboml.models.encoding import PhaseEncoding\n",
"from qibo import Circuit, gates, hamiltonians\n",
"from qiboml.models.decoding import QuantumDecoding\n",
"from qiboml.interfaces.pytorch import QuantumModel\n",
"from qibo import set_backend\n",
"\n",
"from qiboedu.scripts.lie_eqgnn_utils import *\n",
"from qiboedu.scripts.plotscripts import plot_loss, plot_accuracies\n",
"from qiboedu.scripts.lie_eqgnn_train import *\n",
"\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reorganize the import package by package and follow the PEP 8 guidelines:

  1. Standard library imports.
  2. Related third party imports.
  3. Local application/library specific imports.

(It is already done more or less, but saying this for the moment you will move here os and json - See comment below)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants