Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/cirq-web/cirq_ts/web…
Browse files Browse the repository at this point in the history
…pack-5.94.0
  • Loading branch information
mhucka authored Sep 6, 2024
2 parents 18b9506 + f56a799 commit ea07929
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 37 deletions.
7 changes: 5 additions & 2 deletions cirq-core/cirq/experiments/xeb_fitting_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import itertools
import multiprocessing
from typing import Iterable
Expand All @@ -36,6 +37,8 @@
)
from cirq.experiments.xeb_sampling import sample_2q_xeb_circuits

_POOL_NUM_PROCESSES = min(4, multiprocessing.cpu_count())


@pytest.fixture(scope='module')
def circuits_cycle_depths_sampled_df():
Expand Down Expand Up @@ -229,7 +232,7 @@ def test_characterize_phased_fsim_parameters_with_xeb():
characterize_phi=False,
)
p_circuits = [parameterize_circuit(circuit, options) for circuit in circuits]
with multiprocessing.Pool() as pool:
with multiprocessing.Pool(_POOL_NUM_PROCESSES) as pool:
result = characterize_phased_fsim_parameters_with_xeb(
sampled_df=sampled_df,
parameterized_circuits=p_circuits,
Expand Down Expand Up @@ -270,7 +273,7 @@ def test_parallel_full_workflow(use_pool):
)

if use_pool:
pool = multiprocessing.Pool()
pool = multiprocessing.Pool(_POOL_NUM_PROCESSES)
else:
pool = None

Expand Down
7 changes: 5 additions & 2 deletions cirq-core/cirq/experiments/xeb_simulation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import multiprocessing
from typing import Dict, Any, Optional
from typing import Sequence
Expand All @@ -23,6 +24,8 @@
import cirq.experiments.random_quantum_circuit_generation as rqcg
from cirq.experiments.xeb_simulation import simulate_2q_xeb_circuits

_POOL_NUM_PROCESSES = min(4, multiprocessing.cpu_count())


def test_simulate_2q_xeb_circuits():
q0, q1 = cirq.LineQubit.range(2)
Expand All @@ -42,7 +45,7 @@ def test_simulate_2q_xeb_circuits():
assert len(row['pure_probs']) == 4
assert np.isclose(np.sum(row['pure_probs']), 1)

with multiprocessing.Pool() as pool:
with multiprocessing.Pool(_POOL_NUM_PROCESSES) as pool:
df2 = simulate_2q_xeb_circuits(circuits, cycle_depths, pool=pool)

pd.testing.assert_frame_equal(df, df2)
Expand Down Expand Up @@ -130,7 +133,7 @@ def test_incremental_simulate(multiprocess):
cycle_depths = np.arange(3, 100, 9, dtype=np.int64)

if multiprocess:
pool = multiprocessing.Pool()
pool = multiprocessing.Pool(_POOL_NUM_PROCESSES)
else:
pool = None

Expand Down
2 changes: 1 addition & 1 deletion cirq-core/cirq/transformers/noise_adding.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _gate_in_moment(gate: ops.Gate, moment: circuits.Moment) -> bool:


@transformer_api.transformer
class DepolerizingNoiseTransformer:
class DepolarizingNoiseTransformer:
"""Add local depolarizing noise after two-qubit gates in a specified circuit. More specifically,
with probability p, append a random non-identity two-qubit Pauli operator after each specified
two-qubit gate.
Expand Down
8 changes: 4 additions & 4 deletions cirq-core/cirq/transformers/noise_adding_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ def test_noise_adding():
circuit = one_layer * 10

# test that p=0 does nothing
transformed_circuit_p0 = na.DepolerizingNoiseTransformer(0.0)(circuit)
transformed_circuit_p0 = na.DepolarizingNoiseTransformer(0.0)(circuit)
assert transformed_circuit_p0 == circuit

# test that p=1 doubles the circuit depth
transformed_circuit_p1 = na.DepolerizingNoiseTransformer(1.0)(circuit)
transformed_circuit_p1 = na.DepolarizingNoiseTransformer(1.0)(circuit)
assert len(transformed_circuit_p1) == 20

# test that we get a deterministic result when using a specific rng
rng = np.random.default_rng(0)
transformed_circuit_p0_03 = na.DepolerizingNoiseTransformer(0.03)(circuit, rng=rng)
transformed_circuit_p0_03 = na.DepolarizingNoiseTransformer(0.03)(circuit, rng=rng)
expected_circuit = (
one_layer * 2
+ circuits.Circuit(ops.I(qubits[2]), ops.Z(qubits[3]))
Expand All @@ -44,7 +44,7 @@ def test_noise_adding():
assert transformed_circuit_p0_03 == expected_circuit

# test that supplying a dictionary for p works
transformed_circuit_p_dict = na.DepolerizingNoiseTransformer(
transformed_circuit_p_dict = na.DepolarizingNoiseTransformer(
{tuple(qubits[:2]): 1.0, tuple(qubits[2:]): 0.0}
)(circuit)
assert len(transformed_circuit_p_dict) == 20 # depth should be doubled
Expand Down
28 changes: 25 additions & 3 deletions cirq-google/cirq_google/api/v2/run_context.proto
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,37 @@ message DeviceParametersDiff {
// as index into the strs repeated field.
int32 name = 2;
}

// Param value whose type is not among proto field types supported by
// ArgValue. In other words, it is the responsibility of the client codes
// to enforce the validity and type consistency of this param value.
message GenericValue {
// Type description of the value representation. Eg. if the following value
// bytes field is a JSON string, type_descriptor can be its JSON namespace;
// or if the following value field is a protobuf serialization, type_descriptor
// can be its protobuf definition URL.
string type_descriptor = 1;

// The value in client's encoding.
bytes value = 2;
}

message Param {
// the resource group hosting this parameter key, as index into groups
// repeated field.
int32 resource_group = 1;
// name of this param, as index into the strs repeated field.
int32 name = 2;
// this param's new value, as message ArgValue to allow variant types,
// including bool, string, double, float and arrays.
ArgValue value = 3;

oneof param_val {
// this param's new value, as message ArgValue to allow types of bool,
// string, double, float and arrays.
ArgValue value = 3;

// this param's new value, and its type is not among the variants supported
// by ArgValue.
GenericValue generic_value = 4;
}
}
repeated ResourceGroup groups = 1;
repeated Param params = 2;
Expand Down
15 changes: 13 additions & 2 deletions cirq-google/cirq_google/api/v2/run_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@


def to_device_parameters_diff(
device_params: Sequence[tuple[run_context_pb2.DeviceParameter, program_pb2.ArgValue]]
device_params: Sequence[
tuple[
run_context_pb2.DeviceParameter,
program_pb2.ArgValue | run_context_pb2.DeviceParametersDiff.GenericValue,
]
]
) -> run_context_pb2.DeviceParametersDiff:
"""Constructs a DeviceParametersDiff from multiple DeviceParameters and values.
Expand Down Expand Up @@ -64,6 +69,12 @@ def resource_path_id(path: tuple[str, ...]) -> int:
resource_path = tuple(device_param.path[:-1])
param_name = device_param.path[-1]
path_id = resource_path_id(resource_path)
diff.params.add(name=token_id(param_name), resource_group=path_id, value=value)
val_kw = {}
if isinstance(value, run_context_pb2.DeviceParametersDiff.GenericValue):
val_kw["generic_value"] = value
else:
val_kw["value"] = value

diff.params.add(name=token_id(param_name), resource_group=path_id, **val_kw)

return diff
23 changes: 12 additions & 11 deletions cirq-google/cirq_google/api/v2/run_context_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 39 additions & 4 deletions cirq-google/cirq_google/api/v2/run_context_pb2.pyi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ea07929

Please sign in to comment.