Skip to content

Commit

Permalink
Test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam-XiaoyueLi committed May 21, 2024
1 parent b997251 commit 976989e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
17 changes: 1 addition & 16 deletions src/qibo/models/dbi/group_commutator_iteration_transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ class DoubleBracketRotationType(Enum):
group_commutator = auto()
"""Use group commutator approximation"""

group_commutator_reordered = auto()
"""Use group commutator approximation with reordering of the operators"""

group_commutator_reduced = auto()
"""Use group commutator approximation with a reduction using symmetry
Expand Down Expand Up @@ -184,19 +181,7 @@ def group_commutator(
eo1.circuit(-s_step),
eo2.circuit(s_step),
]
elif gc_type is DoubleBracketRotationType.group_commutator_reordered:
query_list_forward = [
eo1.circuit(s_step),
eo2.circuit(-s_step),
eo1.circuit(-s_step),
eo2.circuit(s_step),
]
query_list_backward = [
eo2.circuit(-s_step),
eo1.circuit(s_step),
eo2.circuit(s_step),
eo1.circuit(-s_step),
]

elif gc_type is DoubleBracketRotationType.group_commutator_reduced:
query_list_forward = [
eo1.circuit(s_step),
Expand Down
24 changes: 17 additions & 7 deletions tests/test_models_dbi.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,6 @@ def test_gci_evolution_oracles_types_numerical(

assert norm(j_1 - k_1) < 1e-10

# when gci mode is single_commutator, an error should be raised:
with pytest.raises(ValueError):
gci.mode_double_bracket_rotation = DoubleBracketRotationType.single_commutator
u_gc_from_oracles = gci.group_commutator(
t_step, evolution_oracle_diagonal_target
)

# compare DoubleBracketRotationType.group_commutator_reduced and group_commutator
gci = GroupCommutatorIterationWithEvolutionOracles(deepcopy(evolution_oracle))
u_gc_from_oracles = gci.group_commutator(
Expand Down Expand Up @@ -263,6 +256,23 @@ def test_gci_evolution_oracles_types_numerical(
)
assert norm(h_update_gc - h_update_gc_reduced) < 1e-10

# when gci mode is single_commutator, an error should be raised:
with pytest.raises(ValueError):
gci.mode_double_bracket_rotation = DoubleBracketRotationType.single_commutator
u_gc_from_oracles = gci.group_commutator(
t_step, evolution_oracle_diagonal_target
)

# when gci eo_mode is unrecognized, an errorr should be raised:
with pytest.raises(ValueError):
gci.mode_double_bracket_rotation = DoubleBracketRotationType.group_commutator
evolution_oracle_diagonal_target = EvolutionOracle(
d_0, "D0", mode_evolution_oracle=DoubleBracketRotationType.group_commutator
)
u_gc_from_oracles = gci.group_commutator(
t_step, evolution_oracle_diagonal_target
)


@pytest.mark.parametrize("nqubits", [3])
@pytest.mark.parametrize(
Expand Down

0 comments on commit 976989e

Please sign in to comment.