diff --git a/docs/tutorials/gradients.ipynb b/docs/tutorials/gradients.ipynb index 6bd011190..8922a86f7 100644 --- a/docs/tutorials/gradients.ipynb +++ b/docs/tutorials/gradients.ipynb @@ -233,8 +233,8 @@ " \"\"\"Compute ⟨Y(alpha)| `op` | Y(alpha)⟩\"\"\"\n", " params = {'alpha': alpha}\n", " sim = cirq.Simulator()\n", - " final_state = sim.simulate(my_circuit, params).final_state\n", - " return op.expectation_from_wavefunction(final_state, {qubit: 0}).real\n", + " final_state_vector = sim.simulate(my_circuit, params).final_state_vector\n", + " return op.expectation_from_state_vector(final_state_vector, {qubit: 0}).real\n", "\n", "\n", "my_alpha = 0.3\n", diff --git a/docs/tutorials/hello_many_worlds.ipynb b/docs/tutorials/hello_many_worlds.ipynb index 210e26e4d..145d1531c 100644 --- a/docs/tutorials/hello_many_worlds.ipynb +++ b/docs/tutorials/hello_many_worlds.ipynb @@ -246,7 +246,7 @@ "source": [ "# Calculate a state vector with a=0.5 and b=-0.5.\n", "resolver = cirq.ParamResolver({a: 0.5, b: -0.5})\n", - "output_state_vector = cirq.Simulator().simulate(circuit, resolver).final_state\n", + "output_state_vector = cirq.Simulator().simulate(circuit, resolver).final_state_vector\n", "output_state_vector" ] }, @@ -275,7 +275,7 @@ "\n", "qubit_map={q0: 0, q1: 1}\n", "\n", - "z0.expectation_from_wavefunction(output_state_vector, qubit_map).real" + "z0.expectation_from_state_vector(output_state_vector, qubit_map).real" ] }, { @@ -290,7 +290,7 @@ "source": [ "z0x1 = 0.5 * z0 + cirq.X(q1)\n", "\n", - "z0x1.expectation_from_wavefunction(output_state_vector, qubit_map).real" + "z0x1.expectation_from_state_vector(output_state_vector, qubit_map).real" ] }, { @@ -402,9 +402,9 @@ "\n", "for vals in batch_vals:\n", " resolver = cirq.ParamResolver({a: vals[0], b: vals[1]})\n", - " final_state = cirq_simulator.simulate(circuit, resolver).final_state\n", + " final_state_vector = cirq_simulator.simulate(circuit, resolver).final_state_vector\n", " cirq_results.append(\n", - " [z0.expectation_from_wavefunction(final_state, {\n", + " [z0.expectation_from_state_vector(final_state_vector, {\n", " q0: 0,\n", " q1: 1\n", " }).real])\n", @@ -919,8 +919,8 @@ " state = cirq_simulator.simulate(\n", " full_circuit,\n", " {s:v for (s,v) in zip(control_params, params_to_prepare_output[index])}\n", - " ).final_state\n", - " expectation = z0.expectation_from_wavefunction(state, {qubit: 0}).real\n", + " ).final_state_vector\n", + " expectation = z0.expectation_from_state_vector(state, {qubit: 0}).real\n", " print(f'For a desired output (expectation) of {desired_values[index]} with'\n", " f' noisy preparation, the controller\\nnetwork found the following '\n", " f'values for theta: {params_to_prepare_output[index]}\\nWhich gives an'\n", diff --git a/tensorflow_quantum/core/ops/batch_util.py b/tensorflow_quantum/core/ops/batch_util.py index 951e4d27b..a60c9eaa7 100644 --- a/tensorflow_quantum/core/ops/batch_util.py +++ b/tensorflow_quantum/core/ops/batch_util.py @@ -211,7 +211,7 @@ def _setup_dict(array_view, view_shape, simulator, post_process): def _state_worker_func(indices, programs, params): - """Compute the wavefunction for each program in indices.""" + """Compute the state vector for each program in indices.""" x_np = _convert_complex_view_to_np(INFO_DICT['arr'], INFO_DICT['shape']) simulator = INFO_DICT['sim'] @@ -243,7 +243,7 @@ def _analytical_expectation_worker_func(indices, programs, params, ops): continue if old_batch_index != batch_index: - # must compute a new wavefunction. + # must compute a new state vector. qubit_oder = dict( zip(sorted(programs[batch_index].all_qubits()), list(range(len(programs[batch_index].all_qubits()))))) @@ -349,7 +349,7 @@ def batch_calculate_state(circuits, param_resolvers, simulator): `cirq.ParamResolver` in `param_resolvers` was used to resolve any symbols in it. If simulator is a `cirq.DensityMatrixSimulator` this final state will be a density matrix, if simulator is a `cirq.Simulator` this final state - will be a wavefunction. More specifically for a given `i` + will be a state vector. More specifically for a given `i` `batch_calculate_state` will use `param_resolvers[i]` to resolve the symbols in `circuits[i]` and then place the final state in the return list at index `i`. @@ -445,8 +445,8 @@ def batch_calculate_expectation(circuits, param_resolvers, ops, simulator): state.final_density_matrix, order) for x in op).real elif isinstance(simulator, cirq.Simulator): post_process = \ - lambda op, state, order: op.expectation_from_wavefunction( - state.final_state, order).real + lambda op, state, order: op.expectation_from_state_vector( + state.final_state_vector, order).real else: raise TypeError('Simulator {} is not supported by ' 'batch_calculate_expectation.'.format(type(simulator))) @@ -620,7 +620,7 @@ def batch_sample(circuits, param_resolvers, n_samples, simulator): repetitions=n_samples) elif isinstance(simulator, cirq.Simulator): post_process = lambda state, size, n_samples: cirq.sample_state_vector( - state.final_state, list(range(size)), repetitions=n_samples) + state.final_state_vector, list(range(size)), repetitions=n_samples) else: raise TypeError('Simulator {} is not supported by batch_sample.'.format( type(simulator))) diff --git a/tensorflow_quantum/core/ops/batch_util_test.py b/tensorflow_quantum/core/ops/batch_util_test.py index df8b1eb24..cc50fd807 100644 --- a/tensorflow_quantum/core/ops/batch_util_test.py +++ b/tensorflow_quantum/core/ops/batch_util_test.py @@ -37,7 +37,7 @@ def _get_mixed_batch(qubits, symbols, size): def _pad_state(sim, state, n): if isinstance(sim, cirq.Simulator): - state = state.final_state + state = state.final_state_vector if isinstance(sim, cirq.DensityMatrixSimulator): state = state.final_density_matrix return np.pad(state, (0, (1 << n) - state.shape[-1]), @@ -47,9 +47,10 @@ def _pad_state(sim, state, n): def _expectation_helper(sim, circuit, params, op): if isinstance(sim, cirq.Simulator): - state = sim.simulate(circuit, params).final_state.astype(np.complex128) + state = sim.simulate(circuit, + params).final_state_vector.astype(np.complex128) return [ - op.expectation_from_wavefunction( + op.expectation_from_state_vector( state, dict( zip(sorted(circuit.all_qubits()), @@ -73,7 +74,7 @@ def _expectation_helper(sim, circuit, params, op): def _sample_helper(sim, state, n_qubits, n_samples): if isinstance(sim, cirq.Simulator): - return cirq.sample_state_vector(state.final_state, + return cirq.sample_state_vector(state.final_state_vector, list(range(n_qubits)), repetitions=n_samples) if isinstance(sim, cirq.DensityMatrixSimulator): @@ -92,8 +93,8 @@ class BatchUtilTest(tf.test.TestCase, parameterized.TestCase): }, { 'sim': cirq.Simulator() }]) - def test_batch_simulate_state(self, sim): - """Test variable sized wavefunction output.""" + def test_batch_simulate_state_vector(self, sim): + """Test variable sized state vector output.""" circuit_batch, resolver_batch = _get_mixed_batch( cirq.GridQubit.rect(1, N_QUBITS), SYMBOLS, BATCH_SIZE) results = batch_util.batch_calculate_state(circuit_batch, diff --git a/tensorflow_quantum/core/ops/circuit_execution_ops.py b/tensorflow_quantum/core/ops/circuit_execution_ops.py index a947fc3a5..bf3889218 100644 --- a/tensorflow_quantum/core/ops/circuit_execution_ops.py +++ b/tensorflow_quantum/core/ops/circuit_execution_ops.py @@ -22,7 +22,7 @@ from tensorflow_quantum.python import quantum_context -class TFQWavefunctionSimulator(enum.Enum): +class TFQStateVectorSimulator(enum.Enum): """Enum to make specifying TFQ simulators user-friendly.""" expectation = tfq_simulate_ops.tfq_simulate_expectation samples = tfq_simulate_ops.tfq_simulate_samples @@ -120,7 +120,7 @@ def get_expectation_op( op = None if backend is None: - op = TFQWavefunctionSimulator.expectation + op = TFQStateVectorSimulator.expectation if isinstance(backend, cirq.SimulatesFinalState): op = cirq_ops._get_cirq_analytical_expectation(backend) @@ -216,7 +216,7 @@ def get_sampling_op( op = None if backend is None: - op = TFQWavefunctionSimulator.samples + op = TFQStateVectorSimulator.samples if isinstance(backend, cirq.Sampler): op = cirq_ops._get_cirq_samples(backend) @@ -269,7 +269,7 @@ def get_state_op( backend: Optional Python `object` that specifies what backend this op should use when evaluating circuits. Can be any `cirq.SimulatesFinalState`. If not provided, the default C++ - wavefunction simulator will be used. + state vector simulator will be used. 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 @@ -305,7 +305,7 @@ def get_state_op( op = None if backend is None: - op = TFQWavefunctionSimulator.state + op = TFQStateVectorSimulator.state if isinstance(backend, (cirq.SimulatesFinalState)): op = cirq_ops._get_cirq_simulate_state(backend) @@ -416,7 +416,7 @@ def get_sampled_expectation_op( op = None if backend is None: - op = TFQWavefunctionSimulator.sampled_expectation + op = TFQStateVectorSimulator.sampled_expectation if isinstance(backend, cirq.Sampler): op = cirq_ops._get_cirq_sampled_expectation(backend) diff --git a/tensorflow_quantum/core/ops/cirq_ops_test.py b/tensorflow_quantum/core/ops/cirq_ops_test.py index e37172735..31dcdb27e 100644 --- a/tensorflow_quantum/core/ops/cirq_ops_test.py +++ b/tensorflow_quantum/core/ops/cirq_ops_test.py @@ -281,10 +281,10 @@ def test_simulate_state_output_padding(self, op_and_sim, all_n_qubits): 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 + # state vectors should be zero everywhere to the right of the states # present in this system elif isinstance(result, cirq.StateVectorTrialResult): - wf = result.final_state + wf = result.final_state_vector blank_state = np.ones( (2**max(all_n_qubits)), dtype=np.complex64) * -2 blank_state[:wf.shape[0]] = wf diff --git a/tensorflow_quantum/core/ops/math_ops/inner_product_op_test.py b/tensorflow_quantum/core/ops/math_ops/inner_product_op_test.py index b9be44080..b9a62c116 100644 --- a/tensorflow_quantum/core/ops/math_ops/inner_product_op_test.py +++ b/tensorflow_quantum/core/ops/math_ops/inner_product_op_test.py @@ -245,9 +245,9 @@ def test_correctness_with_symbols(self, n_qubits, batch_size, for i in range(batch_size): final_circuit = cirq.resolve_parameters(circuit_batch[i], resolver_batch[i]) - final_wf = cirq.final_wavefunction(final_circuit) + final_wf = cirq.final_state_vector(final_circuit) for j in range(inner_dim_size): - internal_wf = cirq.final_wavefunction(other_batch[i][j]) + 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) @@ -292,9 +292,9 @@ def test_correctness_without_symbols(self, n_qubits, batch_size, out_arr = np.empty((batch_size, inner_dim_size), dtype=np.complex64) for i in range(batch_size): - final_wf = cirq.final_wavefunction(circuit_batch[i]) + final_wf = cirq.final_state_vector(circuit_batch[i]) for j in range(inner_dim_size): - internal_wf = cirq.final_wavefunction(other_batch[i][j]) + 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) diff --git a/tensorflow_quantum/core/ops/math_ops/tfq_inner_product.cc b/tensorflow_quantum/core/ops/math_ops/tfq_inner_product.cc index 09c091a95..6cff60664 100644 --- a/tensorflow_quantum/core/ops/math_ops/tfq_inner_product.cc +++ b/tensorflow_quantum/core/ops/math_ops/tfq_inner_product.cc @@ -162,7 +162,7 @@ class TfqInnerProductOp : public tensorflow::OpKernel { State sv = StateSpace(largest_nq, tfq_for).CreateState(); State scratch = StateSpace(largest_nq, tfq_for).CreateState(); - // Simulate programs one by one. Parallelizing over wavefunctions + // Simulate programs one by one. Parallelizing over state vectors // we no longer parallelize over circuits. Each time we encounter a // a larger circuit we will grow the Statevector as necessary. for (int i = 0; i < fused_circuits.size(); i++) { @@ -239,8 +239,8 @@ class TfqInnerProductOp : public tensorflow::OpKernel { } if (cur_batch_index != old_batch_index) { - // We've run into a new wavefunction we must compute. - // Only compute a new wavefunction when we have to. + // We've run into a new state vector we must compute. + // Only compute a new state vector when we have to. if (nq > largest_nq) { sv = ss.CreateState(); scratch = ss.CreateState(); diff --git a/tensorflow_quantum/core/ops/tfq_calculate_unitary_op.cc b/tensorflow_quantum/core/ops/tfq_calculate_unitary_op.cc index bd30ebc7b..6d444a829 100644 --- a/tensorflow_quantum/core/ops/tfq_calculate_unitary_op.cc +++ b/tensorflow_quantum/core/ops/tfq_calculate_unitary_op.cc @@ -108,7 +108,7 @@ class TfqCalculateUnitaryOp : public tensorflow::OpKernel { int largest_nq = 1; Unitary u = UnitarySpace(largest_nq, tfq_for).CreateUnitary(); - // Simulate programs one by one. Parallelizing over wavefunctions + // Simulate programs one by one. Parallelizing over state vectors // we no longer parallelize over circuits. Each time we encounter a // a larger circuit we will grow the unitary as nescessary. for (int i = 0; i < fused_circuits.size(); i++) { diff --git a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op.cc b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op.cc index 3ffde7503..6079f1462 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op.cc @@ -134,7 +134,7 @@ class TfqSimulateExpectationOp : public tensorflow::OpKernel { State sv = StateSpace(largest_nq, tfq_for).CreateState(); State scratch = StateSpace(largest_nq, tfq_for).CreateState(); - // Simulate programs one by one. Parallelizing over wavefunctions + // Simulate programs one by one. Parallelizing over state vectors // we no longer parallelize over circuits. Each time we encounter a // a larger circuit we will grow the Statevector as necessary. for (int i = 0; i < fused_circuits.size(); i++) { @@ -205,8 +205,8 @@ class TfqSimulateExpectationOp : public tensorflow::OpKernel { } if (cur_batch_index != old_batch_index) { - // We've run into a new wavefunction we must compute. - // Only compute a new wavefunction when we have to. + // We've run into a new state vector we must compute. + // Only compute a new state vector when we have to. if (nq > largest_nq) { sv = ss.CreateState(); scratch = ss.CreateState(); diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops.py b/tensorflow_quantum/core/ops/tfq_simulate_ops.py index 0ecd5481b..17f1fd6bd 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops.py @@ -46,7 +46,7 @@ def tfq_simulate_expectation(programs, symbol_names, symbol_values, pauli_sums): def tfq_simulate_state(programs, symbol_names, symbol_values): - """Returns the state of the programs using the C++ wavefunction simulator. + """Returns the state of the programs using the C++ state vector simulator. Simulate the final state of `programs` given `symbol_values` are placed inside of the symbols with the name in `symbol_names` in each circuit. @@ -70,7 +70,7 @@ def tfq_simulate_state(programs, symbol_names, symbol_values): def tfq_simulate_samples(programs, symbol_names, symbol_values, num_samples): - """Generate samples using the C++ wavefunction simulator. + """Generate samples using the C++ state vector simulator. Simulate the final state of `programs` given `symbol_values` are placed inside of the symbols with the name in `symbol_names` in each circuit. diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_test.py index 526007ac6..8cf79bc6a 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_test.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_test.py @@ -313,7 +313,7 @@ def test_simulate_state_output_padding(self, all_n_qubits): manual_padded_results = [] for circuit in circuit_batch: result = sim.simulate(circuit) - wf = result.final_state + wf = result.final_state_vector blank_state = np.ones( (2**max(all_n_qubits)), dtype=np.complex64) * -2 blank_state[:wf.shape[0]] = wf diff --git a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op.cc b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op.cc index 5e6cc443c..320f34987 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op.cc @@ -151,7 +151,7 @@ class TfqSimulateSampledExpectationOp : public tensorflow::OpKernel { State sv = StateSpace(largest_nq, tfq_for).CreateState(); State scratch = StateSpace(largest_nq, tfq_for).CreateState(); - // Simulate programs one by one. Parallelizing over wavefunctions + // Simulate programs one by one. Parallelizing over state vectors // we no longer parallelize over circuits. Each time we encounter a // a larger circuit we will grow the Statevector as necessary. for (int i = 0; i < fused_circuits.size(); i++) { @@ -223,8 +223,8 @@ class TfqSimulateSampledExpectationOp : public tensorflow::OpKernel { } if (cur_batch_index != old_batch_index) { - // We've run into a new wavefunction we must compute. - // Only compute a new wavefunction when we have to. + // We've run into a new state vector we must compute. + // Only compute a new state vector when we have to. if (nq > largest_nq) { sv = ss.CreateState(); scratch = ss.CreateState(); diff --git a/tensorflow_quantum/core/ops/tfq_simulate_samples_op.cc b/tensorflow_quantum/core/ops/tfq_simulate_samples_op.cc index cedff3ef2..d3ea45756 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_samples_op.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_samples_op.cc @@ -133,7 +133,7 @@ class TfqSimulateSamplesOp : public tensorflow::OpKernel { int largest_nq = 1; State sv = StateSpace(largest_nq, tfq_for).CreateState(); - // Simulate programs one by one. Parallelizing over wavefunctions + // Simulate programs one by one. Parallelizing over state vectors // we no longer parallelize over circuits. Each time we encounter a // a larger circuit we will grow the Statevector as nescessary. for (int i = 0; i < fused_circuits.size(); i++) { diff --git a/tensorflow_quantum/core/ops/tfq_simulate_state_op.cc b/tensorflow_quantum/core/ops/tfq_simulate_state_op.cc index 40f33af43..467fd4737 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_state_op.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_state_op.cc @@ -127,7 +127,7 @@ class TfqSimulateStateOp : public tensorflow::OpKernel { int largest_nq = 1; State sv = StateSpace(largest_nq, tfq_for).CreateState(); - // Simulate programs one by one. Parallelizing over wavefunctions + // Simulate programs one by one. Parallelizing over state vectors // we no longer parallelize over circuits. Each time we encounter a // a larger circuit we will grow the Statevector as nescessary. for (int i = 0; i < fused_circuits.size(); i++) { @@ -217,7 +217,7 @@ REGISTER_OP("TfqSimulateState") .Input("programs: string") .Input("symbol_names: string") .Input("symbol_values: float") - .Output("wavefunction: complex64") + .Output("state_vector: complex64") .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { tensorflow::shape_inference::ShapeHandle programs_shape; TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); diff --git a/tensorflow_quantum/core/src/util_qsim.h b/tensorflow_quantum/core/src/util_qsim.h index 25feb9fab..55fff1f17 100644 --- a/tensorflow_quantum/core/src/util_qsim.h +++ b/tensorflow_quantum/core/src/util_qsim.h @@ -140,7 +140,7 @@ tensorflow::Status ComputeExpectationQsim(const tfq::proto::PauliSum& p_sum, const StateSpaceT& ss, StateT& state, StateT& scratch, float* expectation_value) { - // apply the gates of the pauliterms to a copy of the wavefunction + // apply the gates of the pauliterms to a copy of the state vector // and add up expectation value term by term. tensorflow::Status status = tensorflow::Status::OK(); for (const tfq::proto::PauliTerm& term : p_sum.terms()) { @@ -192,7 +192,7 @@ tensorflow::Status ComputeSampledExpectationQsim( if (num_samples == 0) { return tensorflow::Status::OK(); } - // apply the gates of the pauliterms to a copy of the wavefunction + // apply the gates of the pauliterms to a copy of the state vector // and add up expectation value term by term. tensorflow::Status status = tensorflow::Status::OK(); for (const tfq::proto::PauliTerm& term : p_sum.terms()) { @@ -301,7 +301,7 @@ tensorflow::Status AccumulateOperators( const std::vector& p_sums, const std::vector& op_coeffs, const SimT& sim, const StateSpaceT& ss, StateT& source, StateT& scratch, StateT& dest) { - // apply the gates of the pauliterms to a copy of the wavefunction + // apply the gates of the pauliterms to a copy of the state vector // accumulating results as we go. Effectively doing O|psi> for an arbitrary // O. Result is stored on scratch. tensorflow::Status status = tensorflow::Status::OK(); diff --git a/tensorflow_quantum/datasets/spin_system_test.py b/tensorflow_quantum/datasets/spin_system_test.py index bc6678e49..48528d434 100644 --- a/tensorflow_quantum/datasets/spin_system_test.py +++ b/tensorflow_quantum/datasets/spin_system_test.py @@ -70,7 +70,7 @@ def test_fidelity(self): for nspins in self.supported_nspins_tfi_chain: circuits, _, _, addinfo = self.data_dict_tfi_chain[nspins] for n in self.random_subset_tfi_chain: - phi = cirq.Simulator().simulate(circuits[n]).final_state + phi = cirq.Simulator().simulate(circuits[n]).final_state_vector gs = addinfo[n].gs self.assertAllClose(np.abs(np.vdot(gs, phi)), 1.0, rtol=1e-3) @@ -82,8 +82,8 @@ def test_paulisum(self): self.qbs_dict_tfi_chain[nspins][i]: i for i in range(nspins) } for n in self.random_subset_tfi_chain: - phi = cirq.Simulator().simulate(circuits[n]).final_state - e = pauli_sums[n].expectation_from_wavefunction(phi, qubit_map) + phi = cirq.Simulator().simulate(circuits[n]).final_state_vector + e = pauli_sums[n].expectation_from_state_vector(phi, qubit_map) self.assertAllClose(e, addinfo[n].gs_energy, rtol=1e-4) def test_returned_objects(self): @@ -109,9 +109,9 @@ def test_param_resolver(self): resolved_circuit = cirq.resolve_parameters( addinfo[n].var_circuit, addinfo[n].params) state_circuit = cirq.Simulator().simulate( - circuits[n]).final_state + circuits[n]).final_state_vector state_resolved_circuit = cirq.Simulator().simulate( - resolved_circuit).final_state + resolved_circuit).final_state_vector self.assertAllClose(np.abs( np.vdot(state_circuit, state_resolved_circuit)), 1.0, @@ -169,7 +169,7 @@ def test_fidelity(self): for nspins in self.supported_nspins_xxz_chain: circuits, _, _, addinfo = self.data_dict_xxz_chain[nspins] for n in self.random_subset_xxz_chain: - phi = cirq.Simulator().simulate(circuits[n]).final_state + phi = cirq.Simulator().simulate(circuits[n]).final_state_vector gs = addinfo[n].gs self.assertAllClose(np.abs(np.vdot(gs, phi)), 1.0, rtol=5e-3) @@ -181,8 +181,8 @@ def test_paulisum(self): self.qbs_dict_xxz_chain[nspins][i]: i for i in range(nspins) } for n in self.random_subset_xxz_chain: - phi = cirq.Simulator().simulate(circuits[n]).final_state - e = pauli_sums[n].expectation_from_wavefunction(phi, qubit_map) + phi = cirq.Simulator().simulate(circuits[n]).final_state_vector + e = pauli_sums[n].expectation_from_state_vector(phi, qubit_map) self.assertAllClose(e, addinfo[n].gs_energy, rtol=5e-3) def test_returned_objects(self): @@ -208,9 +208,9 @@ def test_param_resolver(self): resolved_circuit = cirq.resolve_parameters( addinfo[n].var_circuit, addinfo[n].params) state_circuit = cirq.Simulator().simulate( - circuits[n]).final_state + circuits[n]).final_state_vector state_resolved_circuit = cirq.Simulator().simulate( - resolved_circuit).final_state + resolved_circuit).final_state_vector self.assertAllClose(np.abs( np.vdot(state_circuit, state_resolved_circuit)), 1.0, diff --git a/tensorflow_quantum/python/layers/circuit_executors/state.py b/tensorflow_quantum/python/layers/circuit_executors/state.py index 56f11c55c..6f979139a 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/state.py +++ b/tensorflow_quantum/python/layers/circuit_executors/state.py @@ -51,7 +51,7 @@ class State(tf.keras.layers.Layer): (0.-3.0908619663705394e-08j), (0.707106+6.181723932741079e-08j)]]> - This use case can be simplified to compute the wavefunction produced by a + This use case can be simplified to compute the state vector produced by a fixed circuit where the values of the parameters vary. For example, this layer produces a Bell state.