Skip to content

Commit 0bcd97f

Browse files
authored
Adding a QuickStart guide. (#43)
1 parent f7284c5 commit 0bcd97f

4 files changed

Lines changed: 45 additions & 8 deletions

File tree

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
- name: Run tests
3636
run: |
3737
hatch -v run test
38+
hatch -v run test_readme
3839
- name: Upload coverage data
3940
uses: actions/upload-artifact@v4
4041
with:

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,40 @@ $ pip install quantum-evolution-kernel
4242
$ pipx install quantum-evolution-kernel
4343
```
4444

45-
## Usage
45+
## QuickStart
46+
47+
```python
48+
# Load a dataset
49+
import torch_geometric.datasets as pyg_dataset
50+
og_ptcfm = pyg_dataset.TUDataset(root="dataset", name="PTC_FM")
51+
52+
# Setup a quantum feature extractor for this dataset.
53+
# In this example, we'll use QutipExtractor, to emulate a Quantum Device on our machine.
54+
import qek.data.graphs as qek_graphs
55+
import qek.data.extractors as qek_extractors
56+
extractor = qek_extractors.QutipExtractor(compiler=qek_graphs.PTCFMCompiler())
57+
58+
# Add the graphs, compile them and look at the results.
59+
extractor.add_graphs(graphs=og_ptcfm)
60+
extractor.compile()
61+
processed_dataset = extractor.run().processed_data
62+
63+
# Prepare a machine learning pipeline with Scikit Learn.
64+
from sklearn.model_selection import train_test_split
65+
from sklearn.svm import SVC
66+
67+
X = [data for data in processed_dataset] # Features
68+
y = [data.target for data in processed_dataset] # Targets
69+
X_train, X_test, y_train, y_test = train_test_split(X, y, stratify = y, test_size=0.2, random_state=42)
70+
71+
# Train a kernel
72+
from qek.kernel import QuantumEvolutionKernel as QEK
73+
kernel = QEK(mu=0.5)
74+
model = SVC(kernel=kernel, random_state=42)
75+
model.fit(X_train, y_train)
76+
```
77+
78+
## Documentation
4679

4780
We have a two parts tutorial:
4881

examples/tutorial 1 - Using a Quantum Device to Extract Machine-Learning Features.ipynb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@
122122
"#\n",
123123
"# On our test computer, the practical limit is around 10 qubits.\n",
124124
"max_qubits = 5\n",
125-
"processed_dataset = extractor.run(max_qubits=max_qubits)\n",
126-
"display(\"Extracted features from %s samples\"% (len(processed_dataset.states), ))"
125+
"processed_dataset = extractor.run(max_qubits=max_qubits).processed_data\n",
126+
"display(\"Extracted features from %s samples\"% (len(processed_dataset), ))"
127127
]
128128
},
129129
{
@@ -173,12 +173,13 @@
173173
" display(\"Compiled %s sequences\" % (len(compiled), ))\n",
174174
"\n",
175175
" # Launch the execution.\n",
176-
" processed_dataset = extractor.run()\n",
176+
" extracted = extractor.run()\n",
177177
" display(\"Work enqueued with ids %s\" % (extractor.batch_ids, ))\n",
178178
"\n",
179179
" # ...and wait for the results.\n",
180-
" await processed_dataset\n",
181-
" display(\"Extracted features from %s samples\"% (len(processed_dataset.states), ))"
180+
" await extracted\n",
181+
" processed_data = extracted.processed_data\n",
182+
" display(\"Extracted features from %s samples\"% (len(processed_data), ))"
182183
]
183184
},
184185
{

pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ dependencies = [
6262
"pytest-cov",
6363
"pytest-xdist",
6464
"pytest-asyncio",
65+
"pytest-markdown-docs",
6566
"nbconvert",
6667
"ipykernel",
6768
"pre-commit",
@@ -72,11 +73,12 @@ dependencies = [
7273
]
7374

7475
[tool.hatch.envs.default.scripts]
75-
test = "pytest -n auto --cov-report=term-missing --cov-config=pyproject.toml --cov=qek --cov=tests --ignore=./tests/test_examples.py --ignore=./tests/test_notebooks.py {args}"
76+
test = "pytest -n auto --cov-report=term-missing --cov-config=pyproject.toml --cov=qek --cov=tests --markdown-docs {args}"
77+
test_readme = "pytest --markdown-docs README.md"
7678

7779
[tool.pytest.ini_options]
7880
testpaths = ["tests"]
79-
addopts = """-vvv --cov-report=term-missing --cov-config=pyproject.toml --cov=qek --cov=tests"""
81+
addopts = """-vvv --cov-report=term-missing --cov-config=pyproject.toml --cov=qek --cov=tests --markdown-docs"""
8082
xfail_strict = true
8183
filterwarnings = [
8284
"ignore:Call to deprecated create function FieldDescriptor",

0 commit comments

Comments
 (0)