Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/tutorials/gradients.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 7 additions & 7 deletions docs/tutorials/hello_many_worlds.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
Expand Down Expand Up @@ -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"
]
},
{
Expand All @@ -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"
]
},
{
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
12 changes: 6 additions & 6 deletions tensorflow_quantum/core/ops/batch_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down Expand Up @@ -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())))))
Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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)))
Expand Down
13 changes: 7 additions & 6 deletions tensorflow_quantum/core/ops/batch_util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand All @@ -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()),
Expand All @@ -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):
Expand All @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions tensorflow_quantum/core/ops/circuit_execution_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tensorflow_quantum/core/ops/cirq_ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tensorflow_quantum/core/ops/math_ops/inner_product_op_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions tensorflow_quantum/core/ops/math_ops/tfq_inner_product.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion tensorflow_quantum/core/ops/tfq_calculate_unitary_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
6 changes: 3 additions & 3 deletions tensorflow_quantum/core/ops/tfq_simulate_expectation_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions tensorflow_quantum/core/ops/tfq_simulate_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tensorflow_quantum/core/ops/tfq_simulate_ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion tensorflow_quantum/core/ops/tfq_simulate_samples_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
4 changes: 2 additions & 2 deletions tensorflow_quantum/core/ops/tfq_simulate_state_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -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));
Expand Down
6 changes: 3 additions & 3 deletions tensorflow_quantum/core/src/util_qsim.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -301,7 +301,7 @@ tensorflow::Status AccumulateOperators(
const std::vector<tfq::proto::PauliSum>& p_sums,
const std::vector<float>& 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();
Expand Down
Loading