-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from Jij-Inc/hotfix/qrao_linear_case
Hotfix/qrao linear case
- Loading branch information
Showing
5 changed files
with
129 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import jijmodeling_transpiler_quantum.qiskit as jtq | ||
from jijmodeling_transpiler_quantum.core.ising_qubo import IsingModel | ||
from jijmodeling_transpiler_quantum.core.qrac import ( | ||
greedy_graph_coloring, | ||
check_linear_term, | ||
) | ||
from jijmodeling_transpiler_quantum.qiskit.qrao import ( | ||
qrac31_encode_ising, | ||
qrac21_encode_ising, | ||
) | ||
|
||
|
||
def test_check_linear_term(): | ||
ising = IsingModel({(0, 1): 2.0, (0, 2): 1.0}, {2: 5.0, 3: 2.0}, 6.0) | ||
max_color_group_size = 3 | ||
_, color_group = greedy_graph_coloring( | ||
ising.quad.keys(), max_color_group_size=max_color_group_size | ||
) | ||
color_group = check_linear_term( | ||
color_group, ising.linear.keys(), max_color_group_size | ||
) | ||
|
||
qrac_hamiltonian, offset, encoding = qrac31_encode_ising( | ||
ising, color_group | ||
) | ||
|
||
ising = IsingModel( | ||
{(0, 1): 2.0, (0, 2): 1.0}, | ||
{2: 5.0, 3: 2.0, 4: 1.0, 5: 1.0, 6: 1.0}, | ||
6.0, | ||
) | ||
max_color_group_size = 3 | ||
_, color_group = greedy_graph_coloring( | ||
ising.quad.keys(), max_color_group_size=max_color_group_size | ||
) | ||
color_group = check_linear_term( | ||
color_group, ising.linear.keys(), max_color_group_size | ||
) | ||
|
||
qrac_hamiltonian, offset, encoding = qrac31_encode_ising( | ||
ising, color_group | ||
) | ||
|
||
ising = IsingModel( | ||
{(0, 1): 2.0, (0, 2): 1.0}, | ||
{2: 5.0, 3: 2.0, 4: 1.0, 5: 1.0, 6: 1.0}, | ||
6.0, | ||
) | ||
max_color_group_size = 2 | ||
_, color_group = greedy_graph_coloring( | ||
ising.quad.keys(), max_color_group_size=max_color_group_size | ||
) | ||
color_group = check_linear_term( | ||
color_group, ising.linear.keys(), max_color_group_size | ||
) | ||
|
||
qrac_hamiltonian, offset, encoding = qrac21_encode_ising( | ||
ising, color_group | ||
) |