summaryrefslogtreecommitdiff
path: root/python-pywmi.spec
blob: fe3673a4a61c2f5388513a61d16f530984972907 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
%global _empty_manifest_terminate_build 0
Name:		python-pywmi
Version:	0.7.15
Release:	1
Summary:	Essential tools and interfaces for WMI solving.
License:	MIT
URL:		http://github.com/samuelkolb/pywmi
Source0:	https://mirrors.nju.edu.cn/pypi/web/packages/57/ee/e6c5a32908092872b7e0f410da1d9fc989c10f6193af70a091bdc18ecdf2/pywmi-0.7.15.tar.gz
BuildArch:	noarch

Requires:	python3-pysmt
Requires:	python3-numpy
Requires:	python3-future
Requires:	python3-matplotlib
Requires:	python3-pillow
Requires:	python3-polytope
Requires:	python3-tabulate
Requires:	python3-graphviz
Requires:	python3-sympy
Requires:	python3-scipy
Requires:	python3-autodora
Requires:	python3-deprecated
Requires:	python3-networkx
Requires:	python3-antlr4-python3-runtime
Requires:	python3-pysdd

%description
# pywmi [![Build Status](https://travis-ci.org/weighted-model-integration/pywmi.svg?branch=master)](https://travis-ci.org/weighted-model-integration/pywmi)
## Installation

    pip install pywmi

pywmi offers various services and engines that require additional installation steps.

### SMT solvers
pywmi relies upon pysmt to interface with SMT solvers. If you want to benefit from functionality relying on SMT solvers
please install an SMT solver through the pysmt-install tool that comes as part of your pywmi installation.

    pysmt-install --msat  # example to install mathsat, more solvers are available

For older versions of PySMT (older than version 0.8), you have to make sure that when you use pywmi, the SMT solvers are on your path.
The pysmt-install tool can show you the necessary commands.

    pysmt-install --env

### XADD engine
The XADD engine performs WMI using XADDs as described in [Kolb et al., 2018](https://www.ijcai.org/proceedings/2018/698).
To use this engine you need [Java](https://www.oracle.com/technetwork/java/javase/downloads/index.html), [Gurobi](https://www.gurobi.com) and the xadd library JAR file.
The pywmi-install tool that comes with your pywmi installation can automatically download and install the JAR file,
however, you need to install Java and Gurobi manually. Once you did that, just call:

    pywmi-install xadd
    pywmi-install xadd --force  # To download a new version


### Predicate abstraction engine
The predicate abstraction engine (short PA engine) uses MathSAT and Latte to solve WMI using predicate abstraction, as 
described in [Morettin et al., 2017](https://www.ijcai.org/proceedings/2017/0100.pdf).
In order to use the PA engine, you need to install the MathSAT SMT solver (see instructions above),
Latte (see instructions below) and the [wmipa library](https://github.com/unitn-sml/wmi-pa). You can use the
`pysmt-install` utility to download the library.

    pywmi-install pa
    pywmi-install pa --force  # To download a new version

**Manual installation**

You can also download or clone the library manually and add it to your `PYTHONPATH`
1. Download / clone the [wmipa library](https://github.com/unitn-sml/wmi-pa)
2. Add the directory containing the library to your `PYTHONPATH`

### Native XSDD engine
The native XSDD engine (and the PiecewiseXSDD class for representing piecewise functions) are implemented using the
[PySDD](https://github.com/wannesm/PySDD) library. The PySDD package can be installed as follows:

    pip install git+https://github.com/wannesm/PySDD.git#egg=PySDD

### External XSDD engine
WMI using XSDD inference is also supported by pywmi. To use the XSDD engine you need to install
[HAL-ProbLog](https://bitbucket.org/pedrozudo/hal_problog) by following the instructions provided in the README file.

**Summary**
1. Install the [dmd compiler v2.078.3](http://downloads.dlang.org/releases/2.x/2.078.3/)
2. `git clone https://github.com/ariovistus/pyd.git`
3. `cd pyd`
4. `python setup.py install`
5. `cd ../`
6. `git clone --recursive https://github.com/ML-KULeuven/psipy.git`
7. `cd psypi`
8. `python psipy/build_psi.py`
9. `python setup.py install`
10. Add the psi library to your path (command printed during the previous step)
11. `cd ../`
12. `git clone https://bitbucket.org/pedrozudo/hal_problog.git`
13. `cd hal_problog`
14. `python setup.py install`

Take care that your code does not run in the same directory as the one you cloned the libraries, as they will pollute
your namespace.

### Latte
The Latte integration backend as well as the predicate abstraction solver require
[Latte](https://www.math.ucdavis.edu/~latte/software.php) to be installed. You can find the latest releases on their
[GitHub releases page](https://github.com/latte-int/latte/releases). You'll probably want the bundle: latte-integrale.

**Summary**
1. `wget "https://github.com/latte-int/latte/releases/download/version_1_7_5/latte-integrale-1.7.5.tar.gz"`
2. `tar -xvzf latte-integrale-1.7.5.tar.gz`
3. `cd latte-integrale-1.7.5`
4. `./configure`
5. `make`


## Usage
### Calling pywmi

**Setup density and query**

    import pysmt.shortcuts as smt

    # Create a "domain" with boolean variables a and b and real variables x, y (both between 0 and 1)
    domain = Domain.make(["a", "b"], ["x", "y"], [(0, 1), (0, 1)])

    a, b = domain.get_bool_symbols()  # Get PySMT symbols for the boolean variables
    x, y = domain.get_real_symbols()  # Get PySMT variables for the continuous variables

    # Create support
    support = (a | b) & (~a | ~b) & (x <= y) & domain.get_bounds()

    # Create weight function (PySMT requires constants to be wrapped, e.g., smt.Real(0.2))
    weight_function = smt.Ite(a, smt.Real(0.2), smt.Real(0.8)) * (smt.Ite(x <= 0.5, smt.Real(0.2), 0.2 + y) + smt.Real(0.1))

    # Create query
    query = x <= y / 2

**Use engine to perform inference**

    # Create rejection-sampling based engine (no setup required)
    rejection_engine = RejectionEngine(domain, support, weight_function, sample_count=100000)

    print("Volume (Rejection):           ", rejection_engine.compute_volume())  # Compute the weighted model integral
    print("Query probability (Rejection):", rejection_engine.compute_probability(query))  # Compute query probability

 **Use XADD engine (make sure you have installed the prerequisites)**

    # Create XADD engine (mode resolve refers to the integration algorithm described in
    # Kolb et al. Efficient symbolic integration for probabilistic inference. IJCAI 2018)
    # !! Requires XADD solver to be setup (see above) !!
    xadd_engine = XaddEngine(domain, support, weight_function, mode="resolve")

    print("Volume (XADD):                ", xadd_engine.compute_volume())  # Compute the weighted model integral
    print("Query probability (XADD):     ", xadd_engine.compute_probability(query))  # Compute query probability

**Generating uniform samples and their labels**

    from pywmi.sample import uniform
    # n: Required number of samples
    # domain, support: Domain and support defined as above
    samples = uniform(domain, n)
    labels = evaluate(samples, support, samples)

**Generating weighted positive samples**

    from pywmi.sample import positive
    # n: Required number of samples
    # domain, support, weight: Defining the density as above
    # Optional:
    #   sample_pool_size: The number of uniformly sampled positive samples to weight and select the samples from
    #   sample_count: The number of samples to draw initially, from which to build the positive pool
    #   max_samples: The maximum number of uniformly sampled samples (positive or negative) to generate before failing
    #                => If max_samples is exceeded a SamplingError will be raised
    samples, positive_ratio = positive(n, domain, support, weight)

**Handle densities and write to files**

    # Wrap support and weight function (and optionally queries) in a density object
    density = Density(domain, support, weight_function, [query])

    # Density object can be saved to and loaded from files
    filename = "my_density.json"
    density.to_file(filename)  # Save to file
    density = Density.from_file(filename)  # Load from file

**Work from command line**

    # Compare engines from command line
    python -m pywmi my_density.json compare rej:n100000 xadd:mresolve  # Compute the weighted model integral
    python -m pywmi my_density.json compare rej:n100000 xadd:mresolve -q 0  # Compute query probability (query at index 0)

    # Compute volumes and probabilities from command line
    # You can provide multiple engines and the result of the first engine not to fail will be returned
    python -m pywmi my_density.json volume rej:n100000  # Compute weighted model integral
    python -m pywmi my_density.json prob rej:n100000  # Compute all query probabilities

    # Plot 2-D support
    python -m pywmi my_density.json plot -o my_density.png

Find the complete running example in [pywmi/tests/running_example.py](pywmi/tests/running_example.py)




%package -n python3-pywmi
Summary:	Essential tools and interfaces for WMI solving.
Provides:	python-pywmi
BuildRequires:	python3-devel
BuildRequires:	python3-setuptools
BuildRequires:	python3-pip
%description -n python3-pywmi
# pywmi [![Build Status](https://travis-ci.org/weighted-model-integration/pywmi.svg?branch=master)](https://travis-ci.org/weighted-model-integration/pywmi)
## Installation

    pip install pywmi

pywmi offers various services and engines that require additional installation steps.

### SMT solvers
pywmi relies upon pysmt to interface with SMT solvers. If you want to benefit from functionality relying on SMT solvers
please install an SMT solver through the pysmt-install tool that comes as part of your pywmi installation.

    pysmt-install --msat  # example to install mathsat, more solvers are available

For older versions of PySMT (older than version 0.8), you have to make sure that when you use pywmi, the SMT solvers are on your path.
The pysmt-install tool can show you the necessary commands.

    pysmt-install --env

### XADD engine
The XADD engine performs WMI using XADDs as described in [Kolb et al., 2018](https://www.ijcai.org/proceedings/2018/698).
To use this engine you need [Java](https://www.oracle.com/technetwork/java/javase/downloads/index.html), [Gurobi](https://www.gurobi.com) and the xadd library JAR file.
The pywmi-install tool that comes with your pywmi installation can automatically download and install the JAR file,
however, you need to install Java and Gurobi manually. Once you did that, just call:

    pywmi-install xadd
    pywmi-install xadd --force  # To download a new version


### Predicate abstraction engine
The predicate abstraction engine (short PA engine) uses MathSAT and Latte to solve WMI using predicate abstraction, as 
described in [Morettin et al., 2017](https://www.ijcai.org/proceedings/2017/0100.pdf).
In order to use the PA engine, you need to install the MathSAT SMT solver (see instructions above),
Latte (see instructions below) and the [wmipa library](https://github.com/unitn-sml/wmi-pa). You can use the
`pysmt-install` utility to download the library.

    pywmi-install pa
    pywmi-install pa --force  # To download a new version

**Manual installation**

You can also download or clone the library manually and add it to your `PYTHONPATH`
1. Download / clone the [wmipa library](https://github.com/unitn-sml/wmi-pa)
2. Add the directory containing the library to your `PYTHONPATH`

### Native XSDD engine
The native XSDD engine (and the PiecewiseXSDD class for representing piecewise functions) are implemented using the
[PySDD](https://github.com/wannesm/PySDD) library. The PySDD package can be installed as follows:

    pip install git+https://github.com/wannesm/PySDD.git#egg=PySDD

### External XSDD engine
WMI using XSDD inference is also supported by pywmi. To use the XSDD engine you need to install
[HAL-ProbLog](https://bitbucket.org/pedrozudo/hal_problog) by following the instructions provided in the README file.

**Summary**
1. Install the [dmd compiler v2.078.3](http://downloads.dlang.org/releases/2.x/2.078.3/)
2. `git clone https://github.com/ariovistus/pyd.git`
3. `cd pyd`
4. `python setup.py install`
5. `cd ../`
6. `git clone --recursive https://github.com/ML-KULeuven/psipy.git`
7. `cd psypi`
8. `python psipy/build_psi.py`
9. `python setup.py install`
10. Add the psi library to your path (command printed during the previous step)
11. `cd ../`
12. `git clone https://bitbucket.org/pedrozudo/hal_problog.git`
13. `cd hal_problog`
14. `python setup.py install`

Take care that your code does not run in the same directory as the one you cloned the libraries, as they will pollute
your namespace.

### Latte
The Latte integration backend as well as the predicate abstraction solver require
[Latte](https://www.math.ucdavis.edu/~latte/software.php) to be installed. You can find the latest releases on their
[GitHub releases page](https://github.com/latte-int/latte/releases). You'll probably want the bundle: latte-integrale.

**Summary**
1. `wget "https://github.com/latte-int/latte/releases/download/version_1_7_5/latte-integrale-1.7.5.tar.gz"`
2. `tar -xvzf latte-integrale-1.7.5.tar.gz`
3. `cd latte-integrale-1.7.5`
4. `./configure`
5. `make`


## Usage
### Calling pywmi

**Setup density and query**

    import pysmt.shortcuts as smt

    # Create a "domain" with boolean variables a and b and real variables x, y (both between 0 and 1)
    domain = Domain.make(["a", "b"], ["x", "y"], [(0, 1), (0, 1)])

    a, b = domain.get_bool_symbols()  # Get PySMT symbols for the boolean variables
    x, y = domain.get_real_symbols()  # Get PySMT variables for the continuous variables

    # Create support
    support = (a | b) & (~a | ~b) & (x <= y) & domain.get_bounds()

    # Create weight function (PySMT requires constants to be wrapped, e.g., smt.Real(0.2))
    weight_function = smt.Ite(a, smt.Real(0.2), smt.Real(0.8)) * (smt.Ite(x <= 0.5, smt.Real(0.2), 0.2 + y) + smt.Real(0.1))

    # Create query
    query = x <= y / 2

**Use engine to perform inference**

    # Create rejection-sampling based engine (no setup required)
    rejection_engine = RejectionEngine(domain, support, weight_function, sample_count=100000)

    print("Volume (Rejection):           ", rejection_engine.compute_volume())  # Compute the weighted model integral
    print("Query probability (Rejection):", rejection_engine.compute_probability(query))  # Compute query probability

 **Use XADD engine (make sure you have installed the prerequisites)**

    # Create XADD engine (mode resolve refers to the integration algorithm described in
    # Kolb et al. Efficient symbolic integration for probabilistic inference. IJCAI 2018)
    # !! Requires XADD solver to be setup (see above) !!
    xadd_engine = XaddEngine(domain, support, weight_function, mode="resolve")

    print("Volume (XADD):                ", xadd_engine.compute_volume())  # Compute the weighted model integral
    print("Query probability (XADD):     ", xadd_engine.compute_probability(query))  # Compute query probability

**Generating uniform samples and their labels**

    from pywmi.sample import uniform
    # n: Required number of samples
    # domain, support: Domain and support defined as above
    samples = uniform(domain, n)
    labels = evaluate(samples, support, samples)

**Generating weighted positive samples**

    from pywmi.sample import positive
    # n: Required number of samples
    # domain, support, weight: Defining the density as above
    # Optional:
    #   sample_pool_size: The number of uniformly sampled positive samples to weight and select the samples from
    #   sample_count: The number of samples to draw initially, from which to build the positive pool
    #   max_samples: The maximum number of uniformly sampled samples (positive or negative) to generate before failing
    #                => If max_samples is exceeded a SamplingError will be raised
    samples, positive_ratio = positive(n, domain, support, weight)

**Handle densities and write to files**

    # Wrap support and weight function (and optionally queries) in a density object
    density = Density(domain, support, weight_function, [query])

    # Density object can be saved to and loaded from files
    filename = "my_density.json"
    density.to_file(filename)  # Save to file
    density = Density.from_file(filename)  # Load from file

**Work from command line**

    # Compare engines from command line
    python -m pywmi my_density.json compare rej:n100000 xadd:mresolve  # Compute the weighted model integral
    python -m pywmi my_density.json compare rej:n100000 xadd:mresolve -q 0  # Compute query probability (query at index 0)

    # Compute volumes and probabilities from command line
    # You can provide multiple engines and the result of the first engine not to fail will be returned
    python -m pywmi my_density.json volume rej:n100000  # Compute weighted model integral
    python -m pywmi my_density.json prob rej:n100000  # Compute all query probabilities

    # Plot 2-D support
    python -m pywmi my_density.json plot -o my_density.png

Find the complete running example in [pywmi/tests/running_example.py](pywmi/tests/running_example.py)




%package help
Summary:	Development documents and examples for pywmi
Provides:	python3-pywmi-doc
%description help
# pywmi [![Build Status](https://travis-ci.org/weighted-model-integration/pywmi.svg?branch=master)](https://travis-ci.org/weighted-model-integration/pywmi)
## Installation

    pip install pywmi

pywmi offers various services and engines that require additional installation steps.

### SMT solvers
pywmi relies upon pysmt to interface with SMT solvers. If you want to benefit from functionality relying on SMT solvers
please install an SMT solver through the pysmt-install tool that comes as part of your pywmi installation.

    pysmt-install --msat  # example to install mathsat, more solvers are available

For older versions of PySMT (older than version 0.8), you have to make sure that when you use pywmi, the SMT solvers are on your path.
The pysmt-install tool can show you the necessary commands.

    pysmt-install --env

### XADD engine
The XADD engine performs WMI using XADDs as described in [Kolb et al., 2018](https://www.ijcai.org/proceedings/2018/698).
To use this engine you need [Java](https://www.oracle.com/technetwork/java/javase/downloads/index.html), [Gurobi](https://www.gurobi.com) and the xadd library JAR file.
The pywmi-install tool that comes with your pywmi installation can automatically download and install the JAR file,
however, you need to install Java and Gurobi manually. Once you did that, just call:

    pywmi-install xadd
    pywmi-install xadd --force  # To download a new version


### Predicate abstraction engine
The predicate abstraction engine (short PA engine) uses MathSAT and Latte to solve WMI using predicate abstraction, as 
described in [Morettin et al., 2017](https://www.ijcai.org/proceedings/2017/0100.pdf).
In order to use the PA engine, you need to install the MathSAT SMT solver (see instructions above),
Latte (see instructions below) and the [wmipa library](https://github.com/unitn-sml/wmi-pa). You can use the
`pysmt-install` utility to download the library.

    pywmi-install pa
    pywmi-install pa --force  # To download a new version

**Manual installation**

You can also download or clone the library manually and add it to your `PYTHONPATH`
1. Download / clone the [wmipa library](https://github.com/unitn-sml/wmi-pa)
2. Add the directory containing the library to your `PYTHONPATH`

### Native XSDD engine
The native XSDD engine (and the PiecewiseXSDD class for representing piecewise functions) are implemented using the
[PySDD](https://github.com/wannesm/PySDD) library. The PySDD package can be installed as follows:

    pip install git+https://github.com/wannesm/PySDD.git#egg=PySDD

### External XSDD engine
WMI using XSDD inference is also supported by pywmi. To use the XSDD engine you need to install
[HAL-ProbLog](https://bitbucket.org/pedrozudo/hal_problog) by following the instructions provided in the README file.

**Summary**
1. Install the [dmd compiler v2.078.3](http://downloads.dlang.org/releases/2.x/2.078.3/)
2. `git clone https://github.com/ariovistus/pyd.git`
3. `cd pyd`
4. `python setup.py install`
5. `cd ../`
6. `git clone --recursive https://github.com/ML-KULeuven/psipy.git`
7. `cd psypi`
8. `python psipy/build_psi.py`
9. `python setup.py install`
10. Add the psi library to your path (command printed during the previous step)
11. `cd ../`
12. `git clone https://bitbucket.org/pedrozudo/hal_problog.git`
13. `cd hal_problog`
14. `python setup.py install`

Take care that your code does not run in the same directory as the one you cloned the libraries, as they will pollute
your namespace.

### Latte
The Latte integration backend as well as the predicate abstraction solver require
[Latte](https://www.math.ucdavis.edu/~latte/software.php) to be installed. You can find the latest releases on their
[GitHub releases page](https://github.com/latte-int/latte/releases). You'll probably want the bundle: latte-integrale.

**Summary**
1. `wget "https://github.com/latte-int/latte/releases/download/version_1_7_5/latte-integrale-1.7.5.tar.gz"`
2. `tar -xvzf latte-integrale-1.7.5.tar.gz`
3. `cd latte-integrale-1.7.5`
4. `./configure`
5. `make`


## Usage
### Calling pywmi

**Setup density and query**

    import pysmt.shortcuts as smt

    # Create a "domain" with boolean variables a and b and real variables x, y (both between 0 and 1)
    domain = Domain.make(["a", "b"], ["x", "y"], [(0, 1), (0, 1)])

    a, b = domain.get_bool_symbols()  # Get PySMT symbols for the boolean variables
    x, y = domain.get_real_symbols()  # Get PySMT variables for the continuous variables

    # Create support
    support = (a | b) & (~a | ~b) & (x <= y) & domain.get_bounds()

    # Create weight function (PySMT requires constants to be wrapped, e.g., smt.Real(0.2))
    weight_function = smt.Ite(a, smt.Real(0.2), smt.Real(0.8)) * (smt.Ite(x <= 0.5, smt.Real(0.2), 0.2 + y) + smt.Real(0.1))

    # Create query
    query = x <= y / 2

**Use engine to perform inference**

    # Create rejection-sampling based engine (no setup required)
    rejection_engine = RejectionEngine(domain, support, weight_function, sample_count=100000)

    print("Volume (Rejection):           ", rejection_engine.compute_volume())  # Compute the weighted model integral
    print("Query probability (Rejection):", rejection_engine.compute_probability(query))  # Compute query probability

 **Use XADD engine (make sure you have installed the prerequisites)**

    # Create XADD engine (mode resolve refers to the integration algorithm described in
    # Kolb et al. Efficient symbolic integration for probabilistic inference. IJCAI 2018)
    # !! Requires XADD solver to be setup (see above) !!
    xadd_engine = XaddEngine(domain, support, weight_function, mode="resolve")

    print("Volume (XADD):                ", xadd_engine.compute_volume())  # Compute the weighted model integral
    print("Query probability (XADD):     ", xadd_engine.compute_probability(query))  # Compute query probability

**Generating uniform samples and their labels**

    from pywmi.sample import uniform
    # n: Required number of samples
    # domain, support: Domain and support defined as above
    samples = uniform(domain, n)
    labels = evaluate(samples, support, samples)

**Generating weighted positive samples**

    from pywmi.sample import positive
    # n: Required number of samples
    # domain, support, weight: Defining the density as above
    # Optional:
    #   sample_pool_size: The number of uniformly sampled positive samples to weight and select the samples from
    #   sample_count: The number of samples to draw initially, from which to build the positive pool
    #   max_samples: The maximum number of uniformly sampled samples (positive or negative) to generate before failing
    #                => If max_samples is exceeded a SamplingError will be raised
    samples, positive_ratio = positive(n, domain, support, weight)

**Handle densities and write to files**

    # Wrap support and weight function (and optionally queries) in a density object
    density = Density(domain, support, weight_function, [query])

    # Density object can be saved to and loaded from files
    filename = "my_density.json"
    density.to_file(filename)  # Save to file
    density = Density.from_file(filename)  # Load from file

**Work from command line**

    # Compare engines from command line
    python -m pywmi my_density.json compare rej:n100000 xadd:mresolve  # Compute the weighted model integral
    python -m pywmi my_density.json compare rej:n100000 xadd:mresolve -q 0  # Compute query probability (query at index 0)

    # Compute volumes and probabilities from command line
    # You can provide multiple engines and the result of the first engine not to fail will be returned
    python -m pywmi my_density.json volume rej:n100000  # Compute weighted model integral
    python -m pywmi my_density.json prob rej:n100000  # Compute all query probabilities

    # Plot 2-D support
    python -m pywmi my_density.json plot -o my_density.png

Find the complete running example in [pywmi/tests/running_example.py](pywmi/tests/running_example.py)




%prep
%autosetup -n pywmi-0.7.15

%build
%py3_build

%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
	find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
	find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
	find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
	find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
	find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .

%files -n python3-pywmi -f filelist.lst
%dir %{python3_sitelib}/*

%files help -f doclist.lst
%{_docdir}/*

%changelog
* Wed May 31 2023 Python_Bot <Python_Bot@openeuler.org> - 0.7.15-1
- Package Spec generated