Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
b748658
First by-hand imposition of C3 symmetry on top of triangle scenario (…
eliewolfe Nov 5, 2024
70fa820
Added Gitton's distribution, noticing assertion error
eliewolfe Nov 5, 2024
7eaa0f1
Adjustments to LP code to enable clearer debugging.
eliewolfe Nov 5, 2024
ecb3db9
LP code adjusted to account for symmetries that equate monomials whic…
eliewolfe Nov 5, 2024
084e19b
Minor performance improvements
eliewolfe Nov 5, 2024
cc74859
Remove case sensitivity in classical_sources argument
eliewolfe Nov 5, 2024
ea8c775
Cleanup name (no reason to print copy indices twice)
eliewolfe Nov 5, 2024
b8e9445
Adjust example problem to also enforce outcome relabelling symmetry
eliewolfe Nov 5, 2024
0317f94
Attempt (maybe good?) to adjust InflationSDP to allow for extra power…
eliewolfe Nov 5, 2024
244bfdd
Bugfixes to sdp_utils for compatibility with newer scipy versions.
eliewolfe Nov 5, 2024
c43f3a7
Minor bugfix to InflationSDP to ensure correct internal indexing of M…
eliewolfe Nov 5, 2024
4893704
Hack to ensure equality generation proceeds correctly even when apply…
eliewolfe Nov 7, 2024
a7d7098
Demonstration of no 3-coloring of triangle under party-relabelling an…
eliewolfe Nov 7, 2024
8207a5d
Critical fix in inequality generation now that we are avoiding the FI…
Nov 8, 2024
8a6d6ec
Incorporating (and adding to) prior work by Cristian for lossless sym…
Nov 8, 2024
bbd8f1b
Overhaul of triangle scenario scratch notebook to utilize the new aut…
Nov 8, 2024
d9ba4bf
Testing that PR box does not "become feasible" when incorporating sym…
Nov 8, 2024
cf72264
Untested hack to ensure normalization equalities are discovered for S…
eliewolfe Nov 12, 2024
cf97121
Merge remote-tracking branch 'origin/pedro_symmetries' into pedro_sym…
eliewolfe Nov 12, 2024
5476dc5
Remove garbage computation that does nothing and is memory intensive
eliewolfe Nov 14, 2024
f9fbea2
Fix to avoid including zero monomial when unnecessary, and avoid nump…
eliewolfe Nov 14, 2024
f07cb32
remove unused deletion
eliewolfe Nov 14, 2024
96a1c87
Remove legacy parameters and functions from test
apozas Nov 12, 2024
0b1f73f
Adjust all symmetry generating functions (parties, settings, outcomes…
eliewolfe Nov 28, 2024
c337a5e
Some commented code cleaned up, duplicate property removed, additiona…
eliewolfe Nov 28, 2024
04bc833
Merge branch 'refs/heads/devel' into pedro_symmetries
Dec 3, 2024
741bf98
Quick fix after merge with devel (__init__ of InflationProblem got in…
Dec 3, 2024
d4d0798
Substantial re-write with extensive fixes to possible symmetry genera…
Dec 3, 2024
0800add
Typo bugfix in setting relabelling symmetries generator
Dec 3, 2024
cb9302c
Restoring Collins-Gisin notation convention.
Dec 3, 2024
ec6c7ca
Critical bugfixes to outcome relabelling generators!
Dec 3, 2024
5d06204
Added assertions to ensure correctness of our assumptions regarding i…
eliewolfe Dec 19, 2024
f4af63c
Pass build_columns args to generate_relaxation
apozas Apr 3, 2025
a866337
Remove duplicate definitions in test_pipeline
apozas Apr 3, 2025
91f4b69
Remove duplicate definitions in test_pipeline
apozas Apr 3, 2025
30fad11
Restrict requirement to Mosek 10
apozas Apr 3, 2025
4429de0
Make discover_distribution_symmetries standalone
apozas Apr 3, 2025
d90b3fb
Rename lexorder_symmetries to symmetries
apozas Apr 3, 2025
4ed62ea
Add functions to add and reset symmetries
apozas Apr 3, 2025
4a936c8
Fix symmetry test
apozas Apr 3, 2025
037e374
Uniformize solver output status between LP and SDP
apozas Apr 4, 2025
46cff39
Compute original permutations at the very end
apozas Apr 4, 2025
51f3cb6
Uniformize solver output status between LP and SDP
apozas Apr 4, 2025
fc04acd
Move auxiliary symmetry functions out
apozas Apr 4, 2025
ed4d8e4
Fix symmetry pipeline test
apozas Apr 4, 2025
d772a53
Add networkx requirement
apozas Apr 4, 2025
dd67d13
Added keyword argument to InflationSDP to allow for a variant SDP con…
eliewolfe Apr 7, 2025
6946e73
bugfix defer sort of conjugate atoms until time to select lexicograph…
eliewolfe Apr 8, 2025
88057ab
Mosek 11 compatibility fix: Use reshaped-to-matrix linear expressions…
eliewolfe Apr 9, 2025
ab788b8
Mosek 11 compatibility fix: Use reshaped-to-matrix linear expressions…
eliewolfe Apr 9, 2025
02c925f
Undo 30fad11
apozas Apr 10, 2025
dd157a7
Initialize dictionaries with braces
apozas Apr 10, 2025
9e0f67c
Add networkx requirement
apozas Apr 4, 2025
fde4cf5
Add test for discover_distribution_symmetries
apozas Apr 11, 2025
3adfc17
Add networkx requirement
apozas Apr 4, 2025
8786c2d
RealQT bugfix: needed an asterix to used unpacked iterables in iterto…
eliewolfe Apr 14, 2025
e6d9d5d
Steal monomial creation routing from pedro_symmetries branch to handl…
eliewolfe Apr 14, 2025
7c48dd2
RealQT: In retrospect, this should have been the only required change…
eliewolfe Apr 14, 2025
78fcc4c
Enable the `max_monomial_length` keyword in `generate_relaxation`
eliewolfe Apr 14, 2025
79eae7d
Patch to sdp_utils to allow for Mosek 11 when using the (default) sol…
eliewolfe Apr 15, 2025
20f14db
Make generate_inflation_symmetries a property
apozas Apr 19, 2025
9064ec2
Move group_elements_from_group generators to utils
apozas Apr 19, 2025
c916a5a
Add test for symmetries in inflations
apozas Apr 19, 2025
7832ac4
Add test for group_elements_from_generators
apozas Apr 19, 2025
db0dd70
Bring imports to the beginning of the file
apozas Apr 19, 2025
7afea87
Add documentation and make style fixes
apozas Apr 19, 2025
44b0abb
More documentation and minor edits
apozas Apr 19, 2025
c963ede
Add certificate de-symmetrization
apozas Apr 19, 2025
3381c68
Add documentation
apozas Apr 21, 2025
f0b8c4e
Remove applications folder
apozas Apr 21, 2025
bce9e79
Merge branch 'pedro_symmetries' into devel
apozas Apr 21, 2025
5520ce1
Fix merge errors
apozas Apr 21, 2025
6b6ca72
Fix documentation
apozas Apr 21, 2025
b137902
Sanitize distribution in set_distribution
apozas Apr 21, 2025
e4df380
Remove unused functions
apozas Apr 21, 2025
e608e75
Improved warnings to the user when not all symmetries of the Inflatio…
eliewolfe May 7, 2025
ece46d9
Improved readability with Numpy 2.0+
eliewolfe May 9, 2025
3511bac
continued improved readability with Numpy 2.0+
eliewolfe May 9, 2025
68f7c0d
Switch to eprint for vebosity message in InflationSDP
eliewolfe May 9, 2025
54face8
Switch to eprint for vebosity message in InflationSDP and InflationLP
eliewolfe May 9, 2025
8cd39c0
Merge pull request #164 from ecboghiu/pedro_symmetries
eliewolfe May 9, 2025
f58bf1f
attempt to resolve merge conflict based on shift to eprint
eliewolfe May 9, 2025
02a0245
Removal of commented-out code (causing merge conflicts)
eliewolfe May 9, 2025
7179749
Merge pull request #165 from ecboghiu/realqt
eliewolfe May 9, 2025
cb46e8b
Bring back f4af63c
apozas May 12, 2025
4519d95
CRITICAL BUGFIX to fix InflationSDP. Patch for issue regarding symmet…
eliewolfe May 13, 2025
142ed97
Merge remote-tracking branch 'origin/devel' into devel
eliewolfe May 13, 2025
6f34a94
Reorganization of InflationProblem's assertions prior to addressing I…
eliewolfe May 13, 2025
2181d35
Critical bugfix to InflationSDP to maintain inflation symmetries
eliewolfe May 13, 2025
e5b4790
Fix to ensure warning only printed when verbosity>0
eliewolfe May 13, 2025
7739de8
Fix test_lpi_bounds to use correct cardinalities in set_distribution
eliewolfe May 13, 2025
31b29a6
Added emergency assertion (raise NotImplementedError) to prevent acce…
eliewolfe May 13, 2025
5265053
Critical Fix: maintain boolean data type for arrays which are subsequ…
eliewolfe May 14, 2025
55c4152
Minor feature: add physical monomials and physical atomic factors as …
eliewolfe May 14, 2025
58dcf8e
Performance/sanity-check: An operator sequence only corresponds to a …
eliewolfe May 14, 2025
68f5a28
Make more hackable -- _all_unique_inflation_indices exposed as property.
eliewolfe May 20, 2025
f2302ce
Fixed test by adding a common source
ecboghiu Jul 2, 2025
0c98d84
switch a print to eprint in InflationSDP
eliewolfe Jul 3, 2025
f4b4b3a
use python native float and string instead of np._str and np.float fo…
eliewolfe Jul 7, 2025
6653114
Critical bugfix for LP dualization failing when there are nontrivial …
eliewolfe Jul 7, 2025
fc8fbce
Remove InflationSDP.measurements
apozas Jul 10, 2025
e7518b7
Small cleanups
apozas Jul 10, 2025
383098b
Copy CI configuration from main
apozas Jul 10, 2025
c2972bf
Correction to prior commit (remove referenced to nof_primal_nontriv_b…
eliewolfe Jul 10, 2025
49a3dea
Removing manual dualization from lp_utils.
eliewolfe Jul 10, 2025
d957828
Merge remote-tracking branch 'origin/devel' into devel
eliewolfe Jul 10, 2025
22eafe9
Remove printout in test
apozas Jul 10, 2025
22e499c
Add threshold to PR box test
apozas Jul 11, 2025
1b856ea
Now, finally, fix the tests
apozas Jul 11, 2025
2f38416
Critical bugfix to return solution information when solving SDP with …
eliewolfe Jul 23, 2025
cf7813c
Use of array module to format indices for newer versions of Mosek (to…
eliewolfe Aug 7, 2025
eaa5352
Code simplification for real_qt case.
eliewolfe Aug 7, 2025
d68f7c3
Use defaultdict for desymmetrized dictionary creation.
eliewolfe Aug 7, 2025
eab0805
Certificate dictionaries should not contain entries where the coeffic…
eliewolfe Aug 7, 2025
3ce75d5
additional use of the array module to supress warnings in new Mosek v…
eliewolfe Aug 7, 2025
dcbfc9c
Use directed instead of undirected graph iso
apozas Aug 8, 2025
5859000
test_symmetrized_PRbox: Increase dist. to the set
apozas Aug 8, 2025
eab6819
Add warning when using real quantum theory
apozas Aug 8, 2025
f606c83
Fix indenting inconsistency
apozas Aug 8, 2025
54808cc
Update copyright
apozas Aug 8, 2025
c45dd68
Update to v2.0.3
apozas Aug 8, 2025
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
52 changes: 11 additions & 41 deletions .github/workflows/python-unittest-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,46 +26,16 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install pytest
pip install mosek numba numpy scipy sympy tqdm
# - name: Set up MOSEK license
# env:
# MOSEK_LICENSE_KEY: ${{ secrets.MOSEK_LICENSE_KEY }}
# run: |
# mkdir -p $HOME/mosek
# echo "$MOSEK_LICENSE_KEY" > $HOME/mosek/mosek.lic
pip install mosek numba networkx numpy scipy sympy tqdm
- name: Set up MOSEK license
env:
MOSEK_LICENSE_KEY: ${{ secrets.MOSEK_LICENSE_KEY }}
run: |
mkdir -p $HOME/mosek
echo "$MOSEK_LICENSE_KEY" > $HOME/mosek/mosek.lic
- name: Test with pytest
run: |
pytest -v \
--ignore=test/test_writers.py \
--ignore=test/test_optimize.py \
--deselect=test/test_solvers.py::TestSDP::test_LP_with_SDP \
--deselect=test/test_solvers.py::TestSDP::test_SDP \
--deselect=test/test_solvers.py::TestSDP::test_SDP_equalities \
--deselect=test/test_solvers.py::TestSDP::test_SDP_inequalities \
--deselect=test/test_solvers.py::TestLP::test_LP_free_bounds \
--deselect=test/test_solvers.py::TestLP::test_LP_non_negative_bounds \
--deselect=test/test_solvers.py::TestLP::test_LP_lower_bounds_of_zero \
--deselect=test/test_solvers.py::TestLP::test_LP_free_bounds_of_zero_and_non_negative \
--deselect=test/test_solvers.py::TestLP::test_LP_negative_lower_bounds \
--deselect=test/test_solvers.py::TestLP::test_LP_negative_lower_bounds_and_non_negative \
--deselect=test/test_solvers.py::TestSolverProcesses::test_semiknown_constraints \
--deselect=test/test_solvers.py::TestSolverProcesses::test_partially_known_objective \
--deselect=test/test_pipeline.py::TestSDPOutput::test_bounds \
--deselect=test/test_pipeline.py::TestSDPOutput::test_CHSH \
--deselect=test/test_pipeline.py::TestSDPOutput::test_GHZ_commuting \
--deselect=test/test_pipeline.py::TestSDPOutput::test_GHZ_NC \
--deselect=test/test_pipeline.py::TestSDPOutput::test_instrumental \
--deselect=test/test_pipeline.py::TestSDPOutput::test_lpi \
--deselect=test/test_pipeline.py::TestSDPOutput::test_supports \
--deselect=test/test_pipeline.py::TestLPOutput::test_bounds \
--deselect=test/test_pipeline.py::TestLPOutput::test_instrumental \
--deselect=test/test_pipeline.py::TestLPOutput::test_supports \
--deselect=test/test_pipeline.py::TestInstrumental::test_instrumental_fanout \
--deselect=test/test_pipeline.py::TestInstrumental::test_instrumental_nonfanout \
--deselect=test/test_pipeline.py::TestBell::test_bell_fanout \
--deselect=test/test_pipeline.py::TestBell::test_bell_nonfanout \
--deselect=test/test_pipeline.py::TestTriangle::test_triangle_fanout \
--deselect=test/test_pipeline.py::TestTriangle::test_triangle_nonfanout \
--deselect=test/test_pipeline.py::TestEvans::test_evans_fanout \
--deselect=test/test_pipeline.py::TestEvans::test_evans_nonfanout \
--deselect=test/test_pipeline.py::TestFullNN::test_fullnetworknonlocality_3partite_line
pytest -v
- name: Clean up MOSEK license file
run: |
rm $HOME/mosek/mosek.lic
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
[![DOI](https://zenodo.org/badge/500850617.svg)](https://zenodo.org/badge/latestdoi/500850617)

# Inflation
Inflation is a Python package that implements inflation algorithms for causal inference. In causal inference, the main task is to determine which causal relationships can exist between different observed random variables. Inflation algorithms are a class of techniques designed to solve the causal compatibility problem, that is, test compatibility between some observed data and a given causal relationship.
Inflation is a package, written in Python, that implements inflation algorithms for causal inference. In causal inference, the main task is to determine which causal relationships can exist between different observed random variables. Inflation algorithms are a class of techniques designed to solve the causal compatibility problem, that is, test compatibility between some observed data and a given causal relationship.

The first version of this package implements the inflation technique for quantum causal compatibility. For details, see [Physical Review X 11 (2), 021043 (2021)](https://journals.aps.org/prx/abstract/10.1103/PhysRevX.11.021043). The inflation technique for classical causal compatibility will be implemented in a future update.
This package implements the inflation technique for classical, quantum, and post-quantum causal compatibility. By relaxing independence constraints to symmetries on larger graphs, it develops hierarchies of relaxations of the causal compatibility problem that can be solved using linear and semidefinite programming. For details, see [Wolfe et al. “The inflation technique for causal inference with latent variables.” Journal of Causal Inference 7 (2), 2017-0020 (2019)](https://www.degruyter.com/document/doi/10.1515/jci-2017-0020/html), [Wolfe et al. “Quantum inflation: A general approach to quantum causal compatibility.” Physical Review X 11 (2), 021043 (2021)](https://journals.aps.org/prx/abstract/10.1103/PhysRevX.11.021043), and references therein.

Examples of use of this package include:

- Causal compatibility with classical, quantum, non-signaling, and hybrid models.
- Feasibility problems and extraction of certificates.
- Optimization of Bell operators.
- Optimisation over classical distributions.
- Optimization over classical distributions.
- Handling of bilayer (i.e., networks) and multilayer causal structures.
- Standard [Navascués-Pironio-Acín hierarchy](https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.98.010401).
- Scenarios with partial information.
- Possibilistic compatibility with a causal network.
Expand Down
2 changes: 1 addition & 1 deletion docs/_build/html/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 5ac241c6c147f17086ae747d1ca39b93
config: 3499f0084671aa32dd3b76f6907174da
tags: 645f666f9bcd5a90fca523b33c5a78b7
38 changes: 19 additions & 19 deletions docs/_build/html/_modules/index.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@


<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<html class="writer-html5" lang="en" data-content_root="../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Overview: module code &mdash; Inflation 2.0.2 documentation</title>
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../_static/copybutton.css" type="text/css" />
<!--[if lt IE 9]>
<script src="../_static/js/html5shiv.min.js"></script>
<![endif]-->
<title>Overview: module code &mdash; Inflation 2.0.1 documentation</title>
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=92fd9be5" />
<link rel="stylesheet" type="text/css" href="../_static/css/theme.css?v=e59714d7" />
<link rel="stylesheet" type="text/css" href="../_static/copybutton.css?v=76b2166b" />


<script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/_sphinx_javascript_frameworks_compat.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/clipboard.min.js"></script>
<script src="../_static/copybutton.js"></script>
<script crossorigin="anonymous" integrity="sha256-Ae2Vz/4ePdIu6ZyI/5ZGsYnb+m0JlOmKPjt6XZ9JJkA=" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script>
<script src="../_static/jquery.js?v=5d32c60e"></script>
<script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../_static/documentation_options.js?v=f5cff4aa"></script>
<script src="../_static/doctools.js?v=9a2dae69"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../_static/clipboard.min.js?v=a7894cd8"></script>
<script src="../_static/copybutton.js?v=a56c686a"></script>
<script crossorigin="anonymous" integrity="sha256-Ae2Vz/4ePdIu6ZyI/5ZGsYnb+m0JlOmKPjt6XZ9JJkA=" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script>
<script src="../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
Expand All @@ -33,7 +33,7 @@
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
Expand Down Expand Up @@ -64,8 +64,8 @@
<div class="rst-content">
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="../contents.html" class="icon icon-home"></a> &raquo;</li>
<li>Overview: module code</li>
<li><a href="../contents.html" class="icon icon-home" aria-label="Home"></a></li>
<li class="breadcrumb-item active">Overview: module code</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
Expand Down
1 change: 1 addition & 0 deletions docs/_build/html/_modules/inflation/InflationProblem.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ <h1>Source code for inflation.InflationProblem</h1><div class="highlight"><pre>
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Tuple</span><span class="p">,</span> <span class="n">List</span><span class="p">,</span> <span class="n">Union</span><span class="p">,</span> <span class="n">Dict</span>
<span class="kn">from</span> <span class="nn">warnings</span> <span class="kn">import</span> <span class="n">warn</span>

<span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">sympy</span>
<span class="kn">from</span> <span class="nn">tqdm</span> <span class="kn">import</span> <span class="n">tqdm</span>
Expand Down
17 changes: 3 additions & 14 deletions docs/_build/html/_static/_sphinx_javascript_frameworks_compat.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
/*
* _sphinx_javascript_frameworks_compat.js
* ~~~~~~~~~~
*
* Compatability shim for jQuery and underscores.js.
*
* WILL BE REMOVED IN Sphinx 6.0
* xref RemovedInSphinx60Warning
/* Compatability shim for jQuery and underscores.js.
*
* Copyright Sphinx contributors
* Released under the two clause BSD licence
*/

/**
* select a different prefix for underscore
*/
$u = _.noConflict();


/**
* small helper function to urldecode strings
*
Expand Down
3 changes: 2 additions & 1 deletion docs/_build/html/_static/copybutton.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ div.highlight {
position: relative;
}

.highlight:hover button.copybtn {
/* Show the copybutton */
.highlight:hover button.copybtn, button.copybtn.success {
opacity: 1;
}

Expand Down
44 changes: 36 additions & 8 deletions docs/_build/html/_static/copybutton.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const messages = {
},
'fr' : {
'copy': 'Copier',
'copy_to_clipboard': 'Copié dans le presse-papier',
'copy_to_clipboard': 'Copier dans le presse-papier',
'copy_success': 'Copié !',
'copy_failure': 'Échec de la copie',
},
Expand Down Expand Up @@ -102,18 +102,25 @@ const clearSelection = () => {
}
}

// Changes tooltip text for two seconds, then changes it back
// Changes tooltip text for a moment, then changes it back
// We want the timeout of our `success` class to be a bit shorter than the
// tooltip and icon change, so that we can hide the icon before changing back.
var timeoutIcon = 2000;
var timeoutSuccessClass = 1500;

const temporarilyChangeTooltip = (el, oldText, newText) => {
el.setAttribute('data-tooltip', newText)
el.classList.add('success')
setTimeout(() => el.setAttribute('data-tooltip', oldText), 2000)
setTimeout(() => el.classList.remove('success'), 2000)
// Remove success a little bit sooner than we change the tooltip
// So that we can use CSS to hide the copybutton first
setTimeout(() => el.classList.remove('success'), timeoutSuccessClass)
setTimeout(() => el.setAttribute('data-tooltip', oldText), timeoutIcon)
}

// Changes the copy button icon for two seconds, then changes it back
const temporarilyChangeIcon = (el) => {
el.innerHTML = iconCheck;
setTimeout(() => {el.innerHTML = iconCopy}, 2000)
setTimeout(() => {el.innerHTML = iconCopy}, timeoutIcon)
}

const addCopyButtonToCodeCells = () => {
Expand All @@ -125,7 +132,8 @@ const addCopyButtonToCodeCells = () => {
}

// Add copybuttons to all of our code cells
const codeCells = document.querySelectorAll('div.highlight pre')
const COPYBUTTON_SELECTOR = 'div.highlight pre';
const codeCells = document.querySelectorAll(COPYBUTTON_SELECTOR)
codeCells.forEach((codeCell, index) => {
const id = codeCellId(index)
codeCell.setAttribute('id', id)
Expand All @@ -141,10 +149,25 @@ function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}

/**
* Removes excluded text from a Node.
*
* @param {Node} target Node to filter.
* @param {string} exclude CSS selector of nodes to exclude.
* @returns {DOMString} Text from `target` with text removed.
*/
function filterText(target, exclude) {
const clone = target.cloneNode(true); // clone as to not modify the live DOM
if (exclude) {
// remove excluded nodes
clone.querySelectorAll(exclude).forEach(node => node.remove());
}
return clone.innerText;
}

// Callback when a copy button is clicked. Will be passed the node that was clicked
// should then grab the text and replace pieces of text that shouldn't be used in output
function formatCopyText(textContent, copybuttonPromptText, isRegexp = false, onlyCopyPromptLines = true, removePrompts = true, copyEmptyLines = true, lineContinuationChar = "", hereDocDelim = "") {

var regexp;
var match;

Expand Down Expand Up @@ -199,7 +222,12 @@ function formatCopyText(textContent, copybuttonPromptText, isRegexp = false, onl

var copyTargetText = (trigger) => {
var target = document.querySelector(trigger.attributes['data-clipboard-target'].value);
return formatCopyText(target.innerText, '$ ', false, true, true, true, '', '')

// get filtered text
let exclude = '.linenos';

let text = filterText(target, exclude);
return formatCopyText(text, '$ ', false, true, true, true, '', '')
}

// Initialize with a callback so we can modify the text before copy
Expand Down
17 changes: 16 additions & 1 deletion docs/_build/html/_static/copybutton_funcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,25 @@ function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}

/**
* Removes excluded text from a Node.
*
* @param {Node} target Node to filter.
* @param {string} exclude CSS selector of nodes to exclude.
* @returns {DOMString} Text from `target` with text removed.
*/
export function filterText(target, exclude) {
const clone = target.cloneNode(true); // clone as to not modify the live DOM
if (exclude) {
// remove excluded nodes
clone.querySelectorAll(exclude).forEach(node => node.remove());
}
return clone.innerText;
}

// Callback when a copy button is clicked. Will be passed the node that was clicked
// should then grab the text and replace pieces of text that shouldn't be used in output
export function formatCopyText(textContent, copybuttonPromptText, isRegexp = false, onlyCopyPromptLines = true, removePrompts = true, copyEmptyLines = true, lineContinuationChar = "", hereDocDelim = "") {

var regexp;
var match;

Expand Down
Loading