def test_correct_padding(self):
        """Test the variable sized circuits are properly padded."""
        symbol_names = []
        batch_size = 2
        n_qubits = 5
        qubits1 = cirq.GridQubit.rect(1, n_qubits)
        qubits2 = cirq.GridQubit.rect(1, n_qubits + 1)

        circuit_batch1, resolver_batch1 = \
            util.random_circuit_resolver_batch(
                qubits1, batch_size, include_channels=True)

        circuit_batch2, resolver_batch2 = \
            util.random_circuit_resolver_batch(
                qubits2, batch_size, include_channels=True)

        p1 = [[resolver[symbol]
               for symbol in symbol_names]
              for resolver in resolver_batch1]
        p2 = [[resolver[symbol]
               for symbol in symbol_names]
              for resolver in resolver_batch2]
        symbol_values_array = np.array(p1 + p2)

        n_samples = 10

        op_samples = noisy_samples_op.samples(
            util.convert_to_tensor(circuit_batch1 + circuit_batch2),
            symbol_names, symbol_values_array, [n_samples]).to_list()
        a_reps = np.asarray(op_samples[:2])
        b_reps = np.asarray(op_samples[2:])
        self.assertEqual(a_reps.shape, (2, 10, 5))
        self.assertEqual(b_reps.shape, (2, 10, 6))
    def test_correctness_without_symbols(self, n_qubits, batch_size,
                                         inner_dim_size):
        """Test that inner_product works with symbols."""
        qubits = cirq.GridQubit.rect(1, n_qubits)
        circuit_batch, _ = \
            util.random_circuit_resolver_batch(
                qubits, batch_size)

        other_batch = [
            util.random_circuit_resolver_batch(qubits, inner_dim_size)[0]
            for i in range(batch_size)
        ]

        programs = util.convert_to_tensor(circuit_batch)
        other_programs = util.convert_to_tensor(other_batch)
        symbol_names = tf.convert_to_tensor([], dtype=tf.dtypes.string)
        symbol_values = tf.convert_to_tensor([[] for _ in range(batch_size)])

        out = inner_product_op.inner_product(programs, symbol_names,
                                             symbol_values, other_programs)

        out_arr = np.empty((batch_size, inner_dim_size), dtype=np.complex64)
        for i in range(batch_size):
            final_wf = cirq.final_state_vector(circuit_batch[i])
            for j in range(inner_dim_size):
                internal_wf = cirq.final_state_vector(other_batch[i][j])
                out_arr[i][j] = np.vdot(final_wf, internal_wf)

        self.assertAllClose(out, out_arr)
Beispiel #3
0
    def test_tf_gradient_correctness_without_symbols(self, n_qubits, batch_size,
                                                     inner_dim_size):
        """Tests that tf.gradient of inner_product works without symbols."""
        qubits = cirq.GridQubit.rect(1, n_qubits)
        circuit_batch, _ = \
            util.random_circuit_resolver_batch(
                qubits, batch_size)

        other_batch = [
            util.random_circuit_resolver_batch(qubits, inner_dim_size)[0]
            for i in range(batch_size)
        ]

        programs = util.convert_to_tensor(circuit_batch)
        other_programs = util.convert_to_tensor(other_batch)
        symbol_names = tf.convert_to_tensor([], dtype=tf.dtypes.string)
        symbol_values = tf.convert_to_tensor([[] for _ in range(batch_size)])

        with tf.GradientTape() as tape:
            tape.watch(symbol_values)
            ip = fidelity_op.fidelity(programs, symbol_names, symbol_values,
                                      other_programs)
        out = tape.gradient(ip, symbol_values)
        self.assertAllClose(out, tf.zeros_like(symbol_values), atol=1e-3)
        self.assertDTypeEqual(out, tf.float32.as_numpy_dtype)
Beispiel #4
0
    def test_simulate_state_output_padding(self, all_n_qubits):
        """If a tfq_simulate op is asked to simulate states given circuits
        acting on different numbers of qubits, the op should return a tensor
        padded with zeros up to the size of the largest circuit. The padding
        should be physically correct, such that samples taken from the padded
        states still match samples taken from the original circuit. """
        circuit_batch = []
        for n_qubits in all_n_qubits:
            qubits = cirq.GridQubit.rect(1, n_qubits)
            circuit_batch += util.random_circuit_resolver_batch(qubits, 1)[0]

        tfq_results = tfq_simulate_ops.tfq_simulate_state(
            util.convert_to_tensor(circuit_batch), [],
            [[]] * len(circuit_batch))

        # Don't use batch_util here to enforce consistent padding everywhere
        # without extra tests.
        sim = cirq.Simulator()
        manual_padded_results = []
        for circuit in circuit_batch:
            result = sim.simulate(circuit)
            wf = result.final_state
            blank_state = np.ones(
                (2**max(all_n_qubits)), dtype=np.complex64) * -2
            blank_state[:wf.shape[0]] = wf
            manual_padded_results.append(blank_state)

        self.assertAllClose(tfq_results, manual_padded_results)
Beispiel #5
0
    def test_single_channel(self, channel):
        """Individually test adding just a single channel type to circuits."""
        symbol_names = []
        batch_size = 5
        n_qubits = 6
        qubits = cirq.GridQubit.rect(1, n_qubits)

        circuit_batch, resolver_batch = \
            util.random_circuit_resolver_batch(
                qubits, batch_size, include_channels=False)

        for i in range(batch_size):
            circuit_batch[i] = circuit_batch[i] + channel.on_each(*qubits)

        symbol_values_array = np.array(
            [[resolver[symbol] for symbol in symbol_names]
             for resolver in resolver_batch])

        pauli_sums1 = util.random_pauli_sums(qubits, 3, batch_size)
        pauli_sums2 = util.random_pauli_sums(qubits, 3, batch_size)
        batch_pauli_sums = [[x, y] for x, y in zip(pauli_sums1, pauli_sums2)]
        num_samples = [[20000] * 2] * batch_size

        op_exps = noisy_sampled_expectation_op.sampled_expectation(
            util.convert_to_tensor(circuit_batch),
            symbol_names, symbol_values_array,
            util.convert_to_tensor(batch_pauli_sums), num_samples)

        cirq_exps = batch_util.batch_calculate_expectation(
            circuit_batch, resolver_batch, batch_pauli_sums,
            cirq.DensityMatrixSimulator())

        self.assertAllClose(cirq_exps, op_exps, atol=0.35, rtol=0.35)
    def test_single_channel(self, channel):
        """Individually test adding just a single channel type to circuits."""
        symbol_names = []
        batch_size = 3
        n_qubits = 5
        qubits = cirq.GridQubit.rect(1, n_qubits)

        circuit_batch, resolver_batch = \
            util.random_circuit_resolver_batch(
                qubits, batch_size, include_channels=False)

        for i in range(batch_size):
            circuit_batch[i] = circuit_batch[i] + channel.on_each(*qubits)

        symbol_values_array = np.array(
            [[resolver[symbol]
              for symbol in symbol_names]
             for resolver in resolver_batch])

        n_samples = (2**n_qubits) * 1000

        op_samples = noisy_samples_op.samples(
            util.convert_to_tensor(circuit_batch), symbol_names,
            symbol_values_array, [n_samples]).to_list()
        op_hists = self._compute_hists(op_samples, n_qubits)

        cirq_samples = batch_util.batch_sample(circuit_batch, resolver_batch,
                                               n_samples,
                                               cirq.DensityMatrixSimulator())
        cirq_hists = self._compute_hists(cirq_samples, n_qubits)

        for a, b in zip(op_hists, cirq_hists):
            self.assertLess(stats.entropy(a + 1e-8, b + 1e-8), 0.15)
Beispiel #7
0
    def test_correctness_with_symbols(self, n_qubits, batch_size,
                                      inner_dim_size):
        """Tests that inner_product works with symbols."""
        symbol_names = ['alpha', 'beta', 'gamma']
        n_params = len(symbol_names)
        qubits = cirq.GridQubit.rect(1, n_qubits)
        circuit_batch, resolver_batch = \
          util.random_symbol_circuit_resolver_batch(
              qubits, symbol_names, batch_size)

        other_batch = [
            util.random_circuit_resolver_batch(qubits, inner_dim_size)[0]
            for i in range(batch_size)
        ]

        symbol_values_array = np.array(
            [[resolver[symbol] for symbol in symbol_names]
             for resolver in resolver_batch])

        programs = util.convert_to_tensor(circuit_batch)
        other_programs = util.convert_to_tensor(other_batch)
        symbol_names_tensor = tf.convert_to_tensor(symbol_names,
                                                   dtype=tf.dtypes.string)
        symbol_values = tf.convert_to_tensor(symbol_values_array)
        prev_grad = tf.cast(tf.random.normal((batch_size, inner_dim_size)),
                            tf.complex64)

        out = inner_product_op._inner_product_grad(programs,
                                                   symbol_names_tensor,
                                                   symbol_values,
                                                   other_programs, prev_grad)

        out_arr = np.zeros((batch_size, n_params), dtype=np.complex64)
        # dx came from _GRAD_EPS of core/src/adj_util.cc
        dx = 5e-3
        for i, resolver in enumerate(resolver_batch):
            for k, name in enumerate(symbol_names):
                if name in resolver.param_dict:
                    new_resolver = copy.deepcopy(resolver)
                    new_resolver.param_dict[name] += dx
                    final_circuit_p = cirq.resolve_parameters(
                        circuit_batch[i], new_resolver)
                    new_resolver = copy.deepcopy(resolver)
                    new_resolver.param_dict[name] -= dx
                    final_circuit_m = cirq.resolve_parameters(
                        circuit_batch[i], new_resolver)
                    final_wf_p = cirq.final_state_vector(final_circuit_p)
                    final_wf_m = cirq.final_state_vector(final_circuit_m)
                    # Performs central finite difference.
                    final_wf_grad = 0.5 * (final_wf_p - final_wf_m) / dx
                    for j, other in enumerate(other_batch[i]):
                        internal_wf = cirq.final_state_vector(other)
                        out_arr[i][k] += (prev_grad[i][j] *
                                          np.vdot(final_wf_grad, internal_wf))

        self.assertAllClose(out, np.conj(out_arr), atol=1e-3)
Beispiel #8
0
    def test_calculate_unitary_consistency_symbol_free(self, n_qubits):
        """Test calculate_unitary works without symbols."""
        qubits = cirq.GridQubit.rect(1, n_qubits)
        circuit_batch, _ = util.random_circuit_resolver_batch(qubits, 25)

        tfq_results = tfq_unitary_op.calculate_unitary(
            util.convert_to_tensor(circuit_batch), [],
            [[]] * len(circuit_batch))

        results = [cirq.unitary(circuit) for circuit in circuit_batch]

        self.assertAllClose(tfq_results, results, atol=1e-5)
Beispiel #9
0
    def test_simulate_state_output_padding(self, op_and_sim, all_n_qubits):
        """If a circuit executing op is asked to simulate states given circuits
        acting on different numbers of qubits, the op should return a tensor
        padded with zeros up to the size of the largest circuit. The padding
        should be physically correct, such that samples taken from the padded
        states still match samples taken from the original circuit."""
        op = op_and_sim[0]
        sim = op_and_sim[1]

        circuit_batch = []
        for n_qubits in all_n_qubits:
            qubits = cirq.GridQubit.rect(1, n_qubits)
            circuit_batch += util.random_circuit_resolver_batch(qubits, 1)[0]

        tfq_results = op(util.convert_to_tensor(circuit_batch), [],
                         [[]] * len(circuit_batch))

        # don't use batch_util here to enforce consistent padding everywhere
        # without extra tests
        manual_padded_results = []
        for circuit in circuit_batch:
            result = sim.simulate(circuit)

            # density matricies should be zero everywhere except for the
            # top left corner
            if isinstance(
                    result, cirq.sim.density_matrix_simulator.
                    DensityMatrixTrialResult):
                dm = result.final_density_matrix
                blank_state = np.ones(
                    (2**max(all_n_qubits), 2**(max(all_n_qubits))),
                    dtype=np.complex64) * -2
                blank_state[:dm.shape[0], :dm.shape[1]] = dm
                manual_padded_results.append(blank_state)

            # wavefunctions should be zero everywhere to the right of the states
            # present in this system
            elif isinstance(
                    result,
                    cirq.sim.wave_function_simulator.WaveFunctionTrialResult):
                wf = result.final_state
                blank_state = np.ones(
                    (2**max(all_n_qubits)), dtype=np.complex64) * -2
                blank_state[:wf.shape[0]] = wf
                manual_padded_results.append(blank_state)

            else:
                # TODO
                raise RuntimeError(
                    'Simulator returned unknown type of result.')

        self.assertAllClose(tfq_results, manual_padded_results)
Beispiel #10
0
    def test_simulate_state_no_symbols(self, op_and_sim, n_qubits):
        """Compute states using cirq and tfq without symbols."""
        op = op_and_sim[0]
        sim = op_and_sim[1]

        circuit_batch, resolver_batch = util.random_circuit_resolver_batch(
            cirq.GridQubit.rect(1, n_qubits), BATCH_SIZE)

        op_states = op(util.convert_to_tensor(circuit_batch), [],
                       [[]] * BATCH_SIZE).to_list()
        cirq_states = batch_util.batch_calculate_state(circuit_batch,
                                                       resolver_batch, sim)

        self.assertAllClose(cirq_states, op_states, atol=1e-5, rtol=1e-5)
Beispiel #11
0
    def test_correctness_without_symbols(self, n_qubits, batch_size,
                                         inner_dim_size):
        """Tests that inner_product_adj_grad works without symbols."""
        qubits = cirq.GridQubit.rect(1, n_qubits)
        circuit_batch, _ = \
          util.random_circuit_resolver_batch(
              qubits, batch_size)

        other_batch = [
            util.random_circuit_resolver_batch(qubits, inner_dim_size)[0]
            for i in range(batch_size)
        ]

        programs = util.convert_to_tensor(circuit_batch)
        other_programs = util.convert_to_tensor(other_batch)
        symbol_names = tf.convert_to_tensor([], dtype=tf.dtypes.string)
        symbol_values = tf.convert_to_tensor([[] for _ in range(batch_size)])
        prev_grad = np.ones((batch_size, inner_dim_size))

        with self.assertRaisesRegex(tf.errors.InvalidArgumentError,
                                    'symbols must be a positive integer'):
            inner_product_op._inner_product_grad(programs, symbol_names,
                                                 symbol_values, other_programs,
                                                 prev_grad)
Beispiel #12
0
    def test_calculate_unitary_output_padding(self, all_n_qubits):
        """If calculate_unitary is asked to calculate matrices given circuits
        acting on different numbers of qubits, the op should return a tensor
        padded with zeros up to the size of the largest circuit."""
        circuit_batch = []
        for n_qubits in all_n_qubits:
            qubits = cirq.GridQubit.rect(1, n_qubits)
            circuit_batch += util.random_circuit_resolver_batch(qubits, 1)[0]

        tfq_results = tfq_unitary_op.calculate_unitary(
            util.convert_to_tensor(circuit_batch), [],
            [[]] * len(circuit_batch))

        results = [cirq.unitary(circuit) for circuit in circuit_batch]

        self.assertAllClose(tfq_results.to_list(), results, atol=1e-5)
    def test_simulate_state_large(self, op_and_sim):
        """Test a reasonably large and complex circuit."""
        op, sim = op_and_sim
        symbol_names = []
        circuit_batch, resolver_batch = \
            util.random_circuit_resolver_batch(
                cirq.GridQubit.rect(4, 4), 5)

        symbol_values_array = np.array(
            [[resolver[symbol] for symbol in symbol_names]
             for resolver in resolver_batch]).astype(np.float32)

        op_states = op(util.convert_to_tensor(circuit_batch), symbol_names,
                       symbol_values_array).to_list()

        cirq_states = batch_util.batch_calculate_state(circuit_batch,
                                                       resolver_batch, sim)

        self.assertAllClose(cirq_states, op_states, atol=1e-5, rtol=1e-5)
Beispiel #14
0
    def test_correctness_with_symbols(self, n_qubits, batch_size,
                                      inner_dim_size):
        """Tests that inner_product works with symbols."""
        symbol_names = ['alpha', 'beta', 'gamma']
        qubits = cirq.GridQubit.rect(1, n_qubits)
        circuit_batch, resolver_batch = \
            util.random_symbol_circuit_resolver_batch(
                qubits, symbol_names, batch_size)

        other_batch = [
            util.random_circuit_resolver_batch(qubits, inner_dim_size)[0]
            for i in range(batch_size)
        ]

        symbol_values_array = np.array(
            [[resolver[symbol]
              for symbol in symbol_names]
             for resolver in resolver_batch])

        programs = util.convert_to_tensor(circuit_batch)
        other_programs = util.convert_to_tensor(other_batch)
        symbol_names = tf.convert_to_tensor(symbol_names,
                                            dtype=tf.dtypes.string)
        symbol_values = tf.convert_to_tensor(symbol_values_array)

        out = fidelity_op.fidelity(programs, symbol_names, symbol_values,
                                   other_programs)

        out_arr = np.empty((batch_size, inner_dim_size), dtype=np.complex64)
        for i in range(batch_size):
            final_circuit = cirq.resolve_parameters(circuit_batch[i],
                                                    resolver_batch[i])
            final_wf = cirq.final_state_vector(final_circuit)
            for j in range(inner_dim_size):
                internal_wf = cirq.final_state_vector(other_batch[i][j])
                out_arr[i][j] = np.abs(np.vdot(final_wf, internal_wf))**2

        self.assertAllClose(out, out_arr, atol=1e-5)
        self.assertDTypeEqual(out, tf.float32.as_numpy_dtype)
    def test_inner_product_inputs(self):
        """Make sure that inner_product fails gracefully on bad inputs."""
        n_qubits = 5
        batch_size = 5
        symbol_names = ['alpha']
        qubits = cirq.GridQubit.rect(1, n_qubits)
        circuit_batch, resolver_batch = \
            util.random_symbol_circuit_resolver_batch(
                qubits, symbol_names, batch_size)

        symbol_values_array = np.array(
            [[resolver[symbol] for symbol in symbol_names]
             for resolver in resolver_batch])

        other_batch = [
            util.random_circuit_resolver_batch(qubits, 3)[0]
            for i in range(batch_size)
        ]

        with self.assertRaisesRegex(tf.errors.InvalidArgumentError,
                                    'programs must be rank 1'):
            # Circuit tensor has too many dimensions.
            inner_product_op.inner_product(
                util.convert_to_tensor([circuit_batch]), symbol_names,
                symbol_values_array, util.convert_to_tensor(other_batch))

        with self.assertRaisesRegex(tf.errors.InvalidArgumentError,
                                    'symbol_names must be rank 1.'):
            # symbol_names tensor has too many dimensions.
            inner_product_op.inner_product(
                util.convert_to_tensor(circuit_batch),
                np.array([symbol_names]), symbol_values_array,
                util.convert_to_tensor(other_batch))

        with self.assertRaisesRegex(tf.errors.InvalidArgumentError,
                                    'symbol_values must be rank 2.'):
            # symbol_values_array tensor has too many dimensions.
            inner_product_op.inner_product(
                util.convert_to_tensor(circuit_batch), symbol_names,
                np.array([symbol_values_array]),
                util.convert_to_tensor(other_batch))

        with self.assertRaisesRegex(tf.errors.InvalidArgumentError,
                                    'symbol_values must be rank 2.'):
            # symbol_values_array tensor has too few dimensions.
            inner_product_op.inner_product(
                util.convert_to_tensor(circuit_batch), symbol_names,
                symbol_values_array[0], util.convert_to_tensor(other_batch))

        with self.assertRaisesRegex(tf.errors.InvalidArgumentError,
                                    'other_programs must be rank 2.'):
            # other_programs tensor has too few dimensions.
            inner_product_op.inner_product(
                util.convert_to_tensor(circuit_batch), symbol_names,
                symbol_values_array, util.convert_to_tensor(circuit_batch))

        with self.assertRaisesRegex(tf.errors.InvalidArgumentError,
                                    'other_programs must be rank 2.'):
            # pauli_sums tensor has too many dimensions.
            inner_product_op.inner_product(
                util.convert_to_tensor(circuit_batch), symbol_names,
                symbol_values_array,
                util.convert_to_tensor([[x] for x in other_batch]))

        with self.assertRaisesRegex(tf.errors.InvalidArgumentError,
                                    'Unparseable proto'):
            # circuit tensor has the right type but invalid values.
            inner_product_op.inner_product(['junk'] * batch_size, symbol_names,
                                           symbol_values_array,
                                           util.convert_to_tensor(other_batch))

        with self.assertRaisesRegex(tf.errors.InvalidArgumentError,
                                    'Could not find symbol in parameter map'):
            # symbol_names tensor has the right type but invalid values.
            inner_product_op.inner_product(
                util.convert_to_tensor(circuit_batch), ['junk'],
                symbol_values_array, util.convert_to_tensor(other_batch))

        with self.assertRaisesRegex(tf.errors.InvalidArgumentError,
                                    'not found in reference circuit'):
            # other_programs tensor has the right type but operates on
            # qubits that the reference ciruit doesn't have.
            new_qubits = [cirq.GridQubit(5, 5), cirq.GridQubit(9, 9)]
            new_circuits, _ = util.random_circuit_resolver_batch(
                new_qubits, batch_size)
            inner_product_op.inner_product(
                util.convert_to_tensor(circuit_batch), symbol_names,
                symbol_values_array,
                util.convert_to_tensor([[x] for x in new_circuits]))

        with self.assertRaisesRegex(tf.errors.InvalidArgumentError,
                                    'not found in paired circuit'):
            # other_programs tensor has the right type but operates on
            # qubits that the reference ciruit doesn't have.
            new_qubits = cirq.GridQubit.rect(1, n_qubits - 1)
            new_circuits, _ = util.random_circuit_resolver_batch(
                new_qubits, batch_size)
            inner_product_op.inner_product(
                util.convert_to_tensor(circuit_batch), symbol_names,
                symbol_values_array,
                util.convert_to_tensor([[x] for x in new_circuits]))

        with self.assertRaisesRegex(TypeError, 'Cannot convert'):
            # circuits tensor has the wrong type.
            inner_product_op.inner_product([1.0] * batch_size, symbol_names,
                                           symbol_values_array,
                                           util.convert_to_tensor(other_batch))

        with self.assertRaisesRegex(TypeError, 'Cannot convert'):
            # symbol_names tensor has the wrong type.
            inner_product_op.inner_product(
                util.convert_to_tensor(circuit_batch), [0.1234],
                symbol_values_array, util.convert_to_tensor(other_batch))

        with self.assertRaisesRegex(tf.errors.UnimplementedError, ''):
            # symbol_values tensor has the wrong type.
            inner_product_op.inner_product(
                util.convert_to_tensor(circuit_batch), symbol_names,
                [['junk']] * batch_size, util.convert_to_tensor(other_batch))

        with self.assertRaisesRegex(TypeError, 'Cannot convert'):
            # other_programs tensor has the wrong type.
            inner_product_op.inner_product(
                util.convert_to_tensor(circuit_batch), symbol_names,
                symbol_values_array, [[1.0]] * batch_size)

        with self.assertRaisesRegex(TypeError, 'missing'):
            # we are missing an argument.
            # pylint: disable=no-value-for-parameter
            inner_product_op.inner_product(
                util.convert_to_tensor(circuit_batch), symbol_names,
                symbol_values_array)
            # pylint: enable=no-value-for-parameter

        with self.assertRaisesRegex(TypeError, 'positional arguments'):
            # pylint: disable=too-many-function-args
            inner_product_op.inner_product(
                util.convert_to_tensor(circuit_batch), symbol_names,
                symbol_values_array, util.convert_to_tensor(other_batch), [])

        with self.assertRaisesRegex(tf.errors.InvalidArgumentError,
                                    expected_regex='do not match'):
            # batch programs has wrong batch size.
            inner_product_op.inner_product(
                util.convert_to_tensor(circuit_batch), symbol_names,
                symbol_values_array,
                util.convert_to_tensor(other_batch[:int(batch_size * 0.5)]))

        with self.assertRaisesRegex(tf.errors.InvalidArgumentError,
                                    expected_regex='do not match'):
            # batch programs has wrong batch size.
            inner_product_op.inner_product(
                util.convert_to_tensor(circuit_batch), symbol_names,
                symbol_values_array[::int(batch_size * 0.5)],
                util.convert_to_tensor(other_batch))

        with self.assertRaisesRegex(
                tf.errors.InvalidArgumentError,
                expected_regex='Found symbols in other_programs'):
            # other_programs has symbols.
            inner_product_op.inner_product(
                util.convert_to_tensor(circuit_batch), symbol_names,
                symbol_values_array,
                util.convert_to_tensor([[x] for x in circuit_batch]))

        res = inner_product_op.inner_product(
            util.convert_to_tensor(circuit_batch), symbol_names,
            symbol_values_array.astype(np.float64),
            util.convert_to_tensor(other_batch))
        self.assertDTypeEqual(res, np.complex64)
Beispiel #16
0
def _get_mixed_batch(qubits, symbols, size):
    circuit1, resolver1 = util.random_circuit_resolver_batch(qubits, size // 2)
    circuit2, resolver2 = util.random_symbol_circuit_resolver_batch(
        qubits, symbols, size // 2)
    return circuit1 + circuit2, resolver1 + resolver2