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
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _generate_got_set_for_init_prob(qubit, init_prob):
yield common_gates.ry(_prob_to_angle(init_prob)).on(qubit)


@value.value_equality
@value.value_equality(unhashable=True)
class BayesianNetworkGate(raw_types.Gate):
"""A gate that represents a Bayesian network.

Expand Down
16 changes: 14 additions & 2 deletions cirq-core/cirq/contrib/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import functools

from cirq import _compat
from cirq.protocols.json_serialization import _register_resolver, DEFAULT_RESOLVERS, ObjectFactory


Expand Down Expand Up @@ -39,6 +40,17 @@ def _class_resolver_dictionary() -> dict[str, ObjectFactory]:
return {cls.__name__: cls for cls in classes}


DEFAULT_CONTRIB_RESOLVERS = [contrib_class_resolver] + DEFAULT_RESOLVERS

_register_resolver(_class_resolver_dictionary)

DEFAULT_CONTRIB_RESOLVERS = [contrib_class_resolver, *DEFAULT_RESOLVERS]

_compat.deprecate_attributes(
__name__,
{
'DEFAULT_CONTRIB_RESOLVERS': (
'v1.8',
'DEFAULT_CONTRIB_RESOLVERS is no longer necessary as contrib classes are now '
'automatically recognized and resolved with an import of cirq.contrib.',
)
},
)
33 changes: 0 additions & 33 deletions cirq-core/cirq/contrib/json_test.py

This file was deleted.

10 changes: 10 additions & 0 deletions cirq-core/cirq/contrib/json_test_data/BayesianNetworkGate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"cirq_type": "BayesianNetworkGate",
"init_probs": [
["q0", 0.125],
["q1", null]
],
"arc_probs": [
["q1", ["q0"], [0.25, 0.5]]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cirq.contrib.bayesian_network.BayesianNetworkGate(
init_probs=[('q0', 0.125), ('q1', None)], arc_probs=[('q1', ('q0',), [0.25, 0.5])]
)
169 changes: 169 additions & 0 deletions cirq-core/cirq/contrib/json_test_data/QuantumVolumeResult.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
{
"cirq_type": "QuantumVolumeResult",
"model_circuit": {
"cirq_type": "Circuit",
"moments": [
{
"cirq_type": "Moment",
"operations": [
{
"cirq_type": "GateOperation",
"gate": {
"cirq_type": "HPowGate",
"exponent": 1.0,
"global_shift": 0.0
},
"qubits": [
{
"cirq_type": "LineQubit",
"x": 0
}
]
},
{
"cirq_type": "GateOperation",
"gate": {
"cirq_type": "HPowGate",
"exponent": 1.0,
"global_shift": 0.0
},
"qubits": [
{
"cirq_type": "LineQubit",
"x": 1
}
]
},
{
"cirq_type": "GateOperation",
"gate": {
"cirq_type": "HPowGate",
"exponent": 1.0,
"global_shift": 0.0
},
"qubits": [
{
"cirq_type": "LineQubit",
"x": 2
}
]
},
{
"cirq_type": "GateOperation",
"gate": {
"cirq_type": "HPowGate",
"exponent": 1.0,
"global_shift": 0.0
},
"qubits": [
{
"cirq_type": "LineQubit",
"x": 3
}
]
},
{
"cirq_type": "GateOperation",
"gate": {
"cirq_type": "HPowGate",
"exponent": 1.0,
"global_shift": 0.0
},
"qubits": [
{
"cirq_type": "LineQubit",
"x": 4
}
]
}
]
}
]
},
"heavy_set": [
1,
2,
3
],
"compiled_circuit": {
"cirq_type": "Circuit",
"moments": [
{
"cirq_type": "Moment",
"operations": [
{
"cirq_type": "GateOperation",
"gate": {
"cirq_type": "HPowGate",
"exponent": 1.0,
"global_shift": 0.0
},
"qubits": [
{
"cirq_type": "LineQubit",
"x": 0
}
]
},
{
"cirq_type": "GateOperation",
"gate": {
"cirq_type": "HPowGate",
"exponent": 1.0,
"global_shift": 0.0
},
"qubits": [
{
"cirq_type": "LineQubit",
"x": 1
}
]
},
{
"cirq_type": "GateOperation",
"gate": {
"cirq_type": "HPowGate",
"exponent": 1.0,
"global_shift": 0.0
},
"qubits": [
{
"cirq_type": "LineQubit",
"x": 2
}
]
},
{
"cirq_type": "GateOperation",
"gate": {
"cirq_type": "HPowGate",
"exponent": 1.0,
"global_shift": 0.0
},
"qubits": [
{
"cirq_type": "LineQubit",
"x": 3
}
]
},
{
"cirq_type": "GateOperation",
"gate": {
"cirq_type": "HPowGate",
"exponent": 1.0,
"global_shift": 0.0
},
"qubits": [
{
"cirq_type": "LineQubit",
"x": 4
}
]
}
]
}
]
},
"sampler_result": 0.1
}
22 changes: 22 additions & 0 deletions cirq-core/cirq/contrib/json_test_data/QuantumVolumeResult.repr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
cirq.contrib.quantum_volume.QuantumVolumeResult(
model_circuit=cirq.Circuit(
cirq.Moment(
cirq.H(cirq.LineQubit(0)),
cirq.H(cirq.LineQubit(1)),
cirq.H(cirq.LineQubit(2)),
cirq.H(cirq.LineQubit(3)),
cirq.H(cirq.LineQubit(4)),
)
),
heavy_set=[1, 2, 3],
compiled_circuit=cirq.Circuit(
cirq.Moment(
cirq.H(cirq.LineQubit(0)),
cirq.H(cirq.LineQubit(1)),
cirq.H(cirq.LineQubit(2)),
cirq.H(cirq.LineQubit(3)),
cirq.H(cirq.LineQubit(4)),
)
),
sampler_result=0.1,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cirq_type": "SwapPermutationGate"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cirq.contrib.acquaintance.SwapPermutationGate(swap_gate=cirq.SWAP)
2 changes: 0 additions & 2 deletions cirq-core/cirq/contrib/json_test_data/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,4 @@
should_not_be_serialized=["Unique", "CircuitDag"],
resolver_cache=_class_resolver_dictionary(),
deprecated={},
# TODO: #7520 - create .json and .repr for these so they can be tested here
tested_elsewhere=["QuantumVolumeResult", "SwapPermutationGate", "BayesianNetworkGate"],
)
Loading