def test_wrap_module(): my_module = types.ModuleType('my_module', 'my doc string') my_module.foo = 'foo' my_module.bar = 'bar' assert 'foo' in my_module.__dict__ assert 'bar' in my_module.__dict__ assert 'zoo' not in my_module.__dict__ with pytest.raises(AssertionError, match='deadline should match vX.Y'): deprecate_attributes(my_module, {'foo': ('invalid', 'use bar instead')}) wrapped = deprecate_attributes(my_module, {'foo': ('v0.6', 'use bar instead')}) # Dunder methods assert wrapped.__doc__ == 'my doc string' assert wrapped.__name__ == 'my_module' # Test dict is correct. assert 'foo' in wrapped.__dict__ assert 'bar' in wrapped.__dict__ assert 'zoo' not in wrapped.__dict__ # Deprecation capability. with cirq.testing.assert_deprecated( '_compat_test.py:', 'foo was used but is deprecated.', 'will be removed in cirq v0.6', 'use bar instead', deadline='v0.6', ): _ = wrapped.foo with pytest.raises(ValueError, match='Cirq should not use deprecated functionality'): _ = wrapped.foo with cirq.testing.assert_logs(count=0): _ = wrapped.bar
def test_wrap_module(): my_module = types.ModuleType('my_module', 'my doc string') my_module.foo = 'foo' my_module.bar = 'bar' my_module.__spec__ = ModuleSpec('my_module', loader=None) assert 'foo' in my_module.__dict__ assert 'bar' in my_module.__dict__ assert 'zoo' not in my_module.__dict__ with pytest.raises(AssertionError, match='deadline should match vX.Y'): deprecate_attributes(my_module, {'foo': ('invalid', 'use bar instead')}) # temporarily update sys.modules so deprecate_attributes can find my_module sys.modules['my_module'] = my_module wrapped = deprecate_attributes('my_module', {'foo': ('v0.6', 'use bar instead')}) assert wrapped is sys.modules.pop('my_module') # Dunder methods assert wrapped.__doc__ == 'my doc string' assert wrapped.__name__ == 'my_module' assert wrapped.__spec__ is my_module.__spec__ # Verify __spec__ setter in the wrapped module wrapped.__spec__ = ModuleSpec('my_module', loader=None) assert my_module.__spec__ is wrapped.__spec__ # Test dict is correct. assert 'foo' in wrapped.__dict__ assert 'bar' in wrapped.__dict__ assert 'zoo' not in wrapped.__dict__ # Deprecation capability. with cirq.testing.assert_deprecated( '_compat_test.py:', 'foo was used but is deprecated.', 'will be removed in cirq v0.6', 'use bar instead', deadline='v0.6', ): _ = wrapped.foo with pytest.raises( ValueError, match= 'During testing using Cirq deprecated functionality is not allowed' ): _ = wrapped.foo with cirq.testing.assert_logs(count=0): _ = wrapped.bar
def _test_deprecate_attributes_assert_attributes_in_sys_modules(): """Ensure submodule attributes are consistent with sys.modules items.""" import cirq.testing._compat_test_data.module_a as module_a0 module_a1 = deprecate_attributes( 'cirq.testing._compat_test_data.module_a', {'MODULE_A_ATTRIBUTE': ('v0.6', 'use plain string instead')}, ) assert module_a1 is not module_a0 assert module_a1 is cirq.testing._compat_test_data.module_a assert module_a1 is sys.modules['cirq.testing._compat_test_data.module_a']
from cirq import testing # Registers cirq-core's public classes for JSON serialization. # pylint: disable=wrong-import-position from cirq.protocols.json_serialization import _register_resolver from cirq.json_resolver_cache import _class_resolver_dictionary _register_resolver(_class_resolver_dictionary) # contrib's json resolver cache depends on cirq.DEFAULT_RESOLVER from cirq import contrib # deprecate cirq.ops and related attributes from cirq import _compat _compat.deprecated_submodule( new_module_name='cirq.circuits.moment', old_parent='cirq.ops', old_child='moment', deadline='v0.16', create_attribute=True, ) ops.Moment = Moment # type: ignore _compat.deprecate_attributes('cirq.ops', {'Moment': ('v0.16', 'Use cirq.circuits.Moment instead')}) # pylint: enable=wrong-import-position
from cirq_google import experimental # Register cirq_google's public classes for JSON serialization. from cirq.protocols.json_serialization import _register_resolver from cirq_google.json_resolver_cache import _class_resolver_dictionary _register_resolver(_class_resolver_dictionary) _SERIALIZABLE_GATESET_DEPRECATION_MESSAGE = ( 'SerializableGateSet and associated classes (GateOpSerializer, GateOpDeserializer,' ' SerializingArgs, DeserializingArgs) will no longer be supported.' ' In cirq_google.GridDevice, the new representation of Google devices, the gateset of a device' ' is represented as a cirq.Gateset and is available as' ' GridDevice.metadata.gateset.' ' Engine methods no longer require gate sets to be passed in.' ' In addition, circuit serialization is replaced by cirq_google.CircuitSerializer.' ) _compat.deprecate_attributes( __name__, { 'XMON': ('v0.16', _SERIALIZABLE_GATESET_DEPRECATION_MESSAGE), 'FSIM_GATESET': ('v0.16', _SERIALIZABLE_GATESET_DEPRECATION_MESSAGE), 'SQRT_ISWAP_GATESET': ('v0.16', _SERIALIZABLE_GATESET_DEPRECATION_MESSAGE), 'SYC_GATESET': ('v0.16', _SERIALIZABLE_GATESET_DEPRECATION_MESSAGE), 'NAMED_GATESETS': ('v0.16', _SERIALIZABLE_GATESET_DEPRECATION_MESSAGE), }, )
ExecutableGroupResult, ExecutableGroupResultFilesystemRecord, QuantumRuntimeConfiguration, execute, QubitPlacer, CouldNotPlaceError, NaiveQubitPlacer, RandomDevicePlacer, HardcodedQubitPlacer, ProcessorRecord, EngineProcessorRecord, SimulatedProcessorRecord, SimulatedProcessorWithLocalDeviceRecord, ) from cirq_google import experimental # Register cirq_google's public classes for JSON serialization. from cirq.protocols.json_serialization import _register_resolver from cirq_google.json_resolver_cache import _class_resolver_dictionary _register_resolver(_class_resolver_dictionary) _compat.deprecate_attributes( __name__, { 'Bristlecone': ('v0.15', 'Bristlecone will no longer be supported.'), 'Foxtail': ('v0.15', 'Foxtail will no longer be supported.'), }, )
'sycamore': SYC_GATESET, 'fsim': FSIM_GATESET } document(NAMED_GATESETS, """A convenience mapping from gateset names to gatesets""") GOOGLE_GATESETS = [SYC_GATESET, SQRT_ISWAP_GATESET, FSIM_GATESET, XMON] document(GOOGLE_GATESETS, """All Google gatesets""") _SERIALIZABLE_GATESET_DEPRECATION_MESSAGE = ( 'SerializableGateSet and associated classes (GateOpSerializer, GateOpDeserializer,' ' SerializingArgs, DeserializingArgs) will no longer be supported.' ' In cirq_google.GridDevice, the new representation of Google devices, the gateset of a device' ' is represented as a cirq.Gateset and is available as' ' GridDevice.metadata.gateset.' ' Engine methods no longer require gate sets to be passed in.' ' In addition, circuit serialization is replaced by cirq_google.CircuitSerializer.' ) _compat.deprecate_attributes( __name__, { 'EXPERIMENTAL_PULSE_GATESET': ('v0.16', _SERIALIZABLE_GATESET_DEPRECATION_MESSAGE), 'GOOGLE_GATESETS': ('v0.16', _SERIALIZABLE_GATESET_DEPRECATION_MESSAGE), }, )