Skip to content

Commit

Permalink
faster tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelBroughton committed Apr 3, 2021
1 parent d1d496d commit 402ae69
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

def sampled_expectation(programs, symbol_names, symbol_values, pauli_sums,
num_samples):
"""Estimate (via sampling) expectation values using monte-carlo simulation.
"""Estimates (via sampling) expectation values using monte-carlo simulation.
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
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def test_simulate_consistency(self, batch_size, n_qubits, noisy):
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
num_samples = [[10000] * 2] * batch_size

op_exps = noisy_sampled_expectation_op.sampled_expectation(
util.convert_to_tensor(circuit_batch),
Expand All @@ -262,7 +262,7 @@ def test_simulate_consistency(self, batch_size, n_qubits, noisy):
cirq_exps = batch_util.batch_calculate_expectation(
circuit_batch, resolver_batch, batch_pauli_sums,
cirq.DensityMatrixSimulator() if noisy else cirq.Simulator())
tol = 0.35
tol = 0.5
self.assertAllClose(cirq_exps, op_exps, atol=tol, rtol=tol)

@parameterized.parameters([{
Expand Down Expand Up @@ -290,7 +290,7 @@ def test_single_channel(self, channel):
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 = [[50000] * 2] * batch_size
num_samples = [[20000] * 2] * batch_size

op_exps = noisy_sampled_expectation_op.sampled_expectation(
util.convert_to_tensor(circuit_batch),
Expand All @@ -301,7 +301,7 @@ def test_single_channel(self, channel):
circuit_batch, resolver_batch, batch_pauli_sums,
cirq.DensityMatrixSimulator())

self.assertAllClose(cirq_exps, op_exps, atol=0.25, rtol=0.25)
self.assertAllClose(cirq_exps, op_exps, atol=0.35, rtol=0.35)

def test_correctness_empty(self):
"""Test the expectation for empty circuits."""
Expand Down

0 comments on commit 402ae69

Please sign in to comment.