diff --git a/tensorflow_quantum/python/layers/high_level/controlled_pqc.py b/tensorflow_quantum/python/layers/high_level/controlled_pqc.py index a61b4b50e..7a781f852 100644 --- a/tensorflow_quantum/python/layers/high_level/controlled_pqc.py +++ b/tensorflow_quantum/python/layers/high_level/controlled_pqc.py @@ -128,6 +128,7 @@ def __init__(self, *, repetitions=None, backend='noiseless', + use_cuquantum=False, differentiator=None, **kwargs): """Instantiate this layer. @@ -153,6 +154,8 @@ def __init__(self, `sampled_based` is True or it must inherit `cirq.sim.simulator.SimulatesExpectationValues` if `sample_based` is False. + use_cuquantum: Optional Python `bool` indicating whether or not to use + GPU ops differentiator: Optional `tfq.differentiator` object to specify how gradients of `model_circuit` should be calculated. """ @@ -235,10 +238,13 @@ def __init__(self, if self._analytic: self._layer = expectation.Expectation(backend=backend, - differentiator=differentiator) + differentiator=differentiator, + use_cuquantum=use_cuquantum) else: self._layer = sampled_expectation.SampledExpectation( - backend=backend, differentiator=differentiator) + backend=backend, + differentiator=differentiator, + use_cuquantum=use_cuquantum) self._append_layer = elementary.AddCircuit() diff --git a/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc.py b/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc.py index 9a3b86eec..d213d9d35 100644 --- a/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc.py +++ b/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc.py @@ -142,6 +142,7 @@ def __init__(self, repetitions=None, sample_based=None, differentiator=None, + use_cuquantum=False, **kwargs): """Instantiate this layer. @@ -163,6 +164,8 @@ def __init__(self, trajectory. differentiator: Optional `tfq.differentiator` object to specify how gradients of `model_circuit` should be calculated. + use_cuquantum: Optional `bool` indicating whether to use GPU for + simulation or not. Defaults to `False`. NOT IMPLEMENTED YET. """ super().__init__(**kwargs) # Ingest model_circuit. @@ -218,6 +221,11 @@ def __init__(self, if differentiator is None: differentiator = parameter_shift.ParameterShift() + # Use gpu not supported yet. + if use_cuquantum: + raise NotImplementedError("GPU support for noisy controlled PQC \ + is not yet implemented.") + # Ingest and promote sample based. if sample_based is None: raise ValueError("Please specify sample_based=False for analytic " diff --git a/tensorflow_quantum/python/layers/high_level/noisy_pqc.py b/tensorflow_quantum/python/layers/high_level/noisy_pqc.py index 2c6796231..c61805d89 100644 --- a/tensorflow_quantum/python/layers/high_level/noisy_pqc.py +++ b/tensorflow_quantum/python/layers/high_level/noisy_pqc.py @@ -139,6 +139,7 @@ def __init__( repetitions=None, sample_based=None, differentiator=None, + use_cuquantum=False, initializer=tf.keras.initializers.RandomUniform(0, 2 * np.pi), regularizer=None, constraint=None, @@ -164,6 +165,8 @@ def __init__( trajectory. differentiator: Optional `tfq.differentiator` object to specify how gradients of `model_circuit` should be calculated. + use_cuquantum: Python `bool` indicating whether to use GPU ops + (currently not supported/implemented). initializer: Optional `tf.keras.initializer` object to specify how the symbols in `model_circuit` should be initialized when creating the managed variables. @@ -220,6 +223,11 @@ def __init__( [[repetitions for _ in range(len(operators))]], dtype=tf.dtypes.int32) + # Use gpu not supported yet. + if use_cuquantum: + raise NotImplementedError("GPU support for noisy PQC is not \ + yet implemented.") + # Ingest differentiator. if differentiator is None: differentiator = parameter_shift.ParameterShift() diff --git a/tensorflow_quantum/python/layers/high_level/pqc.py b/tensorflow_quantum/python/layers/high_level/pqc.py index 229ded921..a4c5c3f05 100644 --- a/tensorflow_quantum/python/layers/high_level/pqc.py +++ b/tensorflow_quantum/python/layers/high_level/pqc.py @@ -137,6 +137,7 @@ def __init__( *, repetitions=None, backend='noiseless', + use_cuquantum=False, differentiator=None, initializer=tf.keras.initializers.RandomUniform(0, 2 * np.pi), regularizer=None, @@ -166,6 +167,8 @@ def __init__( `cirq.sim.simulator.SimulatesExpectationValues` if analytic expectations are desired or `cirq.Sampler` if sampled expectations are desired. + use_cuquantum: Optional Python `bool` indicating whether or not to use + GPU ops. differentiator: Optional `tfq.differentiator` object to specify how gradients of `model_circuit` should be calculated. initializer: Optional `tf.keras.initializer` object to specify how the @@ -248,10 +251,14 @@ def __init__( "cirq.sim.simulator.SimulatesExpectationValues.") if self._analytic: self._executor = expectation.Expectation( - backend=backend, differentiator=differentiator) + backend=backend, + differentiator=differentiator, + use_cuquantum=use_cuquantum) else: self._executor = sampled_expectation.SampledExpectation( - backend=backend, differentiator=differentiator) + backend=backend, + differentiator=differentiator, + use_cuquantum=use_cuquantum) self._append_layer = elementary.AddCircuit()