Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more notebook tests applications finance #790

Merged
merged 5 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 3 additions & 3 deletions applications/finance/option_pricing/option_pricing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,10 @@
],
"source": [
"measured_payoff = result_iqae.estimation * scaling_factor\n",
"condidence_interval = np.array(result_iqae.confidence_interval) * scaling_factor\n",
"confidence_interval = np.array(result_iqae.confidence_interval) * scaling_factor\n",
"\n",
"print(\"Measured Payoff:\", measured_payoff)\n",
"print(\"Confidence Interval:\", condidence_interval)"
"print(\"Confidence Interval:\", confidence_interval)"
]
},
{
Expand Down Expand Up @@ -554,7 +554,7 @@
"assert np.isclose(\n",
" measured_payoff,\n",
" expected_payoff,\n",
" atol=10 * (condidence_interval[1] - condidence_interval[0]),\n",
" atol=10 * (confidence_interval[1] - confidence_interval[0]),\n",
")"
]
},
Expand Down
28 changes: 28 additions & 0 deletions tests/notebooks/test_credit_card_fraud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from tests.utils_for_testbook import (
validate_quantum_program_size,
validate_quantum_model,
wrap_testbook,
)
from testbook.client import TestbookNotebookClient


@wrap_testbook("credit_card_fraud", timeout_seconds=1084)
def test_notebook(tb: TestbookNotebookClient) -> None:
# test models
validate_quantum_model(tb.ref("QSVM_FRAUD_BLOCH_SHPERE"))
validate_quantum_model(tb.ref("QSVM_FRAUD_PAULI_ZZ"))
# test quantum programs
validate_quantum_program_size(
tb.ref("qprog"),
expected_width=5, # actual width: 3
expected_depth=50, # actual depth: 38
)

# test notebook content

# true_labels = np.array(selected_prediction_true_labels.values.tolist())
# sklearn.metrics.accuracy_score(predicted_labels, true_labels)
accuracy = tb.ref(
"sklearn.metrics.accuracy_score(predicted_labels, np.array(selected_prediction_true_labels.values.tolist()))"
)
assert accuracy >= 0.9
23 changes: 23 additions & 0 deletions tests/notebooks/test_option_pricing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from tests.utils_for_testbook import (
validate_quantum_program_size,
validate_quantum_model,
wrap_testbook,
)
from testbook.client import TestbookNotebookClient


@wrap_testbook("option_pricing", timeout_seconds=140)
def test_notebook(tb: TestbookNotebookClient) -> None:
# test models
validate_quantum_model(tb.ref("qmod"))
# test quantum programs
validate_quantum_program_size(
tb.ref("qprog"),
expected_width=10, # actual width: 8
expected_depth=9500, # actual depth: 8934
)

# test notebook content
assert tb.ref(
"np.isclose(measured_payoff,expected_payoff,atol=10 * (confidence_interval[1] - confidence_interval[0]))"
)
21 changes: 21 additions & 0 deletions tests/notebooks/test_portfolio_optimization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from tests.utils_for_testbook import (
validate_quantum_program_size,
validate_quantum_model,
wrap_testbook,
)
from testbook.client import TestbookNotebookClient


@wrap_testbook("portfolio_optimization", timeout_seconds=400)
def test_notebook(tb: TestbookNotebookClient) -> None:
# test models
validate_quantum_model(tb.ref("qmod"))
# test quantum programs
validate_quantum_program_size(
tb.ref("qprog"),
expected_width=15, # actual width: 12
expected_depth=300, # actual depth: 217
)

# test notebook content
pass # todo
Loading