Skip to content
Closed
Show file tree
Hide file tree
Changes from 15 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
1,158 changes: 1,158 additions & 0 deletions algorithms/adapt_vqe/adapt_vqe.ipynb

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions algorithms/adapt_vqe/adapt_vqe.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"friendly_name": "adapt_vqe",
"description": "Demonstration of adaptive VQE algorithm",
"qmod_type": ["algorithms"],
"problem_domain_tags": ["optimization"],
"level": ["advanced"]
}
22 changes: 22 additions & 0 deletions algorithms/adapt_vqe/adapt_vqe.qmod
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
qfunc adapt_layer_expanded___0(theta: real, qba: qbit[4]) {
suzuki_trotter(SparsePauliOp {
terms=[
SparsePauliTerm {
paulis=[
IndexedPauli {pauli=1, index=0}
],
coefficient=1.0
}
],
num_qubits=1
}, theta, 1, 1, qba);
}

qfunc adapt_vqe_ansatz_expanded___0(thetas: real[1], qba: qbit[4]) {
adapt_layer_expanded___0(thetas[0], qba);
}

qfunc main(params: real[1], output v: qbit[4]) {
allocate(4, v);
adapt_vqe_ansatz_expanded___0(params, v);
}
44 changes: 44 additions & 0 deletions algorithms/adapt_vqe/adapt_vqe.synthesis_options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"constraints": {
"max_gate_count": {},
"optimization_parameter": "no_opt"
},
"preferences": {
"custom_hardware_settings": {
"basis_gates": [
"sdg",
"s",
"ry",
"r",
"u2",
"cx",
"y",
"p",
"id",
"cz",
"sx",
"h",
"u1",
"t",
"z",
"cy",
"tdg",
"u",
"x",
"rz",
"sxdg",
"rx"
],
"is_symmetric_connectivity": true
},
"debug_mode": true,
"machine_precision": 8,
"optimization_level": 1,
"output_format": ["qasm"],
"pretty_qasm": true,
"random_seed": 4279230856,
"synthesize_all_separately": false,
"timeout_seconds": 300,
"transpilation_option": "auto optimize"
}
}
117 changes: 117 additions & 0 deletions algorithms/adapt_vqe/vqe.qmod
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
qfunc adapt_layer_expanded___0(theta: real, qba: qbit[4]) {
suzuki_trotter(SparsePauliOp {
terms=[
SparsePauliTerm {
paulis=[
IndexedPauli {pauli=1, index=0},
IndexedPauli {pauli=1, index=3}
],
coefficient=1.0
}
],
num_qubits=4
}, theta, 1, 1, qba);
}

qfunc adapt_layer_expanded___1(theta: real, qba: qbit[4]) {
suzuki_trotter(SparsePauliOp {
terms=[
SparsePauliTerm {
paulis=[
IndexedPauli {pauli=1, index=2}
],
coefficient=1.0
}
],
num_qubits=3
}, theta, 1, 1, qba);
}

qfunc adapt_layer_expanded___2(theta: real, qba: qbit[4]) {
suzuki_trotter(SparsePauliOp {
terms=[
SparsePauliTerm {
paulis=[
IndexedPauli {pauli=2, index=0}
],
coefficient=1.0
}
],
num_qubits=1
}, theta, 1, 1, qba);
}

qfunc adapt_layer_expanded___3(theta: real, qba: qbit[4]) {
suzuki_trotter(SparsePauliOp {
terms=[
SparsePauliTerm {
paulis=[
IndexedPauli {pauli=2, index=2},
IndexedPauli {pauli=1, index=0}
],
coefficient=1.0
}
],
num_qubits=3
}, theta, 1, 1, qba);
}

qfunc adapt_layer_expanded___4(theta: real, qba: qbit[4]) {
suzuki_trotter(SparsePauliOp {
terms=[
SparsePauliTerm {
paulis=[
IndexedPauli {pauli=3, index=3},
IndexedPauli {pauli=1, index=1}
],
coefficient=1.0
}
],
num_qubits=4
}, theta, 1, 1, qba);
}

qfunc adapt_layer_expanded___5(theta: real, qba: qbit[4]) {
suzuki_trotter(SparsePauliOp {
terms=[
SparsePauliTerm {
paulis=[
IndexedPauli {pauli=2, index=0},
IndexedPauli {pauli=1, index=2}
],
coefficient=1.0
}
],
num_qubits=3
}, theta, 1, 1, qba);
}

qfunc adapt_layer_expanded___6(theta: real, qba: qbit[4]) {
suzuki_trotter(SparsePauliOp {
terms=[
SparsePauliTerm {
paulis=[
IndexedPauli {pauli=3, index=2},
IndexedPauli {pauli=1, index=1}
],
coefficient=1.0
}
],
num_qubits=3
}, theta, 1, 1, qba);
}

qfunc adapt_vqe_ansatz_expanded___0(thetas: real[7], qba: qbit[4]) {
adapt_layer_expanded___0(thetas[0], qba);
adapt_layer_expanded___1(thetas[1], qba);
adapt_layer_expanded___2(thetas[2], qba);
adapt_layer_expanded___3(thetas[3], qba);
adapt_layer_expanded___4(thetas[4], qba);
adapt_layer_expanded___5(thetas[5], qba);
adapt_layer_expanded___6(thetas[6], qba);
}

qfunc main(params: real[7], output v: qbit[4]) {
allocate(4, v);
adapt_vqe_ansatz_expanded___0(params, v);
}
44 changes: 44 additions & 0 deletions algorithms/adapt_vqe/vqe.synthesis_options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"constraints": {
"max_gate_count": {},
"optimization_parameter": "no_opt"
},
"preferences": {
"custom_hardware_settings": {
"basis_gates": [
"t",
"sdg",
"s",
"cy",
"sxdg",
"x",
"y",
"z",
"p",
"u1",
"sx",
"rx",
"tdg",
"id",
"h",
"ry",
"rz",
"cz",
"r",
"cx",
"u",
"u2"
],
"is_symmetric_connectivity": true
},
"debug_mode": true,
"machine_precision": 8,
"optimization_level": 1,
"output_format": ["qasm"],
"pretty_qasm": true,
"random_seed": 2674494234,
"synthesize_all_separately": false,
"timeout_seconds": 300,
"transpilation_option": "auto optimize"
}
}
19 changes: 19 additions & 0 deletions tests/notebooks/test_adapt_vqe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from tests.utils_for_testbook import (
validate_quantum_program_size,
validate_quantum_model,
wrap_testbook,
)
from testbook.client import TestbookNotebookClient


@wrap_testbook("adapt_vqe", timeout_seconds=1800)
def test_notebook(tb: TestbookNotebookClient) -> None:
# test quantum programs
validate_quantum_program_size(
tb.ref_pydantic("qprog"),
expected_width=10, # actual width=4
expected_depth=30, # actual depth=12
)

# test notebook content
pass # Todo
1 change: 1 addition & 0 deletions tests/resources/timeouts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ U.qmod: 10
WS_iQuHack_2025_final.ipynb: 200
X.qmod: 10
adapt_qaoa.ipynb: 1799
adapt_vqe.ipynb: 1799
adapt_qaoa.qmod: 1799
add_bell_states.qmod: 10
advection_equation_2nd_place_submission.ipynb: 500
Expand Down
Loading