def test_get_state_inputs(self): """Test that get_states only accepts inputs it should.""" circuit_execution_ops.get_state_op() circuit_execution_ops.get_state_op(backend=cirq.Simulator()) circuit_execution_ops.get_state_op( backend=cirq.DensityMatrixSimulator()) with self.assertRaisesRegex(TypeError, expected_regex="Cirq.SimulatesFinalState"): circuit_execution_ops.get_state_op(backend="junk") with self.assertRaisesRegex(TypeError, expected_regex="Cirq.SimulatesFinalState"): mock_engine = mock.Mock() circuit_execution_ops.get_state_op( backend=cirq.google.QuantumEngineSampler( engine=mock_engine, processor_id='test', gate_set=cirq.google.XMON))
def __init__(self, backend=None, **kwargs): """Instantiate a State Layer. Create a layer that will simulate a quantum state and output it into the TensorFlow graph given a correct set of inputs. Args: backend: Optional Backend to use to simulate this state. Defaults to the native TensorFlow Quantum state vector simulator, however users may also specify a preconfigured cirq execution object to use instead, which must inherit `cirq.SimulatesFinalState`. Note that C++ Density Matrix simulation is not yet supported so to do Density Matrix simulation please use `cirq.DensityMatrixSimulator`. """ super().__init__(**kwargs) self.state_op = circuit_execution_ops.get_state_op(backend)
DM_SIM = cirq.sim.density_matrix_simulator.DensityMatrixSimulator() EXPECTATION_OPS = [ circuit_execution_ops.get_expectation_op(backend=None), circuit_execution_ops.get_expectation_op(backend=WF_SIM), circuit_execution_ops.get_expectation_op(backend=DM_SIM) ] SAMPLING_OPS = [ circuit_execution_ops.get_sampling_op(backend=None), circuit_execution_ops.get_sampling_op(backend=WF_SIM), circuit_execution_ops.get_sampling_op(backend=DM_SIM) ] STATE_OPS = [ circuit_execution_ops.get_state_op(backend=None), circuit_execution_ops.get_state_op(backend=WF_SIM), circuit_execution_ops.get_state_op(backend=DM_SIM) ] SAMPLED_EXPECTATION_OPS = [ circuit_execution_ops.get_sampled_expectation_op(backend=None), circuit_execution_ops.get_sampled_expectation_op(backend=WF_SIM), circuit_execution_ops.get_sampled_expectation_op(backend=DM_SIM) ] SIMS = [WF_SIM, WF_SIM, DM_SIM] class OpGetterInputChecks(tf.test.TestCase): """Check that the op getters handle inputs correctly."""
] SAMPLING_OPS = [ circuit_execution_ops.get_sampling_op(backend=None, quantum_concurrent=True), circuit_execution_ops.get_sampling_op(backend=WF_SIM, quantum_concurrent=True), circuit_execution_ops.get_sampling_op(backend=DM_SIM, quantum_concurrent=True), # For timing interests C++ backend is tested in quantum_concurrent mode. circuit_execution_ops.get_sampling_op(backend=None, quantum_concurrent=False) ] STATE_OPS = [ circuit_execution_ops.get_state_op(backend=None, quantum_concurrent=True), circuit_execution_ops.get_state_op(backend=WF_SIM, quantum_concurrent=True), circuit_execution_ops.get_state_op(backend=DM_SIM, quantum_concurrent=True), # For timing interests C++ backend is tested in quantum_concurrent mode. circuit_execution_ops.get_state_op(backend=None, quantum_concurrent=False) ] SAMPLED_EXPECTATION_OPS = [ circuit_execution_ops.get_sampled_expectation_op(backend=None, quantum_concurrent=True), circuit_execution_ops.get_sampled_expectation_op(backend=WF_SIM, quantum_concurrent=True), circuit_execution_ops.get_sampled_expectation_op(backend=DM_SIM, quantum_concurrent=True), # For timing interests C++ backend is tested in quantum_concurrent mode. circuit_execution_ops.get_sampled_expectation_op(backend=None,