def test_get_samples_inputs(self):
     """Test that get_samples only accepts inputs it should."""
     circuit_execution_ops.get_sampling_op()
     circuit_execution_ops.get_sampling_op(backend=cirq.Simulator())
     circuit_execution_ops.get_sampling_op(
         backend=cirq.DensityMatrixSimulator())
     mock_engine = mock.Mock()
     circuit_execution_ops.get_sampling_op(
         backend=cirq.google.QuantumEngineSampler(engine=mock_engine,
                                                  processor_id='test',
                                                  gate_set=cirq.google.XMON))
     with self.assertRaisesRegex(TypeError,
                                 expected_regex="Expected a Cirq.Sampler"):
         circuit_execution_ops.get_sampling_op(backend="junk")
Ejemplo n.º 2
0
    def __init__(self, backend='noiseless', **kwargs):
        """Instantiate this Layer.

        Create a layer that will output bitstring samples taken from either a
        simulated quantum state or a real quantum computer

        Args:
            backend: Optional Backend to use to simulate this state. Defaults
                to the noiseless simulator. Options are {'noisy', 'noiseless'},
                however users may also specify a preconfigured cirq execution
                object to use instead, which must inherit `cirq.Sampler`.
        """
        super().__init__(**kwargs)
        used_op = None
        if backend == 'noiseless':
            used_op = circuit_execution_ops.get_sampling_op(None)
        elif backend == 'noisy':
            used_op = noisy_samples_op.samples
        else:
            used_op = circuit_execution_ops.get_sampling_op(backend)

        self.sample_op = used_op
Ejemplo n.º 3
0
    def __init__(self, backend=None, **kwargs):
        """Instantiate this Layer.

        Create a layer that will output bitstring samples taken from either a
        simulated quantum state or a real quantum computer

        Args:
            backend: Optional Backend to use to simulate this state. Defaults
                to the native Tensorflow simulator (None), however users may
                also specify a preconfigured cirq execution object to use
                instead, which must inherit `cirq.Sampler`.
        """
        super().__init__(**kwargs)
        self.sample_op = circuit_execution_ops.get_sampling_op(backend)
Ejemplo n.º 4
0
# Number of random circuits to use in a test batch.
BATCH_SIZE = 15

# These get used everywhere
WF_SIM = cirq.sim.sparse_simulator.Simulator()
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)
]
DM_SIM = cirq.sim.density_matrix_simulator.DensityMatrixSimulator()

EXPECTATION_OPS = [
    circuit_execution_ops.get_expectation_op(backend=None,
                                             quantum_concurrent=True),
    circuit_execution_ops.get_expectation_op(backend=WF_SIM,
                                             quantum_concurrent=True),
    circuit_execution_ops.get_expectation_op(backend=DM_SIM,
                                             quantum_concurrent=True),
    # For timing interests C++ backend is tested in quantum_concurrent mode.
    circuit_execution_ops.get_expectation_op(backend=None,
                                             quantum_concurrent=False)
]

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)