Abstract
Optical logic operations lie at the heart of optical computing, and they enable many applications such as ultrahighspeed information processing. However, the reported optical logic gates rely heavily on the precise control of input light signals, including their phase difference, polarization, and intensity and the size of the incident beams. Due to the complexity and difficulty in these precise controls, the two output optical logic states may suffer from an inherent instability and a low contrast ratio of intensity. Moreover, the miniaturization of optical logic gates becomes difficult if the extra bulky apparatus for these controls is considered. As such, it is desirable to get rid of these complicated controls and to achieve full logic functionality in a compact photonic system. Such a goal remains challenging. Here, we introduce a simple yet universal design strategy, capable of using plane waves as the incident signal, to perform optical logic operations via a diffractive neural network. Physically, the incident plane wave is first spatially encoded by a specific logic operation at the input layer and further decoded through the hidden layers, namely, a compound Huygens’ metasurface. That is, the judiciously designed metasurface scatters the encoded light into one of two small designated areas at the output layer, which provides the information of output logic states. Importantly, after training of the diffractive neural network, all seven basic types of optical logic operations can be realized by the same metasurface. As a conceptual illustration, three logic operations (NOT, OR, and AND) are experimentally demonstrated at microwave frequencies.
Introduction
Optical computing, which operates with photons instead of electrons, is becoming increasingly important, since it promises to increase the efficiency of information processing beyond traditional electronbased computing^{1}. Due to its unique features of signal propagation at the speed of light, low power consumption, and the capability of parallel processing^{2,3,4,5}, optical computing holds huge potential in many practical scenarios, particularly those involving highthroughput and onthefly data processing, such as augmented reality and autonomous driving^{6}. The logic operation lies at the heart of all computers^{7}. Correspondingly, optical logic gates^{8,9,10,11,12,13}, including plasmonic logic gates, are essential for the further exploration and development of optical analogy computing, nanophotonic processing^{14,15}, and the field of cryptographically secured wireless communication^{16}. As such, there are growing and strong interests to provide optical logic gates with complete logic functionality in photonic systems with compact dimensions.
Previous methodologies towards optical logic gates considered mainly constructive/destructive interference effects, including linear^{8,9,10,11} and nonlinear interference^{12,13}, between the input light signals. We note that the reported works are heavily dependent on the precise control of the basic properties of two input light signals, the control light and/or the pump light, including their phase difference, polarization, and intensity^{7} (Supplementary Note 6); if the two nanowires are close to each other, such as for the plasmonic logic gate, there is also a stringent requirement on the size of input light beams to avoid a potential false input. As a result, a better precise control of input light can more thoroughly realize constructive or destructive interference and lead to a larger intensity contrast ratio between the two output optical logic states “1” and “0”, which is a key feature to characterize the performance of an optical logic gate.
The heavy reliance on the precise control of input light has two unfavourable influences on the design of compact optical logic gates. First, their miniaturization becomes difficult if the additional bulky apparatus to achieve these controls are taken into consideration. Second, owing to the difficulty and complexity to achieve the ideal control of input light, their performance may suffer from an inherent instability, and the intensity contrast ratio between two output logic states may become quite low in practical scenarios^{10}. For miniaturized optical logic gates, it is thus highly desirable to get rid of these critical requirements on the input light. Such a goal remains an open challenge that is long sought after due to its importance for the development of novel architectures for alloptical devices and systems.
To this end, here we introduce a simple yet universal design strategy, namely, a diffractive neural network^{17}, to realize all seven basic optical logic operations in a compact system, simply using plane waves as the input signal. The diffractive neural network is implemented by a compound Huygens’ metasurface^{18}, and it can partially mimic the functionality of an artificial neural network. After training, the compound metasurface can directionally scatter or focus the input encoded light into one of the two designated small areas/points, one of which represents logic state ‘1’ and the other stands for ‘0’. As a conceptual demonstration, three basic logic gates, i.e., NOT, OR, and AND, are experimentally verified using a twolayer highefficiency dielectric metasurface at microwave frequency. Our design strategy features two distinct advantages. First, the realization of optical logic operations here gets rid of the complicated and necessarily precise control of the features of input light; such a scheme is thus totally different from previous works. Moreover, the design of the input layer is very general and powerful, and it can be flexibly modified into other userfavoured and programmable forms. Second, the proposed strategy can enable complete logic functionalities in a single optical network if the transmittance state of the input layer is dynamically tuneable, e.g., electrically tuneable if the optical mask is constructed by a spatial light modulator. Therefore, the revealed universal design strategy has the potential to facilitate a single miniaturized programmable photonic processor for arbitrary logic operations.
Results
Design principle and underlying physics of the optical logic operation
We start with the design principle of the optical logic operation. For binary optical logic operation, the output has only two cases, ‘1’ or ‘0’, which is very similar to a classification/decisionmaking task from the perspective of machine learning^{19} and can be readily tackled by an artificial neural network; Supplementary Note 1 verifies the theoretical feasibility. Analogous to an artificial neural network (Fig. 1a), in the optical regime, a diffractive neural network (composed of one input layer, at least one hidden layer and one output layer) has been found to allow powerful wavefront manipulation and communicate information among layers at the speed of light. As delineated in Fig. 1b, the input layer is a common optical mask and is patterned to form multiple regions. Without loss of generality, each region in the optical mask is set to have two different states for the transmittance of light, and its high (low) transmittance state indicates that it is (is not) selected for optical computing. Then, it is possible and convenient to directly define all seven basic optical logic operators and the input logic states in the optical mask, simply by assigning each of them to a specific region. The hidden layers are designed to decode the encoded input light and image the calculated result at the output layer.
We then progress to the introduction of the underlying physics of the design of hidden layers. We use a metasurface made up of a dense array of subwavelength metaatoms to construct each hidden layer. Each metaatom behaves like an independent neuron in the neural network and interconnects to other metaatoms of the following layers through the diffraction of light. Based on Rayleigh–Sommerfeld diffraction^{20}, the metaatom/neuron in the lth hidden layer, e.g., located at \(\vec r_i^l = \left( {x_i^l,y_i^l,z_i^l} \right)\), serves as a secondary source. The Huygens wavelet of such a source arises as a zderivative of the spherical wave (Fig. 1b) and can be described by \(H_z^{{\mathrm {Huy}}}\left( {\vec r  \vec r_i^l} \right) = G\left( {\vec r_i^l} \right) \cdot h_z^{{\mathrm {Huy}}}\left( {\vec r  \vec r_i^l} \right)\), where
In Eq. (1), \(R = \sqrt {\left( {x  x_i^l} \right)^2 + \left( {y  y_i^l} \right)^2 + \left( {z  z_i^l} \right)^2}\), and k is the wavevector of light in free space. The complexvalued factor \(G\left( {\vec r_i^l} \right)\) is determined by the product of the input wave \(u\left( {\vec r_i^l} \right)\) to the neuron and its transmission coefficient \(t(\vec r_i^l)\), i.e., \(G\left( {\vec r_i^l} \right) = u\left( {\vec r_i^l} \right) \cdot t(\vec r_i^l)\). As such, the total propagation field \(u\left( {\vec r} \right)\) is the summation of the field excited by all neurons in the lth layer, and it can be expressed as
For the first hidden layer with l = 1, \(u\left( {\vec r_i^1} \right)\) is the transmitted light spatially encoded by the input layer.
Following the forward propagation model in Eq. (2), the encoded input light can be directed into any desired location at the output layer via all learnable parameters \(t(\vec r_i^l)\). As shown in Fig. 1b, we designate two small regions with a radius of less than half a wavelength. If most of the field intensity \(s_i^{M + 1} = \left {u\left( {\vec r_i^{M + 1}} \right)} \right^2\) is focused in the left (right) region, the computing result is “1” (“0”). Note that this judgement criterion remains valid and consistent for all logic operations being considered, distinct from the case in refs. ^{11,16}. Before implementing the diffractive neural network, the transmission coefficients \(t\left( {\vec r_i^l} \right) = a_i^l \cdot {\mathrm {e}}^{i\phi _i^l}\) at each hidden layer should be adequately trained via an error backpropagation algorithm. In doing so, we define a loss function with mean square error \(F\left( {t_i^l} \right) = \frac{1}{K}\mathop {\sum }\limits_i \left( {s_i^{M + 1}  g_i^{M + 1}} \right)^2\) to evaluate the performance between the output intensity \(s_i^{M + 1}\) and the ground truth target \(g_i^{M + 1}\), where K is the number of the measurement points. The gradient of the loss function with respect to all the trainable network variables is backpropagated to iteratively update the network during each cycle of the training phase until the network converges; see Supplemental Note 2 and “Methods” section for details. Note that, in our case, we do not split the input data into training, validation and test sets as done in the traditional manner, since our goal is to achieve zeroerror classifications for all cases.
Experimental demonstration of three basic logic operations, NOT, OR, and AND
As a conceptual demonstration, we first numerically realize three basic logic operations (Fig. 2), i.e., NOT, OR, and AND, at the designed frequency f_{0}, since the combination of them can realize any other logic operation^{9}. Our proposed design strategy for optical logic operations is, in principle, applicable for arbitrary frequencies. To facilitate the following experimental verification, f_{0} = 17 GHz (wavelength λ_{0} = 17.6 mm) is chosen here. Figure 2a shows the pattern of the input layer. For simplicity, the high (low) transmittance state for each region is assumed to have a transmittance of 100% (0%).
The hidden layers are composed of a cascaded twolayer transmission metasurface^{21,22} with an axial distance of 17λ_{0} (one of the tuneable parameters in the training process of diffractive neural network). Each metasurface consists of 30 × 42 metaatoms (inset in Fig. 2b), where each metaatom has a square cross section with a width of 0.57λ_{0}. Here, we adopt a facile yet viable highefficiency dielectric metasurface by taking advantage of its unique properties such as high transmittance and polarization insensitivity. The local transmission response of the designed metaatoms is shown in Fig. 2b, where the constituent F4B dielectric has a relative permittivity of 3.5 + 0.003i and is fabricated by mechanical processing with an error <0.05 mm. The transmission phase ϕ varies smoothly over the height h of the metaatom. Approximately, we have \(h = \lambda _0\phi /2\pi \Delta n\), where Δn is the refractive index difference between free space and the chosen dielectric. In contrast, the magnitude of transmission coefficients is almost uniform and close to unity. This way, one may target to train phaseonly diffractive modulation layers. The training details are left to Supplementary Note 2. Figures 2c–l depict the numerical field intensity after training. As expected, most of the fields are correctly focused into one of the two small designated regions.
Figure 3 shows the microwave experimental demonstration of the theoretical proposal in Fig. 2. The experiment setup is depicted in Fig. 3a and described in “Methods” section. A horn antenna excites transverse electric (TE or spolarized) waves with the electric field along the xaxis, and it is placed far from the input layer (~45λ_{0}), so that the incident light signal can be reasonably treated as plane waves^{23} (see Fig. S5). The transmitted fields at the output layer, including their relative phase and amplitude, are measured by an Efield probe (a small monopole antenna^{24}). For example, the inset at the output layer in Fig. 3a shows the measured 2D field intensity for the optical logic operation of “1+0”. Moreover, the experimental performance of all optical logic operations is shown in Fig. 3b. As expected, all the peaks of field intensity definitely appear within one of the two designated regions, consistent with Fig. 2c–l. Quantitatively, the contrast ratios between the measured intensities of two designated regions are all larger than 9.6 dB. The weak fields outside the two designated regions might be caused by the impedance mismatch at the air–dielectric interfaces, and this mismatch can be further reduced by introducing periodic antireflection structures^{25}.
Discussion
Direct realization of all seven optical logic gates and cascaded optical logic gates
We emphasize that the proposed design strategy can, in principle, directly construct any type (basic and compound) of optical logic operation, such as all seven basic logic operations as shown in Figs. 4 and S6. This can be done by extending the encoding manner at the input layer and developing a more sophisticated neural network configuration. For more complete functionalities, we can cascade multiple logic gates. As shown in Fig. S7, the output waves from one logic gate couple into the waveguides and then are guided to the input layer of another logic gate as the inputs^{26}; see the details in Supplementary Note 5.
Optical logic gates at higher frequencies
Although our experimental design in Fig. 3 only works at microwave frequencies, our theoretical design strategy in Fig. 1 should in principle be applicable to various frequency regimes, including terahertz and optical frequencies. The reason is that the main underlying mechanism in this work follows the universal diffractive law, which is scalable according to Maxwell equations. To let our proposed idea work at higher frequencies, we should at least consider scaling down the four key ingredients to higher frequencies, namely, the metasurfaces, the input light encoder (or the spatial light modulator), the light source and detector. These ingredients are accessible to experimental investigations with current technology^{17,25,27}.
Comparisons with the traditionalrelated design
Our design principles of a multifunctional optical logic gate and its switching behaviour are both different from those of the traditional related design; see Supplementary Note 6. First, the traditional multifunctional optical logic gate essentially relies on several singlefunctional logic gates, which are independent of each other and stacked for multifunctional capability. In contrast, our design relies on just one integrated multifunctional optical logic gate. Second, traditional switches generally need to precisely control the input light, or involve the nonlinearity and refractive indices of materials. These stringent controls unfavourably incur a high complexity, high cost, large volume, and even inherent instability of the system. In contrast, our switch gets rid of these stringent requirements, and it just allows or prevents light passing through the corresponding regions/channels. This simplified switch in our design makes a step towards a future miniaturized multifunctional optical logic gate.
Other platforms to facilitate optical logic gates
Apart from the multilayer metasurfaces, there are also other platforms to facilitate optical logic gates, for example, metamaterials/nanophotonics, which can offer ultrahigh computing density in a compact and layerfree fashion^{26}. By suitably engineering its spatial inhomogeneity, we can obtain an optical neural network on the chip scale, and some optical computing tasks such as image recognition and wavelength demultiplexer have already been facilitated^{28}. In Fig. S9, we design a compact integratednanophotonic optical XOR logic gate as an example using topology optimization and finitedifference time domain (FDTD) simulation^{29,30}.
To sum up, we have demonstrated a general framework for all optical logic operations by a compound Huygens’ metasurface enacted diffractive neural network, making a step towards multifunctional optical logic gates and high computing density. In a conceptually microwave experiment, we successfully realize three basic logical operations, i.e., NOT, OR, and AND, on a twolayer dielectric metasurface. Implementing our proposed architecture with metamaterials/nanophotonics may lead to chipscale, ultrafast computing elements and promise the option of alloptical or hybrid optical–electronic technology. Looking forward, our proposed approach will also lead to a broad scope of applications, for example, realtime object recognition in surveillance systems and intelligent wave shaping inside biological tissues in microscope imaging^{31}.
Materials and methods
Training of the diffractive neural network
The diffractive neural network is trained using Python version 3.5.0. and TensorFlow framework version 1.10.0 (Google Inc.) on a server (GeForce 249 10 GTX TITAN X GPU and Intel(R) Xeon(R) CPU X5570 @2.93 GHz with 48 GB RAM, running a Linux 250 operating system). It takes dozens of minutes to make our diffractive neural network converge. Notice that our process does not involve nonlinear activation function. We leave that to future work and experimentally compensate for its absence by a nonlinear optical medium, such as a photorefractive crystal and magnetooptical trap.
Experiment setup
A nearfield 3D scanning system was used for measurements. A horn antenna centred at the twolayer metasurface was used as the excitation source. Another small monopole probe oriented vertically to the ground was used to scan the relative amplitude and phase (S21) of the electric field E_{x}. In measurement, the source and probe were connected to port 1 and port 2 of a vector network analyser, respectively, and the parameter S21 was recorded. The scan resolution in the xoy plane was 2 mm × 2 mm.
References
 1.
Caulfield, H. J. & Dolev, S. Why future supercomputing requires optics. Nat. Photonics 4, 261–263 (2010).
 2.
Silva, A. et al. Performing mathematical operations with metamaterials. Science 343, 160–163 (2014).
 3.
Zhu, T. F. et al. Plasmonic computing of spatial differentiation. Nat. Commun. 8, 15391 (2017).
 4.
Guo, C. et al. Photonic crystal slab Laplace operator for image differentiation. Optica 5, 251–256 (2018).
 5.
Graves, A. et al. Hybrid computing using a neural network with dynamic external memory. Nature 538, 471–476 (2016).
 6.
Lane, N. D. et al. Squeezing deep learning into mobile and embedded devices. IEEE Pervasive Comput. 16, 82–88 (2017).
 7.
Miller, D. A. B. Are optical transistors the logical next step? Nat. Photonics 4, 3–5 (2010).
 8.
Wei, H. et al. Quantum dotbased local field imaging reveals plasmonbased interferometric logic in silver nanowire networks. Nano Lett. 11, 471–475 (2011).
 9.
Wei, H. et al. Cascaded logic gates in nanophotonic plasmon networks. Nat. Commun. 2, 387 (2011).
 10.
Fu, Y. L. et al. Alloptical logic gates based on nanoscale plasmonic slot waveguides. Nano Lett. 12, 5784–5790 (2012).
 11.
Sang, Y. G. et al. Broadband multifunctional plasmonic logic gates. Adv. Opt. Mater. 6, 1701368 (2018).
 12.
Xu, Q. F. & Lipson, M. Alloptical logic based on silicon microring resonators. Opt. Express 15, 924–929 (2007).
 13.
McCutcheon, M. W. et al. Alloptical conditional logic with a nonlinear photonic crystal nanocavity. Appl. Phys. Lett. 95, 221102 (2009).
 14.
Lee, S. W. et al. A fast and lowpower microelectromechanical systembased nonvolatile memory device. Nat. Commun. 2, 220 (2011).
 15.
Driscoll, T. et al. Memory metamaterials. Science 325, 1518–1521 (2009).
 16.
Manjappa, M. et al. Reconfigurable MEMS Fano metasurfaces with multipleinput–output states for logic operations at terahertz frequencies. Nat. Commun. 9, 4056 (2018).
 17.
Lin, X. et al. Alloptical machine learning using diffractive deep neural networks. Science 361, 1004–1008 (2018).
 18.
Raeker, B. O. & Grbic, A. Compound metaoptics for amplitude and phase control of wave fronts. Phys. Rev. Lett. 122, 113901 (2019).
 19.
Esteva, A. et al. Dermatologistlevel classification of skin cancer with deep neural networks. Nature 542, 115–118 (2017).
 20.
Goodman, J. W. Introduction to Fourier Optics 3rd edn (Roberts and Company, Greenwoood Village, 2005).
 21.
Cai, T. et al. Highperformance bifunctional metasurfaces in transmission and reflection geometries. Adv. Opt. Mater. 5, 1600506 (2017).
 22.
Wu., L. W. et al. Hightransmission ultrathin huygens’ metasurface with 360° phase control by using doublelayer transmitarray elements. Phys. Rev. Appl. 12, 024012 (2019).
 23.
Qian, C. et al. Experimental observation of superscattering. Phys. Rev. Lett. 122, 063901 (2019).
 24.
Ye, D. X. et al. Observation of reflectionless absorption due to spatial Kramers–Kronig profile. Nat. Commun. 8, 51 (2017).
 25.
Yi, H. et al. 3D printed millimeterwave and terahertz lenses with fixed and frequency scanned beam. IEEE Trans. Antennas Propag. 64, 442–449 (2016).
 26.
Estakhri, N. M., Edwards, B. & Engheta, N. Inversedesigned metastructures that solve equations. Science 363, 1333–1338 (2019).
 27.
Qian, C. et al. Deeplearningenabled selfadaptive microwave cloak without human intervention. Nat. Photonics https://www.nature.com/articles/s4156602006042 (2020).
 28.
Molesky, S. et al. Inverse design in nanophotonics. Nat. Photonics 12, 659–670 (2018).
 29.
Qian, C. et al. Transient response of a signal through a dispersive invisibility cloak. Opt. Lett. 41, 4911–4914 (2016).
 30.
Qian, C. et al. Observing the transient buildup of a superscatterer in the time domain. Opt. Express 25, 4967–4974 (2017).
 31.
Jang, M. et al. Wavefront shaping with disorderengineered metasurfaces. Nat. Photonics 12, 84–90 (2018).
Acknowledgements
The work at Zhejiang University was sponsored by the National Natural Science Foundation of China (NNSFC) under Grants Nos. 61625502, 11961141010, and 61975176, the TopNotch Young Talents Programme of China, the Fundamental Research Funds for the Central Universities, Nanyang Technological University for NAP StartUp Grant, and the Singapore Ministry of Education (Grant Nos. MOE2018T21022 (S), MOE2016T31006 and Tier 1 RG174/16 (S)). C.Q. was supported by the Chinese Scholarship Council (CSC No. 201906320294) and Zhejiang University Academic Award for Outstanding Doctoral Candidates.
Author information
Affiliations
Contributions
C.Q. conceived the idea and conducted the numerical simulation and experiment; Y.S. helped prepare the experimental samples. C.Q. and X.L. interpreted detailed results and contributed extensively to the writing of the manuscript. X.L., B.Z. and H.C. supervised the project. All members contributed to the discussion and analysis of the results.
Corresponding authors
Ethics declarations
Conflict of interest
The authors declare that they have no conflict of interest.
Supplementary information
Rights and permissions
Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license, and indicate if changes were made. The images or other third party material in this article are included in the article’s Creative Commons license, unless indicated otherwise in a credit line to the material. If material is not included in the article’s Creative Commons license and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/.
About this article
Cite this article
Qian, C., Lin, X., Lin, X. et al. Performing optical logic operations by a diffractive neural network. Light Sci Appl 9, 59 (2020). https://doi.org/10.1038/s4137702003032
Received:
Revised:
Accepted:
Published:
DOI: https://doi.org/10.1038/s4137702003032
Further reading

Intelligent designs in nanophotonics: from optimization towards inverse creation
PhotoniX (2021)

Research progress in optical neural networks: theory, applications and developments
PhotoniX (2021)

Alloptical informationprocessing capacity of diffractive surfaces
Light: Science & Applications (2021)

Optoelectronic convolutional neural networks based on timestretch method
Science China Information Sciences (2021)

Ultracompact Universal LinearOptical Logic Gate Based on Single Rectangle Plasmonic Slot Nanoantenna
Plasmonics (2021)