{ "cells": [ { "cell_type": "markdown", "id": "ab95cab7-0251-429b-b032-285d99ac0120", "metadata": {}, "source": [ "# Logging\n", "\n", "The Python interface for Fulqrum has verbose logging functionality built in. Here we show an example of logging inside the Jupyter notebook from which this docuement is generated." ] }, { "cell_type": "code", "execution_count": 1, "id": "2cb548ff-572f-48ff-866e-6fdb496c06f4", "metadata": {}, "outputs": [], "source": [ "import fulqrum as fq" ] }, { "cell_type": "markdown", "id": "32711ed5-d447-4df4-b686-c0151b5dc8b7", "metadata": {}, "source": [ "## Formatting the logger\n", "\n", "Here we show how to format the logger for useful output. Importantly, when using Jupyter notebooks we need to include `force=True` in the config in order to have the logs show up in the cell output" ] }, { "cell_type": "code", "execution_count": 9, "id": "c0d613c5-e7b9-42ef-8a40-c166b014677b", "metadata": {}, "outputs": [], "source": [ "import logging\n", "\n", "logging.basicConfig(\n", " level=logging.INFO,\n", " force=True,\n", " format=\"%(asctime)s - %(levelname)s - %(name)s - %(message)s\",\n", ")" ] }, { "cell_type": "markdown", "id": "df505263-a762-46f1-8ab0-65cacdfed18e", "metadata": {}, "source": [ "## Small example\n", "\n", "Here we load a molecule, transform it, build a subspace, and finally put them all together in a `SubspaceHamiltonian`. Having set the logging config above, the ouput from each logger entry will be displayed in the cell output." ] }, { "cell_type": "code", "execution_count": 10, "id": "46c3b7e9-2bb9-459a-9be2-fd892e321003", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2026-08-19 06:59:27,767 - INFO - fulqrum.core.fermi_operator - Extended JW time: 0.758 ms\n", "2026-08-19 06:59:27,768 - INFO - fulqrum.core.subspace - Initializing Subspace\n", "2026-08-19 06:59:27,769 - INFO - fulqrum.core.subspace - Full subspace bit-strings\n", "2026-08-19 06:59:27,769 - INFO - fulqrum.core.subspace - Subspace size: 4096\n", "2026-08-19 06:59:27,769 - INFO - fulqrum.core.subspace - Number of bits: 12\n", "2026-08-19 06:59:27,769 - INFO - fulqrum.core.subspace - Using all bitset blocks: True\n", "2026-08-19 06:59:27,770 - INFO - fulqrum.core.subspace - Reserve multiplier: 2\n", "2026-08-19 06:59:27,770 - INFO - fulqrum.core.subspace - Subspace total init time: 1.587 ms\n", "2026-08-19 06:59:27,771 - INFO - fulqrum.core.linear_operator - Initializing SubspaceHamiltonian\n", "2026-08-19 06:59:27,771 - INFO - fulqrum.core.linear_operator - Number of qubits: 12\n", "2026-08-19 06:59:27,771 - INFO - fulqrum.core.linear_operator - Num. diagonal terms 78\n", "2026-08-19 06:59:27,772 - INFO - fulqrum.core.linear_operator - Num. off-diagonal terms 552\n", "2026-08-19 06:59:27,772 - INFO - fulqrum.core.qubit_operator - Term grouping time: 0.076 ms\n", "2026-08-19 06:59:27,772 - INFO - fulqrum.core.linear_operator - Term grouping time: 0.344 ms\n", "2026-08-19 06:59:27,773 - INFO - fulqrum.core.qubit_operator - Starting ladder int grouping, ladder_width = 2\n", "2026-08-19 06:59:27,773 - INFO - fulqrum.core.qubit_operator - Ladder int grouping time: 0.096 ms\n", "2026-08-19 06:59:27,773 - INFO - fulqrum.core.linear_operator - Num. off-diagonal groups: 83\n", "2026-08-19 06:59:27,774 - INFO - fulqrum.core.spmv - Initializing FulqrumSpMV\n", "2026-08-19 06:59:27,774 - INFO - fulqrum.core.spmv - Operator is real\n", "2026-08-19 06:59:27,775 - INFO - fulqrum.core.spmv - Operator type = 2\n", "2026-08-19 06:59:27,776 - INFO - fulqrum.core.spmv - FulqrumSpMV total init time: 1.683 ms\n", "2026-08-19 06:59:27,776 - INFO - fulqrum.core.linear_operator - SubspaceHamiltonian total init time: 4.945 ms\n" ] } ], "source": [ "fop = fq.FermionicOperator.from_json(\"./data/lih.json\")\n", "op = fop.extended_jw_transformation()\n", "\n", "counts = []\n", "for kk in range(2**op.width):\n", " counts.append(bin(kk)[2:].zfill(op.width))\n", "\n", "S = fq.Subspace([counts])\n", "Hsub = fq.SubspaceHamiltonian(op, S)" ] }, { "cell_type": "code", "execution_count": null, "id": "a30c27e6-6fcc-4933-8bf8-f912d14fe116", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.14.4" } }, "nbformat": 4, "nbformat_minor": 5 }