diff --git a/cirq-core/cirq/circuits/qasm_output.py b/cirq-core/cirq/circuits/qasm_output.py index eb3ca16528a..1024938086f 100644 --- a/cirq-core/cirq/circuits/qasm_output.py +++ b/cirq-core/cirq/circuits/qasm_output.py @@ -83,6 +83,17 @@ def _decompose_(self, qubits): def _value_equality_values_(self): return self.lmda, self.theta, self.phi + def _json_dict_(self) -> Dict[str, float]: + return { + 'theta': self.theta, + 'phi': self.phi, + 'lmda': self.lmda, + } + + @classmethod + def _from_json_dict_(cls, theta: float, phi: float, lmda: float, **kwargs) -> 'QasmUGate': + return cls(theta, phi, lmda) + @value.value_equality class QasmTwoQubitGate(ops.Gate): diff --git a/cirq-core/cirq/json_resolver_cache.py b/cirq-core/cirq/json_resolver_cache.py index 6f362dcd52b..a600115ac94 100644 --- a/cirq-core/cirq/json_resolver_cache.py +++ b/cirq-core/cirq/json_resolver_cache.py @@ -51,39 +51,35 @@ def _parallel_gate_op(gate, qubits): import sympy return { - 'AnyIntegerPowerGateFamily': cirq.AnyIntegerPowerGateFamily, 'AmplitudeDampingChannel': cirq.AmplitudeDampingChannel, + 'AnyIntegerPowerGateFamily': cirq.AnyIntegerPowerGateFamily, 'AnyUnitaryGateFamily': cirq.AnyUnitaryGateFamily, 'AsymmetricDepolarizingChannel': cirq.AsymmetricDepolarizingChannel, 'BitFlipChannel': cirq.BitFlipChannel, 'BitstringAccumulator': cirq.work.BitstringAccumulator, 'BooleanHamiltonian': cirq.BooleanHamiltonian, - 'ProductState': cirq.ProductState, 'CCNotPowGate': cirq.CCNotPowGate, 'CCXPowGate': cirq.CCXPowGate, 'CCZPowGate': cirq.CCZPowGate, - 'CNotPowGate': cirq.CNotPowGate, + 'Circuit': cirq.Circuit, + 'CircuitOperation': cirq.CircuitOperation, 'ClassicallyControlledOperation': cirq.ClassicallyControlledOperation, + 'CliffordState': cirq.CliffordState, + 'CliffordTableau': cirq.CliffordTableau, + 'CNotPowGate': cirq.CNotPowGate, + 'ConstantQubitNoiseModel': cirq.ConstantQubitNoiseModel, 'ControlledGate': cirq.ControlledGate, 'ControlledOperation': cirq.ControlledOperation, + 'CrossEntropyResult': CrossEntropyResult, + 'CrossEntropyResultDict': CrossEntropyResultDict, 'CSwapGate': cirq.CSwapGate, 'CXPowGate': cirq.CXPowGate, 'CZPowGate': cirq.CZPowGate, - 'CrossEntropyResult': CrossEntropyResult, - 'CrossEntropyResultDict': CrossEntropyResultDict, - 'Circuit': cirq.Circuit, - 'CircuitOperation': cirq.CircuitOperation, - 'CliffordState': cirq.CliffordState, - 'CliffordTableau': cirq.CliffordTableau, + 'DensePauliString': cirq.DensePauliString, 'DepolarizingChannel': cirq.DepolarizingChannel, - 'ConstantQubitNoiseModel': cirq.ConstantQubitNoiseModel, 'Duration': cirq.Duration, 'FrozenCircuit': cirq.FrozenCircuit, 'FSimGate': cirq.FSimGate, - 'DensePauliString': cirq.DensePauliString, - 'MutableDensePauliString': cirq.MutableDensePauliString, - 'MutablePauliString': cirq.MutablePauliString, - 'ObservableMeasuredResult': cirq.work.ObservableMeasuredResult, 'GateFamily': cirq.GateFamily, 'GateOperation': cirq.GateOperation, 'Gateset': cirq.Gateset, @@ -109,22 +105,22 @@ def _parallel_gate_op(gate, qubits): 'MeasurementGate': cirq.MeasurementGate, '_MeasurementSpec': cirq.work._MeasurementSpec, 'Moment': cirq.Moment, - '_XEigenState': cirq.value.product_state._XEigenState, # type: ignore - '_YEigenState': cirq.value.product_state._YEigenState, # type: ignore - '_ZEigenState': cirq.value.product_state._ZEigenState, # type: ignore + 'MutableDensePauliString': cirq.MutableDensePauliString, + 'MutablePauliString': cirq.MutablePauliString, '_NoNoiseModel': _NoNoiseModel, 'NamedQubit': cirq.NamedQubit, 'NamedQid': cirq.NamedQid, 'NoIdentifierQubit': cirq.testing.NoIdentifierQubit, + 'ObservableMeasuredResult': cirq.work.ObservableMeasuredResult, 'OpIdentifier': cirq.OpIdentifier, - '_PauliX': cirq.ops.pauli_gates._PauliX, - '_PauliY': cirq.ops.pauli_gates._PauliY, - '_PauliZ': cirq.ops.pauli_gates._PauliZ, 'ParamResolver': cirq.ParamResolver, 'ParallelGate': cirq.ParallelGate, 'ParallelGateFamily': cirq.ParallelGateFamily, 'PauliMeasurementGate': cirq.PauliMeasurementGate, 'PauliString': cirq.PauliString, + '_PauliX': cirq.ops.pauli_gates._PauliX, + '_PauliY': cirq.ops.pauli_gates._PauliY, + '_PauliZ': cirq.ops.pauli_gates._PauliZ, 'PhaseDampingChannel': cirq.PhaseDampingChannel, 'PhaseFlipChannel': cirq.PhaseFlipChannel, 'PhaseGradientGate': cirq.PhaseGradientGate, @@ -132,39 +128,44 @@ def _parallel_gate_op(gate, qubits): 'PhasedISwapPowGate': cirq.PhasedISwapPowGate, 'PhasedXPowGate': cirq.PhasedXPowGate, 'PhasedXZGate': cirq.PhasedXZGate, - 'StatePreparationChannel': cirq.StatePreparationChannel, + 'ProductState': cirq.ProductState, 'ProjectorString': cirq.ProjectorString, 'ProjectorSum': cirq.ProjectorSum, - 'RandomGateChannel': cirq.RandomGateChannel, + 'QasmUGate': cirq.circuits.qasm_output.QasmUGate, + '_QubitAsQid': raw_types._QubitAsQid, 'QuantumFourierTransformGate': cirq.QuantumFourierTransformGate, + 'RandomGateChannel': cirq.RandomGateChannel, 'RepetitionsStoppingCriteria': cirq.work.RepetitionsStoppingCriteria, 'ResetChannel': cirq.ResetChannel, + 'Result': cirq.Result, + 'Rx': cirq.Rx, + 'Ry': cirq.Ry, + 'Rz': cirq.Rz, 'SingleQubitCliffordGate': cirq.SingleQubitCliffordGate, 'SingleQubitPauliStringGateOperation': cirq.SingleQubitPauliStringGateOperation, 'SingleQubitReadoutCalibrationResult': cirq.experiments.SingleQubitReadoutCalibrationResult, 'StabilizerStateChForm': cirq.StabilizerStateChForm, + 'StatePreparationChannel': cirq.StatePreparationChannel, 'SwapPowGate': cirq.SwapPowGate, 'SymmetricalQidPair': cirq.SymmetricalQidPair, 'TaggedOperation': cirq.TaggedOperation, 'TiltedSquareLattice': cirq.TiltedSquareLattice, 'TrialResult': cirq.Result, # keep support for Cirq < 0.11. - 'Result': cirq.Result, - 'Rx': cirq.Rx, - 'Ry': cirq.Ry, - 'Rz': cirq.Rz, '_UnconstrainedDevice': cirq.devices.unconstrained_device._UnconstrainedDevice, 'VarianceStoppingCriteria': cirq.work.VarianceStoppingCriteria, 'VirtualTag': cirq.VirtualTag, 'WaitGate': cirq.WaitGate, - '_QubitAsQid': raw_types._QubitAsQid, # The formatter keeps putting this back # pylint: disable=line-too-long 'XEBPhasedFSimCharacterizationOptions': cirq.experiments.XEBPhasedFSimCharacterizationOptions, # pylint: enable=line-too-long + '_XEigenState': cirq.value.product_state._XEigenState, # type: ignore 'XPowGate': cirq.XPowGate, 'XXPowGate': cirq.XXPowGate, + '_YEigenState': cirq.value.product_state._YEigenState, # type: ignore 'YPowGate': cirq.YPowGate, 'YYPowGate': cirq.YYPowGate, + '_ZEigenState': cirq.value.product_state._ZEigenState, # type: ignore 'ZPowGate': cirq.ZPowGate, 'ZZPowGate': cirq.ZZPowGate, # Old types, only supported for backwards-compatibility diff --git a/cirq-core/cirq/protocols/json_test_data/QasmUGate.json b/cirq-core/cirq/protocols/json_test_data/QasmUGate.json new file mode 100644 index 00000000000..7a3f552711c --- /dev/null +++ b/cirq-core/cirq/protocols/json_test_data/QasmUGate.json @@ -0,0 +1,6 @@ +{ + "cirq_type": "QasmUGate", + "theta": 0.1, + "phi": 0.2, + "lmda": 0.3 + } \ No newline at end of file diff --git a/cirq-core/cirq/protocols/json_test_data/QasmUGate.repr b/cirq-core/cirq/protocols/json_test_data/QasmUGate.repr new file mode 100644 index 00000000000..d141b58c1fe --- /dev/null +++ b/cirq-core/cirq/protocols/json_test_data/QasmUGate.repr @@ -0,0 +1 @@ +cirq.circuits.qasm_output.QasmUGate(0.1, 0.2, 0.3) \ No newline at end of file