def test_traits_enforced(self): """Sample composers require `problem`, `samples` and `subsamples`.""" with self.assertRaises(traits.StateTraitMissingError): IdentityComposer().run(State()).result() with self.assertRaises(traits.StateTraitMissingError): IdentityComposer().run(State(problem=True)).result() self.assertTrue( # problem and samples are included by default IdentityComposer().run(State(subsamples=True)).result())
def test_runnable_composition(self): runnable = IdentityDecomposer() | HybridSubproblemRunnable( TabuSampler()) | IdentityComposer() response = runnable.run(self.init_state) self.assertIsInstance(response, concurrent.futures.Future) self.assertEqual(response.result().samples.record[0].energy, -3.0)
def test_default(self): """Subsamples are copied to samples.""" state = State( subproblem=None, subsamples=SampleSet.from_samples_bqm(self.samples, self.problem)) nextstate = IdentityComposer().next(state) self.assertEqual(state.subsamples, nextstate.samples)