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

Keyword arguments for the forward simulators used in select Protocols #358

Merged
merged 22 commits into from
Jan 15, 2024

Conversation

rileyjmurray
Copy link
Collaborator

@rileyjmurray rileyjmurray commented Oct 24, 2023

There are a few Protocol classes where a call to Protocol.run(...) is significantly affected by the forward simulator used by the Protocol's model. This PR changes the signature of these run functions to allow a simulator keyword argument. This argument defaults to None. If it's non-None, then we assign it as the simulator to any relevant Model objects.

Correctness of the implementation relies the casting that happens inside the setter method Model.sim, which is handled by the classmethod ForwardSimulator.cast. I've made minor changes to this classmethod so that it can accommodate any callable that returns a ForwardSimulator object when invoked with zero arguments. I've also created a type alias (in the __init__.py file of the forwardsims subpackage) for values that are permitted in ForwardSimulator.cast.

I made small but nontrivial changes to GST.run, StandardGST.run, and ModelTest.run. I added tests to verify correctness of my changes for each of these functions.

I also made trivial changes to a few functions that served as entry points to the methods mentioned above. I didn't create separate tests for these changes.

@sserita this is ready for review

…ept_ for dealing with "target models". Need to figure out if this is me messing up or if this should be expected for some reason.
@rileyjmurray rileyjmurray changed the base branch from master to develop October 24, 2023 15:28
@rileyjmurray
Copy link
Collaborator Author

Tests are currently failing. Looks like they've been failing for a while. The failures are first observed on this CI run, which was triggered when I pushed this pair of commits.

I'll note that the earlier of the two commits in the above pair changed pytest.ini in a way that could have caused tests to run which hadn't been running before. But we actually made that change a while ago, so hard to say if this is related to the issue in a material way.

@sserita
Copy link
Contributor

sserita commented Dec 19, 2023

Thanks @rileyjmurray! I've actually started looking into the failing tests already, I agree that this may be a case of old tests being picked up that were failing. I will figure that out and push a commit as part of my review.

@coreyostrove
Copy link
Contributor

coreyostrove commented Dec 19, 2023

I've started looking into this as well. From what I can tell part of the issue is that we're picking up some base helper classes as testing classes that we shouldn't be. Here is a comparison of the output of pytest --collect-only on unit/modelmembers/test_operation.py from this branch and from the bugfix-stricter-line-label-handling branch, respectively.

<Package modelmembers>
  <Module test_operation.py>
    <UnitTestCase OpBase>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase LinearOpTester>
      <TestCaseFunction test_raise_on_invalid_method>
    <UnitTestCase DenseOpBase>
      <TestCaseFunction test_arithmetic>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_set_value_raises_on_bad_size>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase MutableDenseOpBase>
      <TestCaseFunction test_arithmetic>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_depolarize>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_element_accessors>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_rotate>
      <TestCaseFunction test_set_value>
      <TestCaseFunction test_set_value_raises_on_bad_size>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_transform>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase ImmutableDenseOpBase>
      <TestCaseFunction test_arithmetic>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_element_accessors>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_raises_on_set_value>
      <TestCaseFunction test_raises_on_transform>
      <TestCaseFunction test_set_value_raises_on_bad_size>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase DenseOpTester>
      <TestCaseFunction test_arithmetic>
      <TestCaseFunction test_convert_to_matrix_raises_on_bad_dim>
      <TestCaseFunction test_convert_to_matrix_raises_on_bad_input>
      <TestCaseFunction test_convert_to_matrix_raises_on_bad_shape>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_element_accessors>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_raises_on_set_value>
      <TestCaseFunction test_raises_on_transform>
      <TestCaseFunction test_set_value_raises_on_bad_size>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase StaticStdOpTester>
      <TestCaseFunction test_chp>
      <TestCaseFunction test_densitymx_svterm_cterm>
      <TestCaseFunction test_raises_on_bad_values>
      <TestCaseFunction test_statevec>
    <UnitTestCase FullOpTester>
      <TestCaseFunction test_arithmetic>
      <TestCaseFunction test_build_from_scratch>
      <TestCaseFunction test_convert_to_linear>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_depolarize>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_element_accessors>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_raise_on_bad_type_conversion>
      <TestCaseFunction test_raises_on_unallowed_conversion>
      <TestCaseFunction test_rotate>
      <TestCaseFunction test_set_value>
      <TestCaseFunction test_set_value_raises_on_bad_size>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_transform>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase LinearlyParamOpTester>
      <TestCaseFunction test_arithmetic>
      <TestCaseFunction test_build_from_scratch>
      <TestCaseFunction test_constructor_raises_on_real_param_constraint_violation>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_depolarize>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_element_accessors>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_rotate>
      <TestCaseFunction test_set_value>
      <TestCaseFunction test_set_value_raises_on_bad_size>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_transform>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase TPOpTester>
      <TestCaseFunction test_arithmetic>
      <TestCaseFunction test_convert>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_depolarize>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_element_accessors>
      <TestCaseFunction test_first_row_read_only>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_rotate>
      <TestCaseFunction test_set_value>
      <TestCaseFunction test_set_value_raises_on_bad_size>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_transform>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase StaticOpTester>
      <TestCaseFunction test_arithmetic>
      <TestCaseFunction test_convert>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_element_accessors>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_raises_on_set_value>
      <TestCaseFunction test_raises_on_transform>
      <TestCaseFunction test_set_value_raises_on_bad_size>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase EigenvalueParamDenseOpBase>
      <TestCaseFunction test_arithmetic>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_element_accessors>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_raises_on_set_value>
      <TestCaseFunction test_raises_on_transform>
      <TestCaseFunction test_set_value_raises_on_bad_size>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase RealEigenvalueParamDenseOpTester>
      <TestCaseFunction test_arithmetic>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_element_accessors>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_include_off_diags_in_degen_blocks>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_raises_on_set_value>
      <TestCaseFunction test_raises_on_transform>
      <TestCaseFunction test_set_value_raises_on_bad_size>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase ComplexEigenvalueParamDenseOpTester>
      <TestCaseFunction test_arithmetic>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_element_accessors>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_include_off_diags_in_degen_blocks>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_raises_on_set_value>
      <TestCaseFunction test_raises_on_transform>
      <TestCaseFunction test_set_value_raises_on_bad_size>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase LindbladErrorgenTester>
      <TestCaseFunction test_errgen_construction>
      <TestCaseFunction test_errgen_construction_from_op>
    <UnitTestCase LindbladErrorgenBase>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_transform>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase CPTPLindbladErrorgenTester>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_transform>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase DiagonalCPTPLindbladDenseOpTester>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_transform>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase CPTPLindbladSparseOpTester>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_transform>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase UnconstrainedLindbladDenseOpTester>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_transform>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase DiagonalUnconstrainedLindbladDenseOpTester>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_transform>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase UntruncatedLindbladDenseOpTester>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_transform>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase ComposedOpTester>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase EmbeddedDenseOpTester>
      <TestCaseFunction test_constructor_raises_on_state_space_label_mismatch>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase TPInstrumentOpTester>
      <TestCaseFunction test_arithmetic>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_element_accessors>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_raises_on_set_value>
      <TestCaseFunction test_raises_on_transform>
      <TestCaseFunction test_set_value_raises_on_bad_size>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase StochasticNoiseOpTester>
      <TestCaseFunction test_instance>
    <UnitTestCase DepolarizeOpTester>
      <TestCaseFunction test_depol_noise_op>
<Package modelmembers>
  <Module test_operation.py>
    <UnitTestCase LinearOpTester>
      <TestCaseFunction test_raise_on_invalid_method>
    <UnitTestCase DenseOpTester>
      <TestCaseFunction test_arithmetic>
      <TestCaseFunction test_convert_to_matrix_raises_on_bad_dim>
      <TestCaseFunction test_convert_to_matrix_raises_on_bad_input>
      <TestCaseFunction test_convert_to_matrix_raises_on_bad_shape>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_element_accessors>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_raises_on_set_value>
      <TestCaseFunction test_raises_on_transform>
      <TestCaseFunction test_set_value_raises_on_bad_size>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase StaticStdOpTester>
      <TestCaseFunction test_chp>
      <TestCaseFunction test_densitymx_svterm_cterm>
      <TestCaseFunction test_raises_on_bad_values>
      <TestCaseFunction test_statevec>
    <UnitTestCase FullOpTester>
      <TestCaseFunction test_arithmetic>
      <TestCaseFunction test_build_from_scratch>
      <TestCaseFunction test_convert_to_linear>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_depolarize>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_element_accessors>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_raise_on_bad_type_conversion>
      <TestCaseFunction test_raises_on_unallowed_conversion>
      <TestCaseFunction test_rotate>
      <TestCaseFunction test_set_value>
      <TestCaseFunction test_set_value_raises_on_bad_size>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_transform>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase LinearlyParamOpTester>
      <TestCaseFunction test_arithmetic>
      <TestCaseFunction test_build_from_scratch>
      <TestCaseFunction test_constructor_raises_on_real_param_constraint_violation>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_depolarize>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_element_accessors>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_rotate>
      <TestCaseFunction test_set_value>
      <TestCaseFunction test_set_value_raises_on_bad_size>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_transform>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase TPOpTester>
      <TestCaseFunction test_arithmetic>
      <TestCaseFunction test_convert>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_depolarize>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_element_accessors>
      <TestCaseFunction test_first_row_read_only>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_rotate>
      <TestCaseFunction test_set_value>
      <TestCaseFunction test_set_value_raises_on_bad_size>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_transform>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase StaticOpTester>
      <TestCaseFunction test_arithmetic>
      <TestCaseFunction test_convert>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_element_accessors>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_raises_on_set_value>
      <TestCaseFunction test_raises_on_transform>
      <TestCaseFunction test_set_value_raises_on_bad_size>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase RealEigenvalueParamDenseOpTester>
      <TestCaseFunction test_arithmetic>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_element_accessors>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_include_off_diags_in_degen_blocks>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_raises_on_set_value>
      <TestCaseFunction test_raises_on_transform>
      <TestCaseFunction test_set_value_raises_on_bad_size>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase ComplexEigenvalueParamDenseOpTester>
      <TestCaseFunction test_arithmetic>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_element_accessors>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_include_off_diags_in_degen_blocks>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_raises_on_set_value>
      <TestCaseFunction test_raises_on_transform>
      <TestCaseFunction test_set_value_raises_on_bad_size>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase LindbladErrorgenTester>
      <TestCaseFunction test_errgen_construction>
      <TestCaseFunction test_errgen_construction_from_op>
    <UnitTestCase CPTPLindbladErrorgenTester>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_transform>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase DiagonalCPTPLindbladDenseOpTester>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_transform>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase CPTPLindbladSparseOpTester>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_transform>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase UnconstrainedLindbladDenseOpTester>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_transform>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase DiagonalUnconstrainedLindbladDenseOpTester>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_transform>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase UntruncatedLindbladDenseOpTester>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_transform>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase ComposedOpTester>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase EmbeddedDenseOpTester>
      <TestCaseFunction test_constructor_raises_on_state_space_label_mismatch>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase TPInstrumentOpTester>
      <TestCaseFunction test_arithmetic>
      <TestCaseFunction test_copy>
      <TestCaseFunction test_deriv_wrt_params>
      <TestCaseFunction test_diamonddist>
      <TestCaseFunction test_element_accessors>
      <TestCaseFunction test_frobeniusdist>
      <TestCaseFunction test_get_dimension>
      <TestCaseFunction test_has_nonzero_hessian>
      <TestCaseFunction test_hessian_wrt_params>
      <TestCaseFunction test_jtracedist>
      <TestCaseFunction test_num_params>
      <TestCaseFunction test_pickle>
      <TestCaseFunction test_raises_on_set_value>
      <TestCaseFunction test_raises_on_transform>
      <TestCaseFunction test_set_value_raises_on_bad_size>
      <TestCaseFunction test_to_string>
      <TestCaseFunction test_torep>
      <TestCaseFunction test_tosparse>
      <TestCaseFunction test_vector_conversion>
    <UnitTestCase StochasticNoiseOpTester>
      <TestCaseFunction test_instance>
    <UnitTestCase DepolarizeOpTester>
      <TestCaseFunction test_depol_noise_op>

I ran this locally, but the behavior seems to match up with what is happening on the runners in the CI log @rileyjmurray linked to. I don't see any difference in the pytest.ini files between these two branches, so some more digging will be needed to figure out the difference.

Question for you about the pytest.ini change, btw, is the pattern matching change additive? I.e. does pytest still find things with the default 'Test' prefix on classes in addition to those suffixed by 'Tester' with this change? (I know I can empirically check this, but figured you might know off-hand).

Edit: Sorry for the very long output, is there any decent way to put blocks of test side-by-side?

Edit 2: I can confirm this isn't a pytest version thing. Syncing the pytest versions up across the two venvs on my machine didn't change anything.

@coreyostrove
Copy link
Contributor

Ok, I think I've tracked down most of the failing tests. As mentioned above it looks like we're picking up tests from helper base classes we shouldn't be. It looks like this was introduced by commit d922474. This commit made one of the helper base classes subclass off of unittest.TestCase. This results in pytest picking it up for legacy compatibility sake. Relevant section of pytest docs quoted below:

pytest supports running Python unittest-based tests out of the box. It’s meant for leveraging existing unittest-based test suites to use pytest as a test runner and also allow to incrementally adapt the test suite to take full advantage of pytest’s features.

To run an existing unittest-style test suite using pytest, type:

pytest tests

pytest will automatically collect unittest.TestCase subclasses and their test methods in test_*.py or *_test.py files.

It looks like this happens in addition to any of the other test discovery that happens. @rileyjmurray, do you remember what the motivation was for this change? Maybe we can achieve it though different means.

@rileyjmurray
Copy link
Collaborator Author

@coreyostrove I don't remember what initially prompted my change you highlighted (direct link to relevant file). OpBase was inheriting directly from object and yet it tried to access functions of the form self.assert_... that would only be available if it subclassed unittest.TestCase. But it seems that the only ...Tester classes in that file which inherit from OpBase also inherit from BaseCase(unittest.TestCase). So I suspect my change to OpBase wasn't actually needed. I've pushed a commit to revert that change. We'll see what it gets us!

@coreyostrove
Copy link
Contributor

Thanks, @rileyjmurray! I pulled up this PR to read your comment just as the newest round of tests were completed. The last failing test is a straightforward one. You have a line in one of your new tests that is referencing the non-existing attribute self.fiducials. This attribute no longer exists for the testing class built in this file, and has been refactored in this code to the class attributes prep_fids and meas_fids. i.e. if you replace this:

result = ls.run_model_test(
            self.mdl_guess, self.ds, self.pspec, self.fiducials,
            self.fiducials, self.germs, self.maxLens,
            advanced_options=dict(objective='chi2', profile=2),
            simulator=MapForwardSimulatorWrapper
        )

with this

result = ls.run_model_test(
            self.mdl_guess, self.ds, self.pspec, self.prep_fids,
            self.meas_fids, self.germs, self.maxLens,
            advanced_options=dict(objective='chi2', profile=2),
            simulator=MapForwardSimulatorWrapper
        )

I think it should do the trick.

@rileyjmurray
Copy link
Collaborator Author

@sserita @coreyostrove, tests are passing!

@sserita
Copy link
Contributor

sserita commented Dec 20, 2023

Yep I saw that! Thanks @coreyostrove for the work on fixing the tests. I had reached a similar conclusion but your answers were much more comprehensive than mine was going to be.
I'll review this later today.

@coreyostrove
Copy link
Contributor

noice

Copy link
Contributor

@sserita sserita left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor changes requested, and I'm interested to hear a little more about your thought process on ForwardSimCallable (I think it'll be mildly annoying to maintain) and the new logic for what objects you think will be passed in to cast that need to be callable.

pygsti/algorithms/core.py Show resolved Hide resolved
pygsti/forwardsims/__init__.py Outdated Show resolved Hide resolved
pygsti/forwardsims/forwardsim.py Show resolved Hide resolved
@@ -193,7 +193,7 @@ def copy(self):
self._processor_grid, self._pblk_sizes)

def create_layout(self, circuits, dataset=None, resource_alloc=None, array_types=('E',),
derivative_dimension=None, verbosity=0):
derivative_dimensions=None, verbosity=0):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: This is also a minimal exposure API change probably worth noting in changelog for 0.9.12.1.

test/unit/protocols/test_gst.py Show resolved Hide resolved
@rileyjmurray
Copy link
Collaborator Author

rileyjmurray commented Jan 2, 2024

TODOs for me:

  • Try to move the type definition for ForwardSimCastable closer to the actual cast function definition. This will require a bit of work to resolve circular imports.
  • Minor modifications responding to comments on things other than ForwardSimCastable.
  • Create a GitHub issue explaining our goal for fancy type annotations and docstrings: ideally we have an explicit docstring featuring the custom type definition doesn't fully rely on programmatic generation (good for developers in IDEs) and we have an automated ReadTheDocs workflow that substitutes custom type declarations with descriptions of those declarations.

@sserita sserita added this to the 0.9.12.1 milestone Jan 11, 2024
@rileyjmurray rileyjmurray requested review from a team as code owners January 15, 2024 19:15
@sserita sserita merged commit b6690aa into develop Jan 15, 2024
4 checks passed
@sserita sserita deleted the fwdsim-selector-protocol-run-arg branch January 15, 2024 22:32
@rileyjmurray
Copy link
Collaborator Author

rileyjmurray commented Jan 16, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants