Skip to content

Commit

Permalink
docstrings for io functions
Browse files Browse the repository at this point in the history
  • Loading branch information
liuanji committed Feb 14, 2024
1 parent 187258a commit 7fa3009
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
12 changes: 11 additions & 1 deletion docs/source/python-api/pyjuice.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,14 @@ PC Compilation
:toctree: generated
:nosignatures:

compile
compile

IO
--

.. autosummary::
:toctree: generated
:nosignatures:

load
save
19 changes: 18 additions & 1 deletion src/pyjuice/io/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@


def save(fname: str, model: Union[CircuitNodes,TensorCircuit]):
"""
Save a PC to file. The file should end with ".jpc".
:param fname: file name
:type fname: str
:param model: an uncompiled (`CircuitNodes`) or compiled (`TensorCircuit`) PC
:type model: Union[CircuitNodes,TensorCircuit]
"""
if isinstance(model, TensorCircuit):
model.update_parameters()
root_ns = model.root_ns
Expand All @@ -25,7 +34,15 @@ def save(fname: str, model: Union[CircuitNodes,TensorCircuit]):
raise ValueError(f"Unknown file type `.{fname.split('.')[-1]}`.")


def load(fname: str):
def load(fname: str) -> CircuitNodes:
"""
Load a PC from file. The file should end with ".jpc".
:param fname: file name
:type fname: str
:returns: a PC node
"""
if fname.endswith(".jpc"):
with open(fname, "rb") as f:
sel_nodes = pickle.load(f)
Expand Down

0 comments on commit 7fa3009

Please sign in to comment.