Skip to content
Closed
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
8 changes: 8 additions & 0 deletions docs/concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ A *quantum neural network* (QNN) is used to describe a parameterized quantum
computational model that is best executed on a quantum computer. This term is
often interchangeable with *parameterized quantum circuit* (PQC).

#### Saving models

Note: `model.save()` does not work for TensorFlow Quantum models containing
custom quantum layers, because full model serialization requires the layer
to be reconstructable without the original Python code. Instead, use
`model.save_weights()` to save the trained parameters, then rebuild the model
architecture in Python and restore them with `model.load_weights()`.
Comment on lines +90 to +94

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is incorrect in multiple ways.

  • Using the term "custom quantum layers" here is misleading. In Keras terminology, "custom layers" refers to user-defined tf.keras.layers.Layer subclasses. model.save() fails on TFQ's built-in layers. Referring to them as "custom quantum layers" implies that built-in TFQ layers support model.save() and only user-subclassed layers fail.

  • Stating "because full model serialization requires the layer to be reconstructable without the original Python code" describes the purpose of model.save(), not why it fails in TFQ. It fails because TFQ layers accept non-TensorFlow objects (such as cirq.Circuit and cirq.PauliSum) in __init__ and do not implement Keras's get_config() method.

  • The whole motivation for #899 (from #56) is that model.save() fails with an uninformative NotEncodableError or NotImplementedError (mentioning get_config). This doesn't actually help the user.

  • The file docs/concepts.md ("Quantum machine learning concepts") is a high-level conceptual overview of quantum computing, quantum data, and QML research. It contains no code snippets or Keras/TFQ API references. Dropping a #### Saving models subsection referencing model.save(), model.save_weights(), and model.load_weights() here does not fit the surrounding document context.



## Research

Expand Down
3 changes: 3 additions & 0 deletions scripts/ci_validate_tutorials.sh

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A recent fix in the main branch solves the notebook test failures. You can remove the changes to this file. (BTW, this would have mixed two unrelated types of changes into one PR, which is bad practice.)

Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ pip install gymnasium[classic-control]==1.2.3
pip install seaborn==0.12.0
# tf_docs pip package needed for noise tutorial.
pip install -q git+https://github.com/tensorflow/docs
# pydot and graphviz needed for tf.keras.utils.plot_model in tutorials
pip install pydot
sudo apt-get install -y graphviz
# Leave the quantum directory, otherwise errors may occur
cd ..

Expand Down
Loading