<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/quantum/blob/v0.7.6/tensorflow_quantum/core/ops/circuit_execution_ops.py#L154-L243) |

Get a Tensorflow op that produces samples from given quantum circuits.

    tfq.get_sampling_op(
        backend=None,
        *,
        quantum_concurrent=quantum_context.get_quantum_concurrent_op_mode()
    )

This function produces a non-differentiable op that will calculate
batches of circuit samples given tensor batches of [`cirq.Circuit`](https://quantumai.google/reference/python/cirq/Circuit)s,
parameter values, and a scalar telling the op how many samples to take.

    # Simulate circuits with cirq.
    my_op = tfq.get_sampling_op(backend=cirq.sim.Simulator())
    # Simulate circuits with C++.
    my_second_op = tfq.get_sampling_op()
    # Prepare some inputs.
    qubit = cirq.GridQubit(0, 0)
    my_symbol = sympy.Symbol('alpha')
    my_circuit_tensor = tfq.convert_to_tensor(
        [cirq.Circuit(cirq.X(qubit)**my_symbol)])
    my_values = np.array([[2.0]])
    n_samples = np.array([10])
    # This op can now be run to take samples.
    output = my_second_op(
        my_circuit_tensor, ['alpha'], my_values, n_samples)
    output
    <tf.RaggedTensor [[[0], [0], [0], [0], [0], [0], [0], [0], [0], [0]]]>

<br />

<br />

<br />

| ## Args ||
|---|---|
| `backend` | Optional Python `object` that specifies what backend this op should use when evaluating circuits. Can be any [`cirq.Sampler`](https://quantumai.google/reference/python/cirq/Sampler). If not provided the default C++ sampling op is returned. |
| `quantum_concurrent` | Optional Python `bool`. True indicates that the returned op should not block graph level parallelism on itself when executing. False indicates that graph level parallelism on itself should be blocked. Defaults to value specified in [`tfq.get_quantum_concurrent_op_mode`](https://www.tensorflow.org/quantum/api_docs/python/tfq/get_quantum_concurrent_op_mode) which defaults to True (no blocking). This flag is only needed for advanced users when using TFQ for very large simulations, or when running on a real chip. |

<br />

<br />

| ## Returns ||
|---|---|
| A `callable` with the following signature: <br /> `op(programs, symbol_names, symbol_values, num_samples)` ||
| `programs` | [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) of strings with shape \[batch_size\] containing the string representations of the circuits to be executed. |
| `symbol_names` | [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) of strings with shape \[n_params\], which is used to specify the order in which the values in `symbol_values` should be placed inside of the circuits in `programs`. |
| `symbol_values` | [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) of real numbers with shape \[batch_size, n_params\] specifying parameter values to resolve into the circuits specified by programs, following the ordering dictated by `symbol_names`. |
| `num_samples` | [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) with one element indicating the number of samples to draw. |
| `Returns` | [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) with shape \[batch_size, num_samples, n_qubits\] that holds samples (as boolean values) for each circuit. |

<br />