Skip to content

[PR5/last from #774] Add use_cuquantum arg into PQC layers #789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 8 additions & 2 deletions tensorflow_quantum/python/layers/high_level/controlled_pqc.py
Original file line number Diff line number Diff line change
@@ -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()

Original file line number Diff line number Diff line change
@@ -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 "
8 changes: 8 additions & 0 deletions tensorflow_quantum/python/layers/high_level/noisy_pqc.py
Original file line number Diff line number Diff line change
@@ -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()
11 changes: 9 additions & 2 deletions tensorflow_quantum/python/layers/high_level/pqc.py
Original file line number Diff line number Diff line change
@@ -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()