<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="https://fabio.pierazzi.com/feed.xml" rel="self" type="application/atom+xml"/><link href="https://fabio.pierazzi.com/" rel="alternate" type="text/html" hreflang="en"/><updated>2026-10-21T12:53:24+00:00</updated><id>https://fabio.pierazzi.com/feed.xml</id><title type="html">blank</title><subtitle>Personal Web page of Fabio Pierazzi. </subtitle><entry><title type="html">Malware Datasets with Timestamps</title><link href="https://fabio.pierazzi.com/blog/2022/malware-datasets/" rel="alternate" type="text/html" title="Malware Datasets with Timestamps"/><published>2022-03-22T21:01:00+00:00</published><updated>2022-03-22T21:01:00+00:00</updated><id>https://fabio.pierazzi.com/blog/2022/malware-datasets</id><content type="html" xml:base="https://fabio.pierazzi.com/blog/2022/malware-datasets/"><![CDATA[<p>This article reports a brief summary of the main datasets we have released for malware research. I will try to keep this list updated with new entries, and use the “changelog” at the end to track major changes to this article.</p> <h2 id="datasets-available">Datasets Available</h2> <p>The <strong>timestamped malware datasets</strong> which we have released for research are the following:</p> <ul> <li><a href="https://s2lab.cs.ucl.ac.uk/projects/tesseract/"><strong>Tesseract dataset</strong></a> (apps from 2014 to 2016): malware downloaded from AndroZoo with extracted feature spaces for <a href="https://www.ndss-symposium.org/wp-content/uploads/2017/09/11_3_1.pdf">DREBIN</a> and <a href="https://www.ndss-symposium.org/ndss2017/ndss-2017-programme/mamadroid-detecting-android-malware-building-markov-chains-behavioral-models/">MaMaDroid</a>.</li> <li><a href="https://s2lab.cs.ucl.ac.uk/projects/intriguing/"><strong>S&amp;P20 APG dataset</strong></a> (apps from 2017 to 2018): malware downloaded from AndroZoo with extracted feature spaces for <a href="https://www.ndss-symposium.org/wp-content/uploads/2017/09/11_3_1.pdf">DREBIN</a> and <a href="https://www.ndss-symposium.org/ndss2017/ndss-2017-programme/mamadroid-detecting-android-malware-building-markov-chains-behavioral-models/">MaMaDroid</a>.</li> </ul> <p>Please note that we are not releasing the goodware/malware directly, but instead only the SHAs of the apps we considered. To re-download the original apks, you can re-download them from <a href="https://androzoo.uni.lu">AndroZoo</a>.</p> <h2 id="loading-features">Loading Features</h2> <p>We did separate the dataset into three JSON files: X, Y, and meta. The following function is used to load the dataset with timestamps:</p> <div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="kn">import</span> <span class="n">datetime</span>
<span class="kn">import</span> <span class="n">json</span>
<span class="kn">import</span> <span class="n">logging</span>
<span class="kn">import</span> <span class="n">time</span>

<span class="k">def</span> <span class="nf">load_features</span><span class="p">(</span><span class="n">fname</span><span class="p">,</span> <span class="n">shas</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
    <span class="sh">"""</span><span class="s">Load feature set.

    Args:
        feature_set (str): The common prefix for the dataset.
            (e.g., </span><span class="sh">'</span><span class="s">data/features/drebin</span><span class="sh">'</span><span class="s"> -&gt; </span><span class="sh">'</span><span class="s">data/features/drebin-[X|Y|meta].json</span><span class="sh">'</span><span class="s">)

        shas (bool): Whether to include shas. In some versions of the dataset,
            shas were included to double-check alignment - these are _not_ features
            and _must_ be removed before training.

    Returns:
        Tuple[List[Dict], List, List]: The features, labels, and timestamps
            for the dataset.

    </span><span class="sh">"""</span>
    <span class="n">logging</span><span class="p">.</span><span class="nf">info</span><span class="p">(</span><span class="sh">'</span><span class="s">Loading features...</span><span class="sh">'</span><span class="p">)</span>
    <span class="k">with</span> <span class="nf">open</span><span class="p">(</span><span class="sh">'</span><span class="s">{}-X.json</span><span class="sh">'</span><span class="p">.</span><span class="nf">format</span><span class="p">(</span><span class="n">fname</span><span class="p">),</span> <span class="sh">'</span><span class="s">r</span><span class="sh">'</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
        <span class="n">X</span> <span class="o">=</span> <span class="n">json</span><span class="p">.</span><span class="nf">load</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
    <span class="c1"># if not shas:
</span>    <span class="c1">#     [o.pop('sha256') for o in X]
</span>
    <span class="n">logging</span><span class="p">.</span><span class="nf">info</span><span class="p">(</span><span class="sh">'</span><span class="s">Loading labels...</span><span class="sh">'</span><span class="p">)</span>
    <span class="k">with</span> <span class="nf">open</span><span class="p">(</span><span class="sh">'</span><span class="s">{}-Y.json</span><span class="sh">'</span><span class="p">.</span><span class="nf">format</span><span class="p">(</span><span class="n">fname</span><span class="p">),</span> <span class="sh">'</span><span class="s">rt</span><span class="sh">'</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
        <span class="n">y</span> <span class="o">=</span> <span class="n">json</span><span class="p">.</span><span class="nf">load</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
    <span class="k">if</span> <span class="sh">'</span><span class="s">apg</span><span class="sh">'</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">fname</span><span class="p">:</span>
        <span class="n">y</span> <span class="o">=</span> <span class="p">[</span><span class="n">o</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">o</span> <span class="ow">in</span> <span class="n">y</span><span class="p">]</span>

    <span class="n">logging</span><span class="p">.</span><span class="nf">info</span><span class="p">(</span><span class="sh">'</span><span class="s">Loading timestamps...</span><span class="sh">'</span><span class="p">)</span>
    <span class="k">with</span> <span class="nf">open</span><span class="p">(</span><span class="sh">'</span><span class="s">{}-meta.json</span><span class="sh">'</span><span class="p">.</span><span class="nf">format</span><span class="p">(</span><span class="n">fname</span><span class="p">),</span> <span class="sh">'</span><span class="s">rt</span><span class="sh">'</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
        <span class="n">t</span> <span class="o">=</span> <span class="n">json</span><span class="p">.</span><span class="nf">load</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
    <span class="n">t</span> <span class="o">=</span> <span class="p">[</span><span class="n">o</span><span class="p">[</span><span class="sh">'</span><span class="s">dex_date</span><span class="sh">'</span><span class="p">]</span> <span class="k">for</span> <span class="n">o</span> <span class="ow">in</span> <span class="n">t</span><span class="p">]</span>
    <span class="k">if</span> <span class="sh">'</span><span class="s">apg</span><span class="sh">'</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">fname</span><span class="p">:</span>
        <span class="n">t</span> <span class="o">=</span> <span class="p">[</span><span class="n">datetime</span><span class="p">.</span><span class="nf">strptime</span><span class="p">(</span><span class="n">o</span> <span class="k">if</span> <span class="nf">isinstance</span><span class="p">(</span><span class="n">o</span><span class="p">,</span> <span class="nb">str</span><span class="p">)</span> <span class="k">else</span> <span class="n">time</span><span class="p">.</span><span class="nf">strftime</span><span class="p">(</span><span class="sh">'</span><span class="s">%Y-%m-%d %H:%M:%S</span><span class="sh">'</span><span class="p">,</span> <span class="n">time</span><span class="p">.</span><span class="nf">localtime</span><span class="p">(</span><span class="n">o</span><span class="p">)),</span>
                               <span class="sh">'</span><span class="s">%Y-%m-%dT%H:%M:%S</span><span class="sh">'</span><span class="p">)</span> <span class="k">for</span> <span class="n">o</span> <span class="ow">in</span> <span class="n">t</span><span class="p">]</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">t</span> <span class="o">=</span> <span class="p">[</span><span class="n">datetime</span><span class="p">.</span><span class="nf">strptime</span><span class="p">(</span><span class="n">o</span> <span class="k">if</span> <span class="nf">isinstance</span><span class="p">(</span><span class="n">o</span><span class="p">,</span> <span class="nb">str</span><span class="p">)</span> <span class="k">else</span> <span class="n">time</span><span class="p">.</span><span class="nf">strftime</span><span class="p">(</span><span class="sh">'</span><span class="s">%Y-%m-%d %H:%M:%S</span><span class="sh">'</span><span class="p">,</span> <span class="n">time</span><span class="p">.</span><span class="nf">localtime</span><span class="p">(</span><span class="n">o</span><span class="p">)),</span>
                               <span class="sh">'</span><span class="s">%Y-%m-%d %H:%M:%S</span><span class="sh">'</span><span class="p">)</span> <span class="k">for</span> <span class="n">o</span> <span class="ow">in</span> <span class="n">t</span><span class="p">]</span>
    <span class="k">return</span> <span class="n">X</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">t</span>
</code></pre></div></div> <p>Please remember to remove any SHAs from the dataset and do not consider them as features.</p> <h2 id="memory-errors">Memory Errors</h2> <p>If you are a BSc/MSc student doing a dissertation, and you are relying on our datasets, but do not have access to a powerful server, you may want to consider “downsampling” strategies to reduce the size of the dataset to make it more manageable.</p> <h3 id="changelog">Changelog</h3> <ul> <li>24/03/2022: v1.0 published</li> </ul>]]></content><author><name></name></author><category term="tutorial"/><category term="tutorial"/><category term="python"/><category term="dataset"/><category term="malware"/><category term="loading"/><category term="features"/><category term="timestamps"/><summary type="html"><![CDATA[This post covers some of the research datasets we have built for research.]]></summary></entry><entry><title type="html">How to Review Literature in Systems Security</title><link href="https://fabio.pierazzi.com/blog/2021/literature-review-systems-security/" rel="alternate" type="text/html" title="How to Review Literature in Systems Security"/><published>2021-10-29T21:00:00+00:00</published><updated>2021-10-29T21:00:00+00:00</updated><id>https://fabio.pierazzi.com/blog/2021/literature-review-systems-security</id><content type="html" xml:base="https://fabio.pierazzi.com/blog/2021/literature-review-systems-security/"><![CDATA[<blockquote> <p><strong>Note:</strong> This post is outdated. For the latest and most comprehensive advice on literature review in systems security, please check out the <a href="/resources/literature-review">Resources page</a>.</p> </blockquote> <p>Are you a BSc or MSc student embarking on your dissertation, or an early-stage Ph.D. researcher feeling uncertain about how to approach a literature review in systems security? If so, this post is for you. Here, I’ll share practical advice and guidance to help you navigate the process of reviewing the literature and positioning your work within the current state of the art in systems security research.</p> <p><strong>Friendly Note:</strong> Everything in this post comes from my own experience (which is always growing and changing!), and reflects my personal take on reviewing literature in Systems Security &amp; AI. My goal is simply to share some tips and starting points for students who are beginning their first big research project and want to get a handle on how to approach a literature review. If you have thoughts, questions, or suggestions, If you have any feedback, I’d be more than happy to challenge my views, and revise my recommendations!</p> <hr/> <p>In these years as an academic supervisor, I see students struggle more and more with understanding how to conduct a literature review. This is understandable: the field has been growing extensively, and more and more papers get published in reputable venues, so it is hard to create a “mental compass” to orient yourself in this sea of literature. Even within Computer Science, every discipline has different venues and understanding how to look for related works requires some effort and experience. Indeed, this guide is meant mostly for Systems Security.</p> <p>During my undergraduate dissertation, I really struggled to understand what it meant to write a “Related Work” section. I got confused because—to me—it looked very similar to the “Introduction” section. Moreover, I felt intimidated to approach and read “research papers” written by experts, as I thought you needed to be a “genius” to read one of those.</p> <p>In practice, a BSc/MSc in Computer Science should give you all the ingredients you need to first approach a research paper. You need to read within your area of expertise, and be patient and persistent: you will not understand everything after one read, and you need to be patient to really understand concepts sometimes. Another important skill is to learn how to navigate the literature, so you can build the foundational knowledge you need to understand more advanced topics. Nevertheless, good research papers—while technical—are also written and structured in an extremely clear way, as they are meant to be understood by a technical audience.</p> <hr/> <h2 id="publication-quality">Publication Quality</h2> <p>Determining the quality of publications is a hard problem that requires expertise and in-depth critical assessment of what you are reading. However, you may use some criteria to prioritize your literature review and identify papers which are more relevant to your research.</p> <h3 id="publication-venues">Publication venues</h3> <p>In academia, research articles are mostly published via <strong>peer-review</strong>. In <strong>academic conferences</strong>, a program committee of experts reviews the paper independently and determines whether its originality, rigor and significance is sufficient to be published at a certain venue. In <strong>academic journals</strong>, there is a committee of “associate editors” which then invite external experts to coordinate the review process.</p> <p>Hence, <strong>publication venue</strong> can be typically used as initial proxies of quality.</p> <p>Keep in mind there could still be bad papers published in good venues (and viceversa), but indicatively venues that are quite selective tend to contain work of higher quality. I find this could be useful especially when you start as a student to read research paper and you feel “lost in the sea”.</p> <p>My list does not intend to be exhaustive, but just indicative.</p> <p>Two highly recommended reads are the following:</p> <ul> <li><a href="https://www.sec.cs.tu-bs.de/~konrieck/topnotch/">Influental Security Papers</a>, by Konrad Rieck, TU Berlin</li> <li><a href="https://www.s3.eurecom.fr/~balzarot/notes/top4_2020/">System Security Circus</a>, by Davide Balzarotti, S3@Eurecom</li> </ul> <h4 id="conferences">Conferences</h4> <p>Academic conferences typically have one edition per year in which authors meet together to discuss and present the works published in that year’s proceedings. Now it has become more frequent to have multiple submission deadlines throughout the years, but each conference remains with a yearly edition in which works are presented.</p> <p>In Systems Security, there are typically four main academic conferences which are commonly considered <strong>top-tier conferences</strong> by the community:</p> <ul> <li><a href="https://www.ieee-security.org/TC/SP2022/">IEEE Symposium on Security &amp; Privacy (S&amp;P, Oakland)</a></li> <li><a href="https://www.usenix.org/conference/usenixsecurity22">USENIX Security Symposium (Sec)</a></li> <li><a href="https://www.sigsac.org/ccs/CCS2021/">ACM Computers and Communication Security (CCS)</a></li> <li><a href="https://www.ndss-symposium.org/ndss2022/#">The Network and Distributed System Security (NDSS) Symposium</a></li> </ul> <p>Apart from the “top four”, other highly reputable venues in Systems Security include (but are not limited to):</p> <ul> <li><a href="http://www.ieee-security.org/TC/EuroSP2021/">IEEE European Symposium on Security and Privacy (EuroS&amp;P)</a></li> <li><a href="https://www.acsac.org">Annual Computer Security Applications Conference (ACSAC)</a></li> <li><a href="https://asiaccs2022.conferenceservice.jp/">ACM ASIA Conference on Computer and Communications Security (ASIACCS)</a></li> <li><a href="https://raid2021.org">International Symposium on Research in Attacks, Intrusions and Defenses (RAID)</a></li> <li><a href="https://dimva2021.campus.ciencias.ulisboa.pt">Conference on Detection of Intrusions and Malware &amp; Vulnerability Assessment (DIMVA)</a></li> <li><a href="https://esorics2021.athene-center.de">European Symposium on Research in Computer Security (ESORICS)</a></li> <li><a href="http://www.codaspy.org/2022/">ACM Conference on Data and Application Security and Privacy (CODASPY)</a></li> </ul> <p>There are also <strong>top workshops</strong> on specific sub-topics, such as: <a href="https://www.usenix.org/conference/scainet20">ScAInet</a>, <a href="https://aisec.cc">AISec</a>, <a href="https://www.ieee-security.org/TC/SP2021/SPW2021/WOOT21/">w00t</a>, <a href="https://www.ieee-security.org/TC/SP2021/SPW2021/dls_website/">DLS</a>, which are often co-located with top conferences. Workshops typically publish preliminary results or interesting new ideas, which maybe do not have yet a sufficiently large experimental evaluation or fully fledged theory behind them.</p> <p>Sometimes work in Systems Security can also be published in closely-related venues but more focused on Data Mining, ML, AI. For example, <a href="https://www2022.thewebconf.org">The Web Conference ACM</a> which is a first-tier conference in data mining has a Security &amp; Privacy track. Other top tier venues in data mining, AI and ML include: <strong>ICML</strong>, <strong>ICLR</strong>, <strong>WSDM</strong>, <strong>NeurIPS</strong>, <strong>IJCAI</strong>, <strong>AAAI</strong>.</p> <h4 id="journals">Journals</h4> <p>Journals in Systems Security are typically used for extensions or consolidation of research results of a conference version, but often host also original research works.</p> <p>Here is a rough list of reputable journals in Systems Security:</p> <ul> <li><a href="https://dl.acm.org/journal/tops">ACM Transactions on Privacy and Security (TOPS; ex-TISSEC)</a></li> <li><a href="https://ieeexplore.ieee.org/xpl/RecentIssue.jsp?punumber=10206">IEEE Transactions on Information Forensics and Security (TIFS)</a></li> <li><a href="https://ieeexplore.ieee.org/xpl/RecentIssue.jsp?punumber=8858">IEEE Transactions on Dependable and Security Computing (TDSC)</a></li> <li><a href="https://www.iospress.com/catalog/journals/journal-of-computer-security">Journal of Computer Security</a></li> <li><a href="https://www.journals.elsevier.com/computers-and-security">Elsevier Computers &amp; Security</a></li> </ul> <p>Typically, ACM and IEEE journals with the name “Transactions” in it tend to be the more prestigious ones, but there are also other highly reputable journals which build a reputation for themselves.</p> <p>In the field of AI and ML, some very good journals are also <a href="https://www.journals.elsevier.com/pattern-recognition">Pattern Recognition</a>, and <a href="https://www.jmlr.org">JMLR</a>.</p> <h3 id="number-of-citations">Number of citations</h3> <p>As humans, we like to measure things. Many systems refer to <strong>number of citations</strong> as a proxy for quality and impact. While this is not necessarily true, papers with high number of citations may be either false positives (e.g., papers cited just because people searched for “computer worm” and cited the first result on scholar), or actually be very influential papers that heavily influenced research in a certain field.</p> <p>Typically, you should also look out for “<strong>Test of Time Awards</strong>”, which are given to influental papers typically after 10 years of their publications.</p> <h3 id="technical-reports-white-papers-and-pre-prints">Technical reports, white papers and pre-prints</h3> <p>Industry frequently publishes technical reports or white papers on some technology. Sometimes, also academics do it (although they mostly call them “technical reports”). While technical reports can undoubtedly be informative, it is important to note that they are <strong>not peer-reviewed</strong>.</p> <p>Hence, even when you find paper pre-prints on websites such as <a href="https://arxiv.org">arXiv</a>, be sure to double-check if they are published somewhere.</p> <p>Sometimes the authors’ name, reputation and affiliation is used as proxy for the quality, but you always need to be more cautious if has not been peer-reviewed, and to critically assess the work itself. It is important to remember, as <strong>Richard Feynman</strong> said:</p> <blockquote> <p>“If [a theory] disagrees with experiments, it’s wrong. And that simple statement is the key to science. It doesn’t make a difference how beautiful your guess is, it doesn’t make a difference how smart you are who made the guess, or what his name is: if it disagrees with the experiment, it’s wrong. That’s all there is to it.”</p> </blockquote> <blockquote> <p><a href="https://youtu.be/LIxvQMhttq4">Richard Feynman</a></p> </blockquote> <p>There can be a variety of valid reasons for which a work isn’t published yet (maybe it is currently under review). Nevertheless, it is important that you keep in mind that accepted work has been peer-reviewed by experts, and hence you should generally hold it to a higher standard than technical reports.</p> <h3 id="publication-years">Publication years</h3> <p>Keep in mind that <strong>research is incremental</strong>: findings at time <em>t</em> may be disproved at time <em>t+1</em>. We always build on the shoulders of giants, but it is a neverending process. While it is fundamental not to forget prior research, it is important to check that your references are up to date with the current state of the art. Even 5 years in the field of computer security are a lot of time.</p> <hr/> <h2 id="how-to-find-related-works">How to find related works</h2> <p>I try to summarize some useful tips and tricks to find relevant works in your field:</p> <ul> <li><strong>Paper search engines</strong>: it may sound trivial, but I think <a href="https://scholar.google.com">Google Scholar</a> is your best search engine at the moment for finding research papers. If you do not have access to scholar, also <a href="https://dblp.org">dblp</a> is a good place to look into.</li> <li><strong>Read “Related Work” sections</strong>: If you find one paper that is very close to what you are doing, look at the papers they cite. This is often a good source of information, and provides</li> <li><strong>Look at the “Cited by” field on Google Scholar</strong>: If you click on the “Cited by” field on Google Scholar, you will also find a list of papers who cited that one, typically sorted by citation number. It can be useful to track more recent advancements of the state of the art. you interesting references to look into.</li> <li><strong>Surveys</strong> and <strong>Systemization of Knowledge (SoK)</strong> papers are also a great place where to understand better the state of the art in a more condensed way. Sometimes also <strong>Reading Lists</strong> are published by prominent researchers in a field, such as the <a href="https://nicholas.carlini.com/writing/2018/adversarial-machine-learning-reading-list.html">Adversarial Machine Learning Reading List </a> from Nicholas Carlini.</li> <li><strong>Search researchers profiles</strong>: If a researcher has published a top paper on a certain systems security topic, if you look at their research profile (e.g., personal home page, dblp, or Google Scholar), you may find other interesting works in the topic.</li> <li><strong>Sessions of recent security conferences</strong>: Conferences are held once per year, and their presentation program is typically divided into “sessions” of a certain topic. For example, if you are doing research in Web Security, a conference may have a “Web Security” session in its program, which can be useful to find relevant works in that area at the moment.</li> <li><strong>Be creative in your keywords search</strong>: Keywords and trends change over time, even for the same topic. Unfortunately—to the best of my knowledge—most paper search engines rely mostly on paper titles, not much on its content. Hence, you need to be smart in your keywords search, since some papers may be using different terminologies. For example, back in 2016, when I started doing research in Android malware analysis, I looked up for “Android clustering” on Google Scholar, or “mobile malware clustering”, and nothing was coming out of my searches. I initially thought no one else did it, until I found out that people was mostly framing it as “malware family identification”!</li> </ul> <h3 id="there-is-no-work-on-this-topic">“There is no work on this topic”</h3> <p>Students often come back to me saying they did not find anything on a certain topic. Well, there can be two situations:</p> <ul> <li>You had a novel idea for opening a new research field that no one else had before. Amazing!</li> <li>You did not “yet” find anything related.</li> </ul> <p>Unfortunately, it is often the second case.</p> <p>Sometimes you need to be creative in your literature review as well. Let me give an example. Maybe you are doing a research on identifying a new type of network attacks that came out earlier this year. But in most cases, even new attacks rely on component previously proposed in old versions. For example, if you want to identify attacker communications within internal networks, there has been a lot of research on “computer worms”. Or maybe even research on graphs and social network may be relevant with respect to the algorithms you are using.</p> <hr/> <h2 id="advice-on-reading-research-papers">Advice on reading research papers</h2> <p>When you first approach a literature review, you will find tens or hundreds of papers related to your work. It can be quite intimidating, and you may feel overwhelmed by the sheer amount of papers that pile up in your “to-read” folder. Indeed, reading thoroughly all of the papers published in a field would be a quite challenging task, if not impossible.</p> <p>I do have the following advices:</p> <ul> <li><strong>Be kind on yourself</strong>. First of all, accept that you cannot possibly read everything thoroughly. Moreover, <strong>understanding is an incremental process</strong>. You will not understand 100% of a paper on a first read. At least, I don’t. It takes time. The more you read about a certain topic, or re-read certain sections, the more you understand about it. I myself still go back and re-read some seminal papers, and always learn something new from a refreshed perspective. You will continuously grow as a researcher and as a professional, and so will your ability to capture connections and meanings in what you read.</li> <li><strong>Read abstracts before choosing which papers to dive into</strong>. Abstracts are there for a reason: to give you an idea of what the paper is contributing to the state of the art. Reading abstracts from many papers should give you an idea of what are the relevant challenges tackled by people, and a small intuition on how they managed to overcome prior works. Of course, abstracts are not sufficient to fully understand a work, but even reading one hundred abstracts becomes a manageable task, versus reading in detail one hundred papers papers. While you are still looking at the literature at a high level, it is also a good practice to skim papers by reading <strong>introduction</strong>, <strong>conclusions</strong>, and going over main results and figures. This is just to identify the works which are most relevant with your research, and which you should read more thoroughly.</li> <li><strong>Talk to colleagues/supervisors</strong>. People will have advice on which papers to read on a certain topic, especially if they’re experts in that sub-area. You can also ask feedback of whether a certain paper you found could be considered relevant or not for your project.</li> <li><strong>Try to (re)implement small ideas</strong>. It is often the case that you may get stuck into “reading mode”, and blocked by the high amount of information. If you try to implement or replicate someone else’s approach, see it as a great learning opportunity which will also benefit your literature review: you will start understanding better how other people have solved certain issues, and what are important questions that need answers. You may also identify missing bits in the literature.</li> <li><strong>Reading groups</strong> are an option where each person reads and summarizes a recent paper to the other members of the reading group. This helps scaling, and improves networking and presentation skills.</li> </ul> <hr/> <h2 id="positioning-your-work">Positioning your work</h2> <p>Understanding how to <strong>position</strong> your work within the state of the art is hard.</p> <p>In your research dissertation/paper, you do not only need to provide a “summary” of the related work. Positioning implies that you “compare and contrast” your proposed approach with existing literature.</p> <p>Here is some advice I always refer to as a starting point:</p> <blockquote> <p>[…] “At a high level what are the differences in what you are doing, and what others have done? Keep this at a high level, you can refer to a future section where specific details and differences will be given. But it is important for the reader to know at a high level, what is new about this work compared to other work in the area.”</p> </blockquote> <blockquote> <p><a href="https://www.cs.columbia.edu/~hgs/etc/intro-style.html">Jim Kurose (UMass), Writing a Good Introduction</a></p> </blockquote> <p>In the previous quote, the author is talking about the Introduction section, where you should just give a high-level intuition of what you are doing that is novel. The Related Work section is dedicated to diving deeper into that comparison, and answering in more details many questions, such as:</p> <ul> <li>Is your approach relying on previous techniques?</li> <li>Are you solving a new problem? Are there other works solving similar problems?</li> <li>What makes your approach better than the state of the art? Is it faster? Is it more efficient? Is it more reliable?</li> </ul> <p>Hence, it is not sufficient to just “list” existing literature, but you really need to explicitly write how each work is related to yours, and where you are improving the state of the art.</p> <p>The “Related Work” section need to be easily accessible to readers, as there is a risk of listing and comparing against a huge amount of papers and losing the “big picture”. So, I find it often useful for clarify to <strong>identify two/three macro-areas of related research</strong> and summarize my contributions with respect to works in each of those areas.</p> <hr/> <h2 id="final-considerations">Final Considerations</h2> <p>I hope you have found this post useful.</p> <p>This is not meant to be an exhaustive list of relevant publication venues, and tips for conducting a literature review. In general, you should see this just as an initial advice to help you navigate more confidently within the state of the art of Systems Security, upon venturing in it for the first time.</p> <p>I would be very happy to hear what are your experiences and if you have any other relevant advice into conducting literature review.</p> <hr/> <h4 id="changelog">Changelog</h4> <ul> <li>v1.0: Nov 16, 2021</li> <li>v1.0.1: Nov 17, 2021 - <em>Fixed System Security Circus link; added Carlini adversarial reading list</em></li> </ul>]]></content><author><name></name></author><category term="tutorial"/><category term="tutorial"/><category term="writing"/><summary type="html"><![CDATA[Advice on how to do literature review and related work in the field of computer security and AI.]]></summary></entry><entry><title type="html">Introduction to Python multiprocessing</title><link href="https://fabio.pierazzi.com/blog/2019/introduction-to-multiprocessing/" rel="alternate" type="text/html" title="Introduction to Python multiprocessing"/><published>2019-03-02T21:01:00+00:00</published><updated>2019-03-02T21:01:00+00:00</updated><id>https://fabio.pierazzi.com/blog/2019/introduction-to-multiprocessing</id><content type="html" xml:base="https://fabio.pierazzi.com/blog/2019/introduction-to-multiprocessing/"><![CDATA[<p>In the past few years, I have been frequently asked how to easily parallelize in Python. It seems that people is often confused by the documentation online and are not sure which solution to go for. So, I decided to write a blog post about a minimum working example of <code class="language-plaintext highlighter-rouge">multiprocessing</code>, which should be pretty easy and straightforward to use for a lot of situations.</p> <h2 id="requirements">Requirements</h2> <p>We need to import a couple of libraries: <code class="language-plaintext highlighter-rouge">multiprocessing</code> and (optionally) <code class="language-plaintext highlighter-rouge">tqdm</code>. In <code class="language-plaintext highlighter-rouge">Python3</code> (stable at 3.7 at the time of writing), the <code class="language-plaintext highlighter-rouge">multiprocessing</code> library is natively included; this library allows you to define a function that you can spawn with different parameters on separate processes (it does not perform multithreading).</p> <div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="n">multiprocessing</span>
</code></pre></div></div> <p>The second library I would recommend is <code class="language-plaintext highlighter-rouge">tqdm</code>, which is not required but it has made my coding life so much easier since I started using it. This library creates a smart progress bar when it is used to wrap an iterable object (e.g., a list in a for cycle). To install it, just run <code class="language-plaintext highlighter-rouge">pip3 install tqdm --upgrade</code>. We will see how to use <code class="language-plaintext highlighter-rouge">tqdm</code> in its very basic form, but I recommend you to have a look at its <a href="https://github.com/tqdm/tqdm">official documentation</a> for more advanced usage.</p> <div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">from</span> <span class="n">tqdm</span> <span class="kn">import</span> <span class="n">tqdm</span>
</code></pre></div></div> <h2 id="function-to-parallelize">Function to parallelize</h2> <p>First, let us define the function that you would like to parallelize. You often have to rethink the logic of your program, but if you have some independent cpu-intensive operations (e.g., training, parsing of long files, preprocessing), chances are there is a way to rethink your code to create a single, independent function that will run on a separate process.</p> <p>Let us define here a function, namely <code class="language-plaintext highlighter-rouge">function_to_parallelize</code>, that just takes two parameters as input and sums them. In this function you can actually do any sort of processing, as long as it is dependent solely on the input parameters. It is relevant to observe that you must use a <strong>single input parameter</strong> for this function. This is not a problem, as this single parameter can be a dictionary containing many parameters that you can unpack. For the purpose of this tutorial, I am using <code class="language-plaintext highlighter-rouge">param1</code> and <code class="language-plaintext highlighter-rouge">param2</code> as parameter names, but of course you can use any name and number of parameters (as long as you embed them within a single <code class="language-plaintext highlighter-rouge">params</code> dictionary).</p> <p>Of course, parameter names need to match the names in the list you pass to the <code class="language-plaintext highlighter-rouge">multiprocessing</code> library (as we will see in a bit).</p> <div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">def</span> <span class="nf">function_to_parallelize</span><span class="p">(</span><span class="n">params</span><span class="p">):</span>
    <span class="n">param1</span> <span class="o">=</span> <span class="n">params</span><span class="p">[</span><span class="sh">'</span><span class="s">param1</span><span class="sh">'</span><span class="p">]</span>
    <span class="n">param2</span> <span class="o">=</span> <span class="n">params</span><span class="p">[</span><span class="sh">'</span><span class="s">param2</span><span class="sh">'</span><span class="p">]</span>

    <span class="c1"># I would recommend to use a dictionary
</span>    <span class="c1"># so you can create richer results
</span>    <span class="c1"># to return to the main process
</span>    <span class="n">result</span> <span class="o">=</span> <span class="p">{}</span>

    <span class="c1"># Do your processing with param1 and param2.
</span>    <span class="c1"># Here, you can do any sort of processing, and
</span>    <span class="c1"># it will be executed independently on a separate process
</span>    <span class="c1"># on a separate (virtual) core of your CPU
</span>    <span class="n">result</span><span class="p">[</span><span class="sh">'</span><span class="s">sum</span><span class="sh">'</span><span class="p">]</span> <span class="o">=</span> <span class="n">param1</span><span class="o">+</span><span class="n">param2</span>

    <span class="k">return</span> <span class="n">result</span>
</code></pre></div></div> <h2 id="parallelization">Parallelization</h2> <p>To perform the actual parallelization, we need to define the number of (virtual) cores that we want to use, and we need to define a-priori the list of parameter combinations that we are going to spawn in parallel.</p> <hr/> <p>You can check how many (virtual) cores you have by using the command line tools <code class="language-plaintext highlighter-rouge">htop</code> or <code class="language-plaintext highlighter-rouge">glances</code>. I would recommend always leaving a couple of cores free, to avoid your machine to go into thrashing with the experts.</p> <div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># This chooses all cores except 2, unless there are only two or less cores.
</span><span class="n">NCPU</span> <span class="o">=</span> <span class="n">multiprocessing</span><span class="p">.</span><span class="nf">cpu_count</span><span class="p">()</span> <span class="o">-</span> <span class="mi">2</span> <span class="k">if</span> <span class="n">multiprocessing</span><span class="p">.</span><span class="nf">cpu_count</span><span class="p">()</span> <span class="o">&gt;</span> <span class="mi">2</span> <span class="k">else</span> <span class="mi">1</span>
</code></pre></div></div> <p>Then, you need to define the parameters that each process will receive as input. You have to basically create a list of parameters. They can be in any number and quantity, and I usually prefer to define them as a <code class="language-plaintext highlighter-rouge">generator</code> of a <code class="language-plaintext highlighter-rouge">dict comprehension</code> for brevity.</p> <div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># Create a Python generator containing a set comprehension of parameters.
# You need to identify what you would like to parallelize on, and then build
# the parameters dictionary
</span><span class="n">X_values</span> <span class="o">=</span> <span class="p">[</span><span class="mi">10</span><span class="p">,</span><span class="mi">22</span><span class="p">,</span><span class="mi">35</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">532</span><span class="p">,</span><span class="mi">12</span><span class="p">,</span><span class="mi">42</span><span class="p">,</span><span class="mi">53</span><span class="p">,</span><span class="mi">23</span><span class="p">]</span>
<span class="n">params</span> <span class="o">=</span> <span class="p">({</span>
    <span class="sh">'</span><span class="s">param1</span><span class="sh">'</span><span class="p">:</span> <span class="n">x</span><span class="p">,</span>
    <span class="sh">'</span><span class="s">param2</span><span class="sh">'</span><span class="p">:</span> <span class="mi">15</span>
<span class="p">}</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">X_values</span><span class="p">)</span>

</code></pre></div></div> <p><strong>Note</strong>: I recommend <em>not</em> to pass big structures as parameters (e.g., large matrices) because it can create a lot of inter-process communication that can cause severe delays or memory errors (e.g., use all the RAM in the machine). When possible, use <a href="https://docs.python.org/3/tutorial/classes.html#generators">Python generators</a> instead of Python lists (as shown above); in this way, the parameters list will not be pre-allocated all at once, but instead it will be allocated while iterating through the cycle.</p> <hr/> <p>Now we are ready to start the actual multiprocessing. We create a <code class="language-plaintext highlighter-rouge">Pool</code> of processes that is managed by the <code class="language-plaintext highlighter-rouge">multiprocessing</code> library itself. Then, Python allows us to iterate through the Pool and get back the results. The function <code class="language-plaintext highlighter-rouge">p.imap</code> returns the results in order.</p> <div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">with</span> <span class="n">multiprocessing</span><span class="p">.</span><span class="nc">Pool</span><span class="p">(</span><span class="n">processes</span><span class="o">=</span><span class="n">NCPU</span><span class="p">)</span> <span class="k">as</span> <span class="n">p</span><span class="p">:</span>    

    <span class="c1"># If you use "generators" for the params list,  
</span>    <span class="c1"># tqdm will not know the total length of the array
</span>    <span class="c1"># (required for the progress bar),
</span>    <span class="c1"># so you have to specify it explicitly,
</span>    <span class="c1"># or derive it from your params.
</span>    <span class="n">MAX_COUNT</span> <span class="o">=</span> <span class="nf">len</span><span class="p">(</span><span class="n">X_values</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">res</span> <span class="ow">in</span> <span class="nf">tqdm</span><span class="p">(</span><span class="n">p</span><span class="p">.</span><span class="nf">imap</span><span class="p">(</span><span class="n">function_to_parallelize</span><span class="p">,</span> <span class="n">params</span><span class="p">),</span><span class="n">total</span><span class="o">=</span><span class="n">MAX_COUNT</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">res</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="nf">print</span><span class="p">(</span><span class="n">res</span><span class="p">[</span><span class="sh">'</span><span class="s">sum</span><span class="sh">'</span><span class="p">])</span>

</code></pre></div></div> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>  0%|          | 0/9 [00:00&lt;?, ?it/s]
</code></pre></div></div> <h2 id="troubleshooting">Troubleshooting</h2> <ol> <li> <p><strong>Machine becomes slow and unresponsive after using multiprocessing</strong></p> <p>I have noticed that sometimes the <code class="language-plaintext highlighter-rouge">multiprocessing</code> library, for very large batches of experiments, leaves some operating system reources in usage—hence, the virtual machine in which you may be running your experiments could become slow and unresponsive after many days of experiments. It may be a problem of the infrastructure I am using to do the experiments, but I have seen this also happening to other colleagues that use other infrastructures. My best recommendation so far is to <strong>restart the VM</strong> if it becomes very slow after using the <code class="language-plaintext highlighter-rouge">multiprocessing</code> library. I know this is a kind of “Have you tried to turn it off and on?” solution, but it has worked so far. I will dig deeper into this, or if you have any insight please do not hesitate to leave a comment below.</p> </li> <li> <p><strong>Each iteration is too slow/Too much RAM is being used</strong></p> <p>Double check that you are using a Python <code class="language-plaintext highlighter-rouge">generator</code> (and not a <code class="language-plaintext highlighter-rouge">list</code>) for the list of parameters (the object named <code class="language-plaintext highlighter-rouge">params</code> in the above code). Also, if you are passing big data structures (e.g., huge feature matrices), remember that that RAM will be used for each process spawned. So, I recommend to do slicing (if possible) before passing big matrices as parameters if you do not need all the rows/columns for your processing.</p> </li> </ol> <h2 id="final-considerations">Final Considerations</h2> <p>I hope you have found this tutorial useful. Many people go for complex solutions for parallelizing Python code, but in most cases I found out that this easy solution is quite as effective. I have put the full code of this minimum working example on GitHub, <a href="https://github.com/fbpierazzi/mwe-python-multiprocessing">here</a>. If you have any suggestion to improve this tutorial or any parts that are not clear, just leave a comment!</p> <p>I would be happy to hear if you have other suggestions to perform multiprocessing in a more effective way.</p>]]></content><author><name></name></author><category term="tutorial"/><category term="tutorial"/><category term="python"/><category term="multiprocessing"/><summary type="html"><![CDATA[This post gives an introduction to the use of Python multiprocessing]]></summary></entry></feed>