-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix silent OOB params post-optimization failure (#236)
* Make Qty raise more specific OOB exception * Renamed exception to error * Added extend_bounds arg to load_best method * Made pmap better cach and raise OOB exception * Made optimizer raise error if opt params are OOB * Linting * Created test to ensure that OOB optimizations are caught * Updated changelog * Linting * Made test be more general and robust * Allow float-esque equality * Changed/set extend_bounds defaults * Use pytest.raises
- Loading branch information
1 parent
2d95723
commit f1ce409
Showing
8 changed files
with
93 additions
and
14 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
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,45 @@ | ||
import numpy as np | ||
import pytest | ||
|
||
import c3.libraries.fidelities as fidelities | ||
from c3.optimizers.optimalcontrol import OptimalControl, OptResultOOBError | ||
from examples.single_qubit_experiment import create_experiment | ||
|
||
|
||
@pytest.mark.integration | ||
def test_raises_OOB_for_bad_optimizer() -> None: | ||
exp = create_experiment() | ||
exp.set_opt_gates(["rx90p[0]"]) | ||
|
||
opt_gates = ["rx90p[0]"] | ||
gateset_opt_map = [ | ||
[ | ||
("rx90p[0]", "d1", "carrier", "framechange"), | ||
], | ||
[ | ||
("rx90p[0]", "d1", "gauss", "amp"), | ||
], | ||
[ | ||
("rx90p[0]", "d1", "gauss", "freq_offset"), | ||
], | ||
] | ||
|
||
exp.pmap.set_opt_map(gateset_opt_map) | ||
|
||
def bad_alg(x_init, fun, *args, **kwargs): | ||
res = np.array([x * -99 for x in x_init]) | ||
fun(res) | ||
return res | ||
|
||
opt = OptimalControl( | ||
fid_func=fidelities.unitary_infid_set, | ||
fid_subspace=["Q1"], | ||
pmap=exp.pmap, | ||
algorithm=bad_alg, | ||
) | ||
|
||
exp.set_opt_gates(opt_gates) | ||
opt.set_exp(exp) | ||
|
||
with pytest.raises(OptResultOOBError): | ||
opt.optimize_controls() |
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